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