Search in sources :

Example 16 with Variant

use of javax.ws.rs.core.Variant in project cxf by apache.

the class ResponseBuilderImplTest method testVariant.

@Test
public void testVariant() throws Exception {
    MetadataMap<String, Object> m = new MetadataMap<>();
    m.putSingle("Content-Type", MediaType.TEXT_XML_TYPE);
    m.putSingle("Content-Language", new Locale("en"));
    m.putSingle("Content-Encoding", "gzip");
    Variant v = new Variant(MediaType.TEXT_XML_TYPE, new Locale("en"), "gzip");
    checkBuild(Response.ok().variant(v).build(), 200, null, m);
}
Also used : Locale(java.util.Locale) Variant(javax.ws.rs.core.Variant) Test(org.junit.Test)

Example 17 with Variant

use of javax.ws.rs.core.Variant in project cxf by apache.

the class ResponseBuilderImplTest method testVariantsArray.

@Test
public void testVariantsArray() throws Exception {
    MetadataMap<String, Object> m = new MetadataMap<>();
    m.add("Content-Type", MediaType.APPLICATION_JSON_TYPE);
    m.add("Content-Language", new Locale("en_uk"));
    m.add("Content-Language", new Locale("en_gb"));
    m.add("Vary", "Accept");
    m.add("Vary", "Accept-Language");
    Variant json = new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en_uk"), null);
    Variant xml = new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en_gb"), null);
    checkBuild(Response.ok().variants(json, xml).build(), 200, null, m);
}
Also used : Locale(java.util.Locale) Variant(javax.ws.rs.core.Variant) Test(org.junit.Test)

Example 18 with Variant

use of javax.ws.rs.core.Variant in project dataverse by IQSS.

the class Users method getTraces.

@GET
@Path("{identifier}/traces/{element}")
@Produces("text/csv, application/json")
public Response getTraces(@Context Request req, @PathParam("identifier") String identifier, @PathParam("element") String element) {
    try {
        AuthenticatedUser userToQuery = authSvc.getAuthenticatedUser(identifier);
        if (!elements.contains(element)) {
            throw new BadRequestException("Not a valid element");
        }
        JsonObjectBuilder jsonObj = execCommand(new GetUserTracesCommand(createDataverseRequest(findUserOrDie()), userToQuery, element));
        List<Variant> vars = Variant.mediaTypes(MediaType.valueOf(FileUtil.MIME_TYPE_CSV), MediaType.APPLICATION_JSON_TYPE).add().build();
        MediaType requestedType = req.selectVariant(vars).getMediaType();
        if ((requestedType != null) && (requestedType.equals(MediaType.APPLICATION_JSON_TYPE))) {
            return ok(jsonObj);
        }
        JsonArray items = null;
        try {
            items = jsonObj.build().getJsonObject("traces").getJsonObject(element).getJsonArray("items");
        } catch (Exception e) {
            return ok(jsonObj);
        }
        return ok(FileUtil.jsonArrayOfObjectsToCSV(items, items.getJsonObject(0).keySet().toArray(new String[0])), MediaType.valueOf(FileUtil.MIME_TYPE_CSV), element + ".csv");
    } catch (WrappedResponse ex) {
        return ex.getResponse();
    }
}
Also used : Variant(javax.ws.rs.core.Variant) JsonArray(javax.json.JsonArray) BadRequestException(javax.ws.rs.BadRequestException) GetUserTracesCommand(edu.harvard.iq.dataverse.engine.command.impl.GetUserTracesCommand) MediaType(javax.ws.rs.core.MediaType) JsonObjectBuilder(javax.json.JsonObjectBuilder) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 19 with Variant

use of javax.ws.rs.core.Variant in project OpenOLAT by OpenOLAT.

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)));
}
Also used : Variant(javax.ws.rs.core.Variant) MediaType(javax.ws.rs.core.MediaType)

Example 20 with Variant

use of javax.ws.rs.core.Variant in project fcrepo by fcrepo.

the class FedoraLdpIT method testGetObjectGraphVariants.

@Test
public void testGetObjectGraphVariants() throws IOException {
    final String location = getLocation(postObjMethod());
    for (final Variant variant : POSSIBLE_RDF_VARIANTS) {
        final HttpGet getObjMethod = new HttpGet(location);
        final String type = variant.getMediaType().getType();
        getObjMethod.addHeader(ACCEPT, type);
        assertEquals("Got bad response for type " + type + " !", OK.getStatusCode(), getStatus(getObjMethod));
    }
}
Also used : Variant(javax.ws.rs.core.Variant) HttpGet(org.apache.http.client.methods.HttpGet) Test(org.junit.Test)

Aggregations

Variant (javax.ws.rs.core.Variant)269 Produces (javax.ws.rs.Produces)187 Header (org.kie.server.remote.rest.common.Header)183 ApiOperation (io.swagger.annotations.ApiOperation)180 Path (javax.ws.rs.Path)176 ApiResponses (io.swagger.annotations.ApiResponses)174 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)174 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)169 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)167 GET (javax.ws.rs.GET)102 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)74 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)71 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)69 Consumes (javax.ws.rs.Consumes)52 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)41 PUT (javax.ws.rs.PUT)39 Locale (java.util.Locale)33 POST (javax.ws.rs.POST)33 ProcessDefinitionNotFoundException (org.jbpm.services.api.ProcessDefinitionNotFoundException)31 ExecutionErrorNotFoundException (org.jbpm.services.api.admin.ExecutionErrorNotFoundException)31