Java Code Examples for org.apache.cxf.jaxrs.utils.JAXRSUtils#getPathSegments()

The following examples show how to use org.apache.cxf.jaxrs.utils.JAXRSUtils#getPathSegments() . 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: WebClient.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Goes back
 * @param fast if true then goes back to baseURI otherwise to a previous path segment
 * @return updated WebClient
 */
public WebClient back(boolean fast) {
    getState().setTemplates(null);
    if (fast) {
        getCurrentBuilder().replacePath(getBaseURI().getPath());
    } else {
        URI uri = getCurrentURI();
        if (uri == getBaseURI()) {
            return this;
        }
        List<PathSegment> segments = JAXRSUtils.getPathSegments(uri.getPath(), false);
        getCurrentBuilder().replacePath(null);
        for (int i = 0; i < segments.size() - 1; i++) {
            getCurrentBuilder().path(HttpUtils.fromPathSegment(segments.get(i)));
        }

    }
    return this;
}
 
Example 2
Source File: UriBuilderImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setPathAndMatrix(String path) {
    leadingSlash = !originalPathEmpty && path.startsWith("/");
    paths = JAXRSUtils.getPathSegments(path, false, false);
    if (!paths.isEmpty()) {
        matrix = paths.get(paths.size() - 1).getMatrixParameters();
    } else {
        matrix.clear();
    }
}
 
Example 3
Source File: UriBuilderImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
private UriBuilder doPath(String path, boolean checkSegments) {
    if (path == null) {
        throw new IllegalArgumentException("path is null");
    }
    if (isAbsoluteUriPath(path)) {
        try {
            URI uri = URI.create(path);
            this.originalPathEmpty = StringUtils.isEmpty(uri.getPath());
            uri(uri);
        } catch (IllegalArgumentException ex) {
            if (!URITemplate.createExactTemplate(path).getVariables().isEmpty()) {
                return uriAsTemplate(path);
            }
            String pathEncoded = HttpUtils.pathEncode(path);
            // Bad hack to bypass the TCK usage of bogus URI with empty paths containing matrix parameters,
            // which even URI class chokes upon; cheaper to do the following than try to challenge,
            // given that URI RFC mentions the possibility of empty paths, though no word on the possibility of
            // such empty paths having matrix parameters...
            int schemeIndex = pathEncoded.indexOf("//");
            if (schemeIndex != -1) {
                int pathComponentStart = pathEncoded.indexOf("/", schemeIndex + 2);
                if (pathComponentStart == -1) {
                    this.originalPathEmpty = true;
                    pathComponentStart = pathEncoded.indexOf(';');
                    if (pathComponentStart != -1) {
                        pathEncoded = pathEncoded.substring(0, pathComponentStart)
                            + "/" + pathEncoded.substring(pathComponentStart);
                    }
                }
            }
            setUriParts(URI.create(pathEncoded));
        }
        return this;
    }

    if (paths.isEmpty()) {
        leadingSlash = path.startsWith("/");
    }

    List<PathSegment> segments;
    if (checkSegments) {
        segments = JAXRSUtils.getPathSegments(path, false, false);
    } else {
        segments = new ArrayList<>();
        path = path.replaceAll("/", "%2F");
        segments.add(new PathSegmentImpl(path, false));
    }
    if (!paths.isEmpty() && !matrix.isEmpty()) {
        PathSegment ps = paths.remove(paths.size() - 1);
        paths.add(replacePathSegment(ps));
    }
    paths.addAll(segments);
    matrix.clear();
    if (!paths.isEmpty()) {
        matrix = paths.get(paths.size() - 1).getMatrixParameters();
    }
    return this;
}
 
Example 4
Source File: UriInfoImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public List<PathSegment> getPathSegments(boolean decode) {
    return JAXRSUtils.getPathSegments(getPath(false), decode);
}