Search in sources :

Example 61 with UriBuilder

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();
}
Also used : SimpleSign(ddf.security.samlp.SimpleSign) Document(org.w3c.dom.Document) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 62 with UriBuilder

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

Example 63 with UriBuilder

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();
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Lock(java.util.concurrent.locks.Lock) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 64 with UriBuilder

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;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) MetacardCreationException(ddf.catalog.data.MetacardCreationException) InternalIngestException(ddf.catalog.source.InternalIngestException) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequest(ddf.catalog.operation.CreateRequest) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) MimeType(javax.activation.MimeType) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) CreateResponse(ddf.catalog.operation.CreateResponse) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) IngestException(ddf.catalog.source.IngestException) InternalIngestException(ddf.catalog.source.InternalIngestException) UriBuilder(javax.ws.rs.core.UriBuilder) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 65 with UriBuilder

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;
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo)

Aggregations

UriBuilder (javax.ws.rs.core.UriBuilder)167 URI (java.net.URI)78 Test (org.junit.Test)58 HashMap (java.util.HashMap)21 Consumes (javax.ws.rs.Consumes)15 Link (org.eclipse.che.api.core.rest.shared.dto.Link)15 IOException (java.io.IOException)12 Path (javax.ws.rs.Path)12 PUT (javax.ws.rs.PUT)11 Produces (javax.ws.rs.Produces)9 URL (java.net.URL)8 ArrayList (java.util.ArrayList)8 GET (javax.ws.rs.GET)8 LinksHelper.createLink (org.eclipse.che.api.core.util.LinksHelper.createLink)8 Timed (com.codahale.metrics.annotation.Timed)7 POST (javax.ws.rs.POST)7 Map (java.util.Map)6 Response (javax.ws.rs.core.Response)6 ServerException (org.eclipse.che.api.core.ServerException)6 List (java.util.List)5