Search in sources :

Example 16 with GenericEntity

use of javax.ws.rs.core.GenericEntity in project nhin-d by DirectProject.

the class TrustBundleResource method getTrustBundlesByDomain.

/**
     * Gets all trust bundles associated to a domain.
     * @param domainName The name of the domain to fetch trust bundles for.
     * @param fetchAnchors  Indicates if the retrieval should also include the trust anchors in the bundle.  When only needing bundle names,
     * this parameter should be set to false for better performance. 
     * @return  A JSON representation of a collection of trust bundle that are associated to the given domain.  Returns a status of
     * 404 if a domain with the given name does not exist or a status of 404 if no trust bundles are associated with the given name.
     */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("domains/{domainName}")
public Response getTrustBundlesByDomain(@PathParam("domainName") String domainName, @QueryParam("fetchAnchors") @DefaultValue("true") boolean fetchAnchors) {
    // make sure the domain exists
    org.nhindirect.config.store.Domain entityDomain;
    try {
        entityDomain = domainDao.getDomainByName(domainName);
        if (entityDomain == null)
            return Response.status(Status.NOT_FOUND).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error looking up domain.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
    Collection<org.nhindirect.config.store.TrustBundleDomainReltn> retBundles = null;
    try {
        retBundles = bundleDao.getTrustBundlesByDomain(entityDomain.getId());
        if (retBundles.isEmpty())
            return Response.noContent().cacheControl(noCache).build();
    } catch (Throwable e) {
        log.error("Error looking up trust bundles", e);
        return Response.serverError().cacheControl(noCache).build();
    }
    final Collection<TrustBundleDomainReltn> modelBundles = new ArrayList<TrustBundleDomainReltn>();
    for (org.nhindirect.config.store.TrustBundleDomainReltn bundleReltn : retBundles) {
        if (!fetchAnchors)
            bundleReltn.getTrustBundle().setTrustBundleAnchors(new ArrayList<TrustBundleAnchor>());
        final TrustBundleDomainReltn newReltn = new TrustBundleDomainReltn();
        newReltn.setIncoming(bundleReltn.isIncoming());
        newReltn.setOutgoing(bundleReltn.isOutgoing());
        newReltn.setDomain(EntityModelConversion.toModelDomain(bundleReltn.getDomain()));
        newReltn.setTrustBundle(EntityModelConversion.toModelTrustBundle(bundleReltn.getTrustBundle()));
        modelBundles.add(newReltn);
    }
    final GenericEntity<Collection<TrustBundleDomainReltn>> entity = new GenericEntity<Collection<TrustBundleDomainReltn>>(modelBundles) {
    };
    return Response.ok(entity).cacheControl(noCache).build();
}
Also used : ArrayList(java.util.ArrayList) CertificateConversionException(org.nhindirect.config.model.exceptions.CertificateConversionException) TrustBundleDomainReltn(org.nhindirect.config.model.TrustBundleDomainReltn) GenericEntity(javax.ws.rs.core.GenericEntity) Collection(java.util.Collection) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 17 with GenericEntity

use of javax.ws.rs.core.GenericEntity in project ORCID-Source by ORCID.

the class IdentifierApiServiceDelegatorTest method testviewIdentifierTypes.

@Test
public void testviewIdentifierTypes() {
    assertEquals(service.viewIdentifierTypes(null).getStatus(), 200);
    Response r = service.viewIdentifierTypes(null);
    @SuppressWarnings("unchecked") GenericEntity<List<IdentifierType>> types = (GenericEntity<List<IdentifierType>>) r.getEntity();
    Boolean found = false;
    for (IdentifierType t : types.getEntity()) {
        if (t.getName().equals("doi")) {
            assertEquals("doi: Digital object identifier", t.getDescription());
            found = true;
        }
    }
    assertTrue("no description for DOI found", found);
}
Also used : Response(javax.ws.rs.core.Response) GenericEntity(javax.ws.rs.core.GenericEntity) ArrayList(java.util.ArrayList) List(java.util.List) IdentifierType(org.orcid.pojo.IdentifierType) Test(org.junit.Test)

Example 18 with GenericEntity

use of javax.ws.rs.core.GenericEntity in project incubator-atlas by apache.

the class EntityService method tagEntities.

@POST
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response tagEntities(String body, @Context HttpHeaders headers, @Context UriInfo ui) throws CatalogException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.tagEntities()");
        }
        Map<String, Object> properties = parsePayload(body);
        if (properties.get("tags") == null || properties.size() != 1) {
            throw new CatalogException("Invalid Request, no 'tags' property specified. Creation of entity resource not supported.", 400);
        }
        String queryString = decode(getQueryString(ui));
        Collection<String> createResults = createResources(entityTagResourceProvider, new CollectionRequest(properties, queryString));
        Collection<Results> result = new ArrayList<>();
        for (String relativeUrl : createResults) {
            result.add(new Results(ui.getBaseUri().toString() + relativeUrl, 201));
        }
        return Response.status(Response.Status.CREATED).entity(new GenericEntity<Collection<Results>>(result) {
        }).build();
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : CollectionRequest(org.apache.atlas.catalog.CollectionRequest) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) GenericEntity(javax.ws.rs.core.GenericEntity) CatalogException(org.apache.atlas.catalog.exception.CatalogException) ArrayList(java.util.ArrayList) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 19 with GenericEntity

