use of javax.ws.rs.core.UriBuilder in project ddf by codice.
the class LogoutMessageImpl method signSamlGet.
private URI signSamlGet(@NotNull SAMLObject samlObject, @NotNull URI target, String relayState, @NotNull String requestType) throws WSSecurityException, SimpleSign.SignatureException, IOException {
Document doc = DOMUtils.createDocument();
doc.appendChild(doc.createElement("root"));
String encodedResponse = URLEncoder.encode(RestSecurity.deflateAndBase64Encode(DOM2Writer.nodeToString(OpenSAMLUtil.toDom(samlObject, doc, false))), "UTF-8");
String requestToSign = String.format("%s=%s&%s=%s", requestType, encodedResponse, SSOConstants.RELAY_STATE, relayState);
UriBuilder uriBuilder = UriBuilder.fromUri(target);
uriBuilder.queryParam(requestType, encodedResponse);
uriBuilder.queryParam(SSOConstants.RELAY_STATE, relayState);
new SimpleSign(systemCrypto).signUriString(requestToSign, uriBuilder);
return uriBuilder.build();
}
use of javax.ws.rs.core.UriBuilder in project stanbol by apache.
the class TemplateLayoutConfiguration method getConsoleBaseUri.
/**
* The Apache Felix Webconsole base URL does not depend on alias configured
* for the Stanbol JerseyEndpoint. However they is affected by the base
* path of the Servlet when Stanbol is running as WAR within a web container.<p>
* <i>LIMITATION</i> this does not take into account the path configured
* for the Apache Felix Webconsole (property: <code>manager.root</code>
* class: <code>org.apache.felix.webconsole.internal.servlet.OsgiManager</code>)
* Because of this it will only work with the default {@link #SYSTEM_CONSOLE}.
* @return The URI for the Apache Felix Webconsole
*/
public URI getConsoleBaseUri() {
String root = getRootUrl();
UriBuilder consolePathBuilder;
if (StringUtils.isNotBlank(root) && !"/".equals(root)) {
String request = getUriInfo().getRequestUri().toString();
int aliasIndex = request.lastIndexOf(root);
if (aliasIndex > 0) {
request = request.substring(0, request.lastIndexOf(root));
}
consolePathBuilder = UriBuilder.fromUri(request);
} else {
consolePathBuilder = getUriInfo().getRequestUriBuilder();
}
if (this.getClass().isAnnotationPresent(Path.class)) {
String path = this.getClass().getAnnotation(Path.class).value();
int levels = path.endsWith("/") ? StringUtils.countMatches(path, "/") - 1 : StringUtils.countMatches(path, "/");
for (int i = levels; i > 0; i--) {
consolePathBuilder = consolePathBuilder.path("../");
}
}
return consolePathBuilder.path(SYSTEM_CONSOLE).build();
}
use of javax.ws.rs.core.UriBuilder in project stanbol by apache.
the class UserResource method createUser.
/*
* RESTful creation of user
* @TODO validity check input
*/
@PUT
@Path("users/{username}")
@Consumes(SupportedFormat.TURTLE)
public Response createUser(@Context UriInfo uriInfo, @PathParam("username") String userName, ImmutableGraph inputGraph) {
Lock writeLock = systemGraph.getLock().writeLock();
writeLock.lock();
systemGraph.addAll(inputGraph);
writeLock.unlock();
UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
URI createdResource = uriBuilder.replacePath("/user-management/users/" + userName).build();
return Response.created(createdResource).build();
}
use of javax.ws.rs.core.UriBuilder in project ddf by codice.
the class RESTEndpoint method addDocument.
/**
* REST Post. Creates a new metadata entry in the catalog.
*
* @param message
* @return
*/
@POST
@Consumes("multipart/*")
public Response addDocument(@Context HttpHeaders headers, @Context UriInfo requestUriInfo, @Context HttpServletRequest httpRequest, MultipartBody multipartBody, @QueryParam("transform") String transformerParam, InputStream message) {
LOGGER.debug("POST");
Response response;
MimeType mimeType = getMimeType(headers);
try {
if (message != null) {
CreateInfo createInfo = null;
if (multipartBody != null) {
List<Attachment> contentParts = multipartBody.getAllAttachments();
if (contentParts != null && contentParts.size() > 0) {
createInfo = parseAttachments(contentParts, transformerParam);
} else {
LOGGER.debug("No file contents attachment found");
}
}
CreateResponse createResponse;
if (createInfo == null) {
CreateRequest createRequest = new CreateRequestImpl(generateMetacard(mimeType, null, message, transformerParam));
createResponse = catalogFramework.create(createRequest);
} else {
CreateStorageRequest streamCreateRequest = new CreateStorageRequestImpl(Collections.singletonList(new IncomingContentItem(uuidGenerator, createInfo.getStream(), createInfo.getContentType(), createInfo.getFilename(), createInfo.getMetacard())), null);
createResponse = catalogFramework.create(streamCreateRequest);
}
String id = createResponse.getCreatedMetacards().get(0).getId();
LOGGER.debug("Create Response id [{}]", id);
UriBuilder uriBuilder = requestUriInfo.getAbsolutePathBuilder().path("/" + id);
ResponseBuilder responseBuilder = Response.created(uriBuilder.build());
responseBuilder.header(Metacard.ID, id);
response = responseBuilder.build();
LOGGER.debug("Entry successfully saved, id: {}", id);
if (INGEST_LOGGER.isInfoEnabled()) {
INGEST_LOGGER.info("Entry successfully saved, id: {}", id);
}
} else {
String errorMessage = "No content found, cannot do CREATE.";
LOGGER.info(errorMessage);
throw new ServerErrorException(errorMessage, Status.BAD_REQUEST);
}
} catch (SourceUnavailableException e) {
String exceptionMessage = "Cannot create catalog entry because source is unavailable: ";
LOGGER.info(exceptionMessage, e);
// Catalog framework logs these exceptions to the ingest logger so we don't have to.
throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
} catch (InternalIngestException e) {
String exceptionMessage = "Error while storing entry in catalog: ";
LOGGER.info(exceptionMessage, e);
// Catalog framework logs these exceptions to the ingest logger so we don't have to.
throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
} catch (MetacardCreationException | IngestException e) {
String exceptionMessage = "Error while storing entry in catalog: ";
LOGGER.info(exceptionMessage, e);
// Catalog framework logs these exceptions to the ingest logger so we don't have to.
throw new ServerErrorException(exceptionMessage, Status.BAD_REQUEST);
} finally {
IOUtils.closeQuietly(message);
}
return response;
}
use of javax.ws.rs.core.UriBuilder in project ddf by codice.
the class MetricsEndpointTest method createUriInfo.
protected UriInfo createUriInfo() throws URISyntaxException {
UriInfo info = mock(UriInfo.class);
when(info.getBaseUri()).thenReturn(new URI(ENDPOINT_ADDRESS));
when(info.getRequestUri()).thenReturn(new URI(ENDPOINT_ADDRESS));
when(info.getAbsolutePath()).thenReturn(new URI(ENDPOINT_ADDRESS));
UriBuilder builder = mock(UriBuilder.class);
when(info.getAbsolutePathBuilder()).thenReturn(builder);
when(builder.path("/uptime.png")).thenReturn(builder);
when(builder.build()).thenReturn(new URI(ENDPOINT_ADDRESS + "/uptime.png"));
return info;
}
Aggregations