public static MarshallingFormat getFormat(String descriptor) { MarshallingFormat format = MarshallingFormat.fromType(descriptor); if (format == null) { format = MarshallingFormat.valueOf(descriptor); } return format; }
public static MarshallingFormat getFormat(String descriptor) { MarshallingFormat format = MarshallingFormat.fromType(descriptor); if (format == null) { format = MarshallingFormat.valueOf(descriptor); } return format; }
public static MediaType getMediaType(HttpHeaders httpHeaders) { String contentType = getContentType(httpHeaders); try { return MediaType.valueOf(contentType); } catch (IllegalArgumentException e) { MarshallingFormat format = MarshallingFormat.fromType(contentType); switch (format) { case JAXB: return MediaType.APPLICATION_XML_TYPE; case XSTREAM: return MediaType.APPLICATION_XML_TYPE; case JSON: return MediaType.APPLICATION_JSON_TYPE; default: return MediaType.APPLICATION_XML_TYPE; } } }
@Test public void testExpectedMarshallingFormats() { assertEquals(MarshallingFormat.JSON, MarshallingFormat.fromType("json")); assertEquals(MarshallingFormat.JAXB, MarshallingFormat.fromType("xml")); assertEquals(MarshallingFormat.XSTREAM, MarshallingFormat.fromType("xstream")); assertEquals(MarshallingFormat.JSON, MarshallingFormat.fromType("application/json")); assertEquals(MarshallingFormat.JAXB, MarshallingFormat.fromType("application/xml")); assertEquals(MarshallingFormat.XSTREAM, MarshallingFormat.fromType("application/xstream")); }
@Test public void testMarshallingFormatsWithExtraneousParameters() { assertEquals(MarshallingFormat.JSON, MarshallingFormat.fromType("application/json;")); assertEquals(MarshallingFormat.JAXB, MarshallingFormat.fromType("application/xml;")); assertEquals(MarshallingFormat.XSTREAM, MarshallingFormat.fromType("application/xstream;")); assertEquals(MarshallingFormat.JSON, MarshallingFormat.fromType("application/json;encode=")); assertEquals(MarshallingFormat.JAXB, MarshallingFormat.fromType("application/xml;encode=utf-8")); assertEquals(MarshallingFormat.XSTREAM, MarshallingFormat.fromType("application/xstream;utf-8")); }
@ApiOperation(value="Evaluates rules by executing commands on the rule session", response=ServiceResponse.class, code=200) @ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error") }) @POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response manageContainer(@Context HttpHeaders headers, @ApiParam(value = "Container id where rules should be evaluated on", required = true) @PathParam("id") String id, @ApiParam(value = "Commands to be executed on rule engine given as BatchExecutionCommand type", required = true) String cmdPayload) { Variant v = getVariant(headers); String contentType = getContentType(headers); String classType = getClassType(headers); MarshallingFormat format = MarshallingFormat.fromType(contentType); if (format == null) { format = MarshallingFormat.valueOf(contentType); } logger.debug("Received request with content '{}'", cmdPayload); Object result = delegate.callContainer(id, cmdPayload, format, classType); Header conversationIdHeader = buildConversationIdHeader(id, registry, headers); try { String response = marshallerHelper.marshal(id, format.getType(), result, ContainerLocatorProvider.get().getLocator()); logger.debug("Returning OK response with content '{}'", response); return createResponse(response, v, Response.Status.OK, conversationIdHeader); } catch (IllegalArgumentException e) { // in case marshalling failed return the call container response to keep backward compatibility String response = marshallerHelper.marshal(format.getType(), result); logger.debug("Returning OK response with content '{}'", response); return createResponse(response, v, Response.Status.OK, conversationIdHeader); } }
@Test public void testMarshallingFormatCase() { assertEquals(MarshallingFormat.JSON, MarshallingFormat.fromType("JSON")); }
@Test public void testEmptyMarshallingFormat() { exception.expectMessage("Invalid marshalling format []"); MarshallingFormat.fromType(""); }
@Test public void testNullMarshallingFormat() { exception.expectMessage("Invalid marshalling format [null]"); MarshallingFormat.fromType(null); }
@Test public void testNonNullEmptyInvalidMarshallingFormat() { exception.expectMessage("Invalid marshalling format [JAX]"); MarshallingFormat.fromType("JAX"); }