use of javax.ws.rs.core.GenericEntity in project oxAuth by GluuFederation.

the class RedirectUtil method getRedirectResponseBuilder.

public static ResponseBuilder getRedirectResponseBuilder(RedirectUri redirectUriResponse, HttpServletRequest httpRequest) {
    ResponseBuilder builder;
    if (httpRequest != null && httpRequest.getHeader(NO_REDIRECT_HEADER) != null) {
        try {
            URI redirectURI = URI.create(redirectUriResponse.toString());
            JSONObject jsonObject = new JSONObject();
            jsonObject.put(JSON_REDIRECT_PROPNAME, redirectURI.toURL());
            String jsonResp = jsonObject.toString();
            jsonResp = jsonResp.replace("\\/", "/");
            builder = Response.ok(new GenericEntity<String>(jsonResp, String.class), MediaType.APPLICATION_JSON_TYPE);
        } catch (MalformedURLException e) {
            builder = Response.serverError();
            log.debug(e.getMessage(), e);
        } catch (JSONException e) {
            builder = Response.serverError();
            log.debug(e.getMessage(), e);
        }
    } else if (redirectUriResponse.getResponseMode() != ResponseMode.FORM_POST) {
        URI redirectURI = URI.create(redirectUriResponse.toString());
        builder = new ResponseBuilderImpl();
        builder = Response.status(HTTP_REDIRECT);
        builder.location(redirectURI);
    } else {
        builder = new ResponseBuilderImpl();
        builder.status(Response.Status.OK);
        builder.type(MediaType.TEXT_HTML_TYPE);
        builder.cacheControl(CacheControl.valueOf("no-cache, no-store"));
        builder.header("Pragma", "no-cache");
        builder.entity(redirectUriResponse.toString());
    }
    return builder;
}
Also used : MalformedURLException(java.net.MalformedURLException) JSONObject(org.codehaus.jettison.json.JSONObject) GenericEntity(javax.ws.rs.core.GenericEntity) ResponseBuilderImpl(org.jboss.resteasy.specimpl.ResponseBuilderImpl) JSONException(org.codehaus.jettison.json.JSONException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) URI(java.net.URI)

Example 20 with GenericEntity

use of javax.ws.rs.core.GenericEntity in project jersey by jersey.

the class TestContainerRequest method setEntity.

void setEntity(final Object requestEntity, final MessageBodyWorkers workers) {
    final Object entity;
    final GenericType entityType;
    if (requestEntity instanceof GenericEntity) {
        entity = ((GenericEntity) requestEntity).getEntity();
        entityType = new GenericType(((GenericEntity) requestEntity).getType());
    } else {
        entity = requestEntity;
        entityType = new GenericType(requestEntity.getClass());
    }
    final byte[] entityBytes;
    if (entity != null) {
        final ByteArrayOutputStream output = new ByteArrayOutputStream();
        OutputStream stream = null;
        try {
            stream = workers.writeTo(entity, entity.getClass(), entityType.getType(), new Annotation[0], getMediaType(), new MultivaluedHashMap<String, Object>(getHeaders()), getPropertiesDelegate(), output, Collections.<WriterInterceptor>emptyList());
        } catch (final IOException | WebApplicationException ex) {
            LOGGER.log(Level.SEVERE, "Transforming entity to input stream failed.", ex);
        } finally {
            if (stream != null) {
                try {
                    stream.close();
                } catch (final IOException e) {
                // ignore
                }
            }
        }
        entityBytes = output.toByteArray();
    } else {
        entityBytes = new byte[0];
    }
    setEntity(new ByteArrayInputStream(entityBytes));
}
Also used : WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) GenericType(javax.ws.rs.core.GenericType) WebApplicationException(javax.ws.rs.WebApplicationException) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Annotation(java.lang.annotation.Annotation) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) GenericEntity(javax.ws.rs.core.GenericEntity)

Aggregations

GenericEntity (javax.ws.rs.core.GenericEntity)27 WebTarget (javax.ws.rs.client.WebTarget)13 GenericType (javax.ws.rs.core.GenericType)13 List (java.util.List)12 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 Collection (java.util.Collection)10 Produces (javax.ws.rs.Produces)9 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 Response (javax.ws.rs.core.Response)5 IOException (java.io.IOException)4 Comparator (java.util.Comparator)4 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 Queue (java.util.Queue)4 Set (java.util.Set)4 Stack (java.util.Stack)4 TreeSet (java.util.TreeSet)4 WebApplicationException (javax.ws.rs.WebApplicationException)4