Search in sources :

Example 86 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project cxf by apache.

the class UriBuilderImplTest method testBuildWithNonEncodedSubstitutionValue3.

@Test
public void testBuildWithNonEncodedSubstitutionValue3() {
    UriBuilder ub = UriBuilder.fromPath("/");
    URI uri = ub.path("{a}").buildFromEncoded("%");
    assertEquals("/%25", uri.toString());
    uri = ub.path("{token}").buildFromEncoded("%", "{}");
    assertEquals("/%25/%7B%7D", uri.toString());
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Test(org.junit.Test)

Example 87 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project cxf by apache.

the class AbstractClient method calculateNewRequestURI.

private URI calculateNewRequestURI(URI newBaseURI, URI requestURI, boolean proxy) {
    String baseURIPath = newBaseURI.getRawPath();
    String reqURIPath = requestURI.getRawPath();
    UriBuilder builder = new UriBuilderImpl().uri(newBaseURI);
    String basePath = reqURIPath.startsWith(baseURIPath) ? baseURIPath : getBaseURI().getRawPath();
    String relativePath = reqURIPath.equals(basePath) ? "" : reqURIPath.startsWith(basePath) ? reqURIPath.substring(basePath.length()) : reqURIPath;
    builder.path(relativePath);
    String newQuery = newBaseURI.getRawQuery();
    if (newQuery == null) {
        builder.replaceQuery(requestURI.getRawQuery());
    } else {
        builder.replaceQuery(newQuery);
    }
    URI newRequestURI = builder.build();
    resetBaseAddress(newBaseURI);
    URI current = proxy ? newBaseURI : newRequestURI;
    resetCurrentBuilder(current);
    return newRequestURI;
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) UriBuilderImpl(org.apache.cxf.jaxrs.impl.UriBuilderImpl) URI(java.net.URI)

Example 88 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project cxf by apache.

the class ClientProxyImpl method invoke.

/**
 * Updates the current state if Client method is invoked, otherwise
 * does the remote invocation or returns a new proxy if subresource
 * method is invoked. Can throw an expected exception if ResponseExceptionMapper
 * is registered
 */
public Object invoke(Object o, Method m, Object[] params) throws Throwable {
    Class<?> declaringClass = m.getDeclaringClass();
    if (Client.class == declaringClass || InvocationHandlerAware.class == declaringClass || Object.class == declaringClass) {
        return m.invoke(this, params);
    }
    resetResponse();
    OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(m);
    if (ori == null) {
        reportInvalidResourceMethod(m, "INVALID_RESOURCE_METHOD");
    }
    MultivaluedMap<ParameterType, Parameter> types = getParametersInfo(m, params, ori);
    List<Parameter> beanParamsList = getParameters(types, ParameterType.BEAN);
    int bodyIndex = getBodyIndex(types, ori);
    List<Object> pathParams = getPathParamValues(m, params, types, beanParamsList, ori, bodyIndex);
    UriBuilder builder = getCurrentBuilder().clone();
    if (isRoot) {
        addNonEmptyPath(builder, ori.getClassResourceInfo().getURITemplate().getValue());
    }
    addNonEmptyPath(builder, ori.getURITemplate().getValue());
    handleMatrixes(m, params, types, beanParamsList, builder);
    handleQueries(m, params, types, beanParamsList, builder);
    URI uri = builder.buildFromEncoded(pathParams.toArray()).normalize();
    MultivaluedMap<String, String> headers = getHeaders();
    MultivaluedMap<String, String> paramHeaders = new MetadataMap<String, String>();
    handleHeaders(m, params, paramHeaders, beanParamsList, types);
    handleCookies(m, params, paramHeaders, beanParamsList, types);
    if (ori.isSubResourceLocator()) {
        ClassResourceInfo subCri = cri.getSubResource(m.getReturnType(), m.getReturnType());
        if (subCri == null) {
            reportInvalidResourceMethod(m, "INVALID_SUBRESOURCE");
        }
        MultivaluedMap<String, String> subHeaders = paramHeaders;
        if (inheritHeaders) {
            subHeaders.putAll(headers);
        }
        ClientState newState = getState().newState(uri, subHeaders, getTemplateParametersMap(ori.getURITemplate(), pathParams));
        ClientProxyImpl proxyImpl = new ClientProxyImpl(newState, proxyLoader, subCri, false, inheritHeaders);
        proxyImpl.setConfiguration(getConfiguration());
        return JAXRSClientFactory.createProxy(m.getReturnType(), proxyLoader, proxyImpl);
    }
    headers.putAll(paramHeaders);
    getState().setTemplates(getTemplateParametersMap(ori.getURITemplate(), pathParams));
    Object body = null;
    if (bodyIndex != -1) {
        body = params[bodyIndex];
        if (body == null) {
            bodyIndex = -1;
        }
    } else if (types.containsKey(ParameterType.FORM)) {
        body = handleForm(m, params, types, beanParamsList);
    } else if (types.containsKey(ParameterType.REQUEST_BODY)) {
        body = handleMultipart(types, ori, params);
    }
    setRequestHeaders(headers, ori, types.containsKey(ParameterType.FORM), body == null ? null : body.getClass(), m.getReturnType());
    try {
        return doChainedInvocation(uri, headers, ori, params, body, bodyIndex, null, null);
    } finally {
        resetResponseStateImmediatelyIfNeeded();
    }
}
Also used : ParameterType(org.apache.cxf.jaxrs.model.ParameterType) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) URI(java.net.URI) Endpoint(org.apache.cxf.endpoint.Endpoint) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Parameter(org.apache.cxf.jaxrs.model.Parameter) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 89 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project cxf by apache.

the class WebClient method setWebClientOperationProperty.

private void setWebClientOperationProperty(Message m, String httpMethod) {
    Object prop = m.getContextualProperty(WEB_CLIENT_OPERATION_REPORTING);
    // Enable the operation reporting by default
    if (prop == null || PropertyUtils.isTrue(prop)) {
        UriBuilder absPathUri = super.getCurrentBuilder().clone();
        absPathUri.replaceQuery(null);
        setPlainOperationNameProperty(m, httpMethod + ":" + absPathUri.build().toString());
    }
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder)

Example 90 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project atlasmap by atlasmap.

the class AtlasService method saveMapping.

protected Response saveMapping(AtlasMapping mapping, UriInfo uriInfo) {
    try {
        saveMappingToFile(mapping);
    } catch (Exception e) {
        LOG.error("Error saving mapping " + mapping.getName() + " to file: " + e.getMessage(), e);
    }
    UriBuilder builder = uriInfo.getAbsolutePathBuilder();
    builder.path(mapping.getName());
    return Response.ok().location(builder.build()).build();
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) AtlasException(io.atlasmap.api.AtlasException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JAXBException(javax.xml.bind.JAXBException) WebApplicationException(javax.ws.rs.WebApplicationException)

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