use of javax.ws.rs.core.Variant in project jersey by eclipse-ee4j.
the class ResponseTest method OkTest5.
/*
* Create an instance of Response using Response.ok(String, Variant).build()
* verify that correct status code is returned
*/
@Test
public void OkTest5() {
Response resp;
int status = 200;
String content = "Test Only";
List<String> encoding = Arrays.asList("gzip", "compress");
List<String> lang = Arrays.asList("en-US", "en-GB", "zh-CN");
MediaType mt = new MediaType("text", "plain");
List<Variant> vts = Variant.VariantListBuilder.newInstance().mediaTypes(mt).languages(new Locale("en", "US"), new Locale("en", "GB"), new Locale("zh", "CN")).encodings(encoding.toArray(new String[0])).add().build();
String tmp;
for (Variant vt : vts) {
resp = Response.ok(content, vt).build();
tmp = verifyResponse(resp, content, status, encoding, lang, null, null, null, null);
if (tmp.endsWith("false")) {
System.out.println("### " + tmp);
fail();
}
}
}
use of javax.ws.rs.core.Variant in project jersey by eclipse-ee4j.
the class ResponseTest method variantTest.
/*
* Create an instance of Response using
* Response.status(int).variant(Variant).build()
* verify that correct status code is returned
*/
@Test
public void variantTest() {
Response resp;
int status = 200;
List<String> encoding = Arrays.asList("gzip", "compress");
List<String> lang = Arrays.asList("en-US", "en-GB", "zh-CN");
MediaType mt = new MediaType("text", "plain");
List<Variant> vts = Variant.VariantListBuilder.newInstance().mediaTypes(mt).languages(new Locale("en", "US"), new Locale("en", "GB"), new Locale("zh", "CN")).encodings(encoding.toArray(new String[0])).add().build();
String tmp;
for (Variant vt : vts) {
resp = Response.status(status).variant(vt).build();
tmp = verifyResponse(resp, null, status, encoding, lang, null, null, null, null);
if (tmp.endsWith("false")) {
System.out.println("### " + tmp);
fail();
}
}
}
use of javax.ws.rs.core.Variant in project openolat by klemens.
the class MediaTypeVariants method isPaged.
public static boolean isPaged(HttpServletRequest httpRequest, Request request) {
String accept = httpRequest.getHeader("Accept");
if (StringHelper.containsNonWhitespace(accept)) {
try {
MediaType requestMediaType = MediaType.valueOf(accept);
if (APPLICATION_JSON_PAGED.equals(requestMediaType) || APPLICATION_XML_PAGED.equals(requestMediaType)) {
return true;
}
} catch (IllegalArgumentException e) {
// can fail
}
}
Variant variant = request.selectVariant(variants);
return (variant != null && (variant.getMediaType().equals(APPLICATION_JSON_PAGED) || variant.getMediaType().equals(APPLICATION_XML_PAGED)));
}
use of javax.ws.rs.core.Variant in project droolsjbpm-integration by kiegroup.
the class ControllerUtils method createCorrectVariant.
public static Response createCorrectVariant(String responseObj, HttpHeaders headers, javax.ws.rs.core.Response.Status status) {
Response.ResponseBuilder responseBuilder = null;
Variant v = getVariant(headers);
if (status != null) {
responseBuilder = Response.status(status).entity(responseObj).variant(v);
} else {
responseBuilder = Response.ok(responseObj, v);
}
return responseBuilder.build();
}
use of javax.ws.rs.core.Variant in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeResource method executeTasksQuery.
@ApiOperation(value = "Executes the task assigning integration query for returning the tasks information as a TaskDataList.", notes = "This operation is mainly intended for the tasks assigning integration implementation, third parties are recommended to use the queries described in the task assigning getting started guide.", response = TaskDataList.class)
@POST
@Path(TASK_ASSIGNING_QUERIES_TASK_DATA_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response executeTasksQuery(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "map with the query parameters", required = true, examples = @Example(value = { @ExampleProperty(mediaType = MediaType.APPLICATION_JSON, value = TASKS_QUERY_PARAMS_MAP_EXAMPLE_JSON), @ExampleProperty(mediaType = MediaType.APPLICATION_XML, value = TASKS_QUERY_PARAMS_MAP_EXAMPLE_XML) })) String payload) {
final Variant v = getVariant(headers);
// no container id available so only used to transfer conversation id if given by client
final Header conversationIdHeader = buildConversationIdHeader("", context, headers);
try {
String contentType = getContentType(headers);
@SuppressWarnings("unchecked") final Map<String, Object> queryParameters = marshallerHelper.unmarshal(payload, contentType, Map.class);
final LocalDateTime queryTime = LocalDateTime.now();
final List<TaskData> taskDataList = runtimeServiceBase.executeFindTasksQuery(queryParameters);
final TaskDataList result = new TaskDataList(taskDataList);
result.setQueryTime(queryTime);
return createCorrectVariant(result, headers, Response.Status.OK, conversationIdHeader);
} catch (Exception e) {
LOGGER.error("Unexpected error finding tasks {}", e.getMessage(), e);
return internalServerError(errorMessage(e), v, conversationIdHeader);
}
}
Aggregations