javax.ws.rs.core.UriBuilder#replaceQuery()源码实例Demo

下面列出了javax.ws.rs.core.UriBuilder#replaceQuery() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cxf   文件: AbstractClient.java
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;
}
 
源代码2 项目: keycloak   文件: FreeMarkerLoginFormsProvider.java
/**
 * 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;
}
 
源代码3 项目: secure-data-service   文件: VersionFilter.java
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;
}
 
源代码4 项目: rest-schemagen   文件: LinkCreator.java
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;
}
 
源代码5 项目: cxf   文件: WebClient.java
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());
    }

}
 
/**
 * 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;
}