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();
}
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);
}
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);
}
}
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;
}
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));
}
Aggregations