/** * 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(); }
/** * Adds a trust bundle to the system. * * @param uriInfo Injected URI context used for building the location URI. * @param bundle The bundle to add to the system. * @return Status of 201 if the bundle was added or a status of 409 if a bundle with the same name * already exists. */ @PUT @Consumes(MediaType.APPLICATION_JSON) public Response addTrustBundle(@Context UriInfo uriInfo, TrustBundle bundle) { // make sure it doesn't exist try { if (bundleDao.getTrustBundleByName(bundle.getBundleName()) != null) return Response.status(Status.CONFLICT).cacheControl(noCache).build(); } catch (Exception e) { log.error("Error looking up bundle.", e); return Response.serverError().cacheControl(noCache).build(); } try { final org.nhindirect.config.store.TrustBundle entityBundle = EntityModelConversion.toEntityTrustBundle(bundle); bundleDao.addTrustBundle(entityBundle); final UriBuilder newLocBuilder = uriInfo.getBaseUriBuilder(); final URI newLoc = newLocBuilder.path("trustbundle/" + bundle.getBundleName()).build(); // the trust bundle does not contain any of the anchors // they must be fetched from the URL... use the // refresh route to force downloading the anchors template.sendBody(entityBundle); return Response.created(newLoc).cacheControl(noCache).build(); } catch (Exception e) { log.error("Error adding trust bundle.", e); return Response.serverError().cacheControl(noCache).build(); } }
/** * Gets all trust bundles in the system. * * @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 all trust bundles in the system. Returns a * status of 204 if no trust bundles exist. */ @GET @Produces(MediaType.APPLICATION_JSON) public Response getTrustBundles( @QueryParam("fetchAnchors") @DefaultValue("true") boolean fetchAnchors) { Collection<org.nhindirect.config.store.TrustBundle> retBundles = null; try { retBundles = bundleDao.getTrustBundles(); 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<TrustBundle> modelBundles = new ArrayList<TrustBundle>(); for (org.nhindirect.config.store.TrustBundle bundle : retBundles) { if (!fetchAnchors) bundle.setTrustBundleAnchors(new ArrayList<TrustBundleAnchor>()); modelBundles.add(EntityModelConversion.toModelTrustBundle(bundle)); } final GenericEntity<Collection<TrustBundle>> entity = new GenericEntity<Collection<TrustBundle>>(modelBundles) {}; return Response.ok(entity).cacheControl(noCache).build(); }
/** * Gets a trust bundle by name. * * @param bundleName The name of the trust bundle to retrieve. * @return A JSON representation of a the trust bundle. Returns a status of 404 if a trust bundle * with the given name does not exist. */ @GET @Produces(MediaType.APPLICATION_JSON) @Path("{bundleName}") public Response getTrustBundleByName(@PathParam("bundleName") String bundleName) { try { final org.nhindirect.config.store.TrustBundle retBundle = bundleDao.getTrustBundleByName(bundleName); if (retBundle == null) return Response.status(Status.NOT_FOUND).cacheControl(noCache).build(); final TrustBundle modelBundle = EntityModelConversion.toModelTrustBundle(retBundle); return Response.ok(modelBundle).cacheControl(noCache).build(); } catch (Throwable e) { log.error("Error looking up trust bundles", e); return Response.serverError().cacheControl(noCache).build(); } }