Java Code Examples for javax.ws.rs.core.UriBuilder#replaceQuery()
The following examples show how to use
javax.ws.rs.core.UriBuilder#replaceQuery() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractClient.java From cxf with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: FreeMarkerLoginFormsProvider.java From keycloak with Apache License 2.0 | 6 votes |
/** * Prepare base uri builder for later use * * @param resetRequestUriParams - for some reason Resteasy 2.3.7 doesn't like query params and form params with the same name and will null out the code form param, so we have to reset them for some pages * @return base uri builder */ protected UriBuilder prepareBaseUriBuilder(boolean resetRequestUriParams) { String requestURI = uriInfo.getBaseUri().getPath(); UriBuilder uriBuilder = UriBuilder.fromUri(requestURI); if (resetRequestUriParams) { uriBuilder.replaceQuery(null); } if (client != null) { uriBuilder.queryParam(Constants.CLIENT_ID, client.getClientId()); } if (authenticationSession != null) { uriBuilder.queryParam(Constants.TAB_ID, authenticationSession.getTabId()); } return uriBuilder; }
Example 3
Source File: VersionFilter.java From secure-data-service with Apache License 2.0 | 6 votes |
private ContainerRequest updateContainerRequest(ContainerRequest containerRequest, List<PathSegment> segments, String newVersion) { //add the new version UriBuilder builder = containerRequest.getBaseUriBuilder().path(newVersion); //add the rest of the request for (PathSegment segment : segments) { builder.path(segment.getPath()); } if (containerRequest.getRequestUri().getQuery() != null && !containerRequest.getRequestUri().getQuery().isEmpty()) { builder.replaceQuery(containerRequest.getRequestUri().getQuery()); } containerRequest.getProperties().put(REQUESTED_PATH, containerRequest.getPath()); containerRequest.setUris(containerRequest.getBaseUri(), builder.build()); return containerRequest; }
Example 4
Source File: LinkCreator.java From rest-schemagen with Apache License 2.0 | 5 votes |
private URI mergeUri(URI baseUri, UriBuilder uriBuilder, Map<String, Object> pathParameters) { URI uri = uriBuilder.buildFromMap(pathParameters); if (baseUri != null) { UriBuilder mergedUriBuilder = UriBuilder.fromUri(baseUri); mergedUriBuilder.path(uri.getPath()); mergedUriBuilder.replaceQuery(uri.getQuery()); return mergedUriBuilder.buildFromMap(pathParameters); } return uri; }
Example 5
Source File: WebClient.java From cxf with Apache License 2.0 | 5 votes |
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()); } }
Example 6
Source File: JerseyHandlerFilter.java From aws-serverless-java-container with Apache License 2.0 | 4 votes |
/** * Given a ServletRequest generates the corresponding Jersey ContainerRequest object. The request URI is * built from the request's <code>getPathInfo()</code> method. The container request also contains the * API Gateway context, stage variables, and Lambda context properties. The original servlet request is * also embedded in a property of the container request to allow injection by the * {@link AwsProxyServletRequestSupplier}. * @param request The incoming servlet request * @return A populated ContainerRequest object. * @throws RuntimeException if we could not read the servlet request input stream. */ // suppressing warnings because I expect headers and query strings to be checked by the underlying // servlet implementation @SuppressFBWarnings({ "SERVLET_HEADER", "SERVLET_QUERY_STRING" }) private ContainerRequest servletRequestToContainerRequest(ServletRequest request) { Timer.start("JERSEY_SERVLET_REQUEST_TO_CONTAINER"); HttpServletRequest servletRequest = (HttpServletRequest)request; if (baseUri == null) { baseUri = getBaseUri(request, "/"); } String requestFullPath = servletRequest.getRequestURI(); if (LambdaContainerHandler.getContainerConfig().getServiceBasePath() != null && LambdaContainerHandler.getContainerConfig().isStripBasePath()) { if (requestFullPath.startsWith(LambdaContainerHandler.getContainerConfig().getServiceBasePath())) { requestFullPath = requestFullPath.replaceFirst(LambdaContainerHandler.getContainerConfig().getServiceBasePath(), ""); if (!requestFullPath.startsWith("/")) { requestFullPath = "/" + requestFullPath; } } } UriBuilder uriBuilder = UriBuilder.fromUri(baseUri).path(requestFullPath); uriBuilder.replaceQuery(servletRequest.getQueryString()); PropertiesDelegate apiGatewayProperties = new MapPropertiesDelegate(); apiGatewayProperties.setProperty(API_GATEWAY_CONTEXT_PROPERTY, servletRequest.getAttribute(API_GATEWAY_CONTEXT_PROPERTY)); apiGatewayProperties.setProperty(API_GATEWAY_STAGE_VARS_PROPERTY, servletRequest.getAttribute(API_GATEWAY_STAGE_VARS_PROPERTY)); apiGatewayProperties.setProperty(LAMBDA_CONTEXT_PROPERTY, servletRequest.getAttribute(LAMBDA_CONTEXT_PROPERTY)); apiGatewayProperties.setProperty(JERSEY_SERVLET_REQUEST_PROPERTY, servletRequest); ContainerRequest requestContext = new ContainerRequest( null, // jersey uses "/" by default uriBuilder.build(), servletRequest.getMethod().toUpperCase(Locale.ENGLISH), (SecurityContext)servletRequest.getAttribute(JAX_SECURITY_CONTEXT_PROPERTY), apiGatewayProperties); InputStream requestInputStream; try { requestInputStream = servletRequest.getInputStream(); if (requestInputStream != null) { requestContext.setEntityStream(requestInputStream); } } catch (IOException e) { log.error("Could not read input stream from request", e); throw new RuntimeException("Could not read request input stream", e); } Enumeration<String> headerNames = servletRequest.getHeaderNames(); while (headerNames.hasMoreElements()) { String headerKey = headerNames.nextElement(); requestContext.getHeaders().addAll(headerKey, Collections.list(servletRequest.getHeaders(headerKey))); } Timer.stop("JERSEY_SERVLET_REQUEST_TO_CONTAINER"); return requestContext; }