private Inflector<RequestProcessingContext, ContainerResponse> getInflector() { return uriRoutingContext.getEndpoint(); }
/** * Create new Jersey container request context. * * @param baseUri base application URI. * @param requestUri request URI. * @param httpMethod request HTTP method name. * @param securityContext security context of the current request. Must not be {@code null}. * The {@link SecurityContext#getUserPrincipal()} must return * {@code null} if the current request has not been authenticated * by the container. * @param propertiesDelegate custom {@link PropertiesDelegate properties delegate} * to be used by the context. */ public ContainerRequest( final URI baseUri, final URI requestUri, final String httpMethod, final SecurityContext securityContext, final PropertiesDelegate propertiesDelegate) { super(true); this.baseUri = baseUri == null ? DEFAULT_BASE_URI : baseUri.normalize(); this.requestUri = requestUri; this.httpMethod = httpMethod; this.securityContext = securityContext; this.propertiesDelegate = new TracingAwarePropertiesDelegate(propertiesDelegate); this.uriRoutingContext = new UriRoutingContext(this); }
@Override public UriBuilder getAbsolutePathBuilder() { return new JerseyUriBuilder().uri(getAbsolutePath()); }
@Override public void setRequestUri(final URI requestUri) throws IllegalStateException { if (!uriRoutingContext.getMatchedURIs().isEmpty()) { throw new IllegalStateException("Method could be called only in pre-matching request filter."); } this.encodedRelativePath = null; this.decodedRelativePath = null; this.absolutePathUri = null; this.uriRoutingContext.invalidateUriComponentViews(); this.requestUri = requestUri; }
@Override public void pushLeftHandPath() { final String rightHandPath = getFinalMatchingGroup(); final int rhpLength = (rightHandPath != null) ? rightHandPath.length() : 0; final String encodedRequestPath = getPath(false); final int length = encodedRequestPath.length() - rhpLength; if (length <= 0) { paths.addFirst(""); } else { paths.addFirst(encodedRequestPath.substring(0, length)); } }
@Override public List<PathSegment> getPathSegments(final String name, final boolean decode) { final int[] bounds = getPathParameterBounds(name); if (bounds != null) { final String path = matchResults.getLast().group(); // Work out how many path segments are up to the start // and end position of the matching path parameter value // This assumes that the path always starts with a '/' int segmentsStart = 0; for (int x = 0; x < bounds[0]; x++) { if (path.charAt(x) == '/') { segmentsStart++; } } int segmentsEnd = segmentsStart; for (int x = bounds[0]; x < bounds[1]; x++) { if (path.charAt(x) == '/') { segmentsEnd++; } } return getPathSegments(decode).subList(segmentsStart - 1, segmentsEnd); } else { return Collections.emptyList(); } }
@Override public List<String> getMatchedURIs() { return getMatchedURIs(true); }
@Override public URI resolve(final URI uri) { return UriTemplate.resolve(getBaseUri(), uri); }
@Override public void pushMatchedRuntimeResource(final RuntimeResource runtimeResource) { if (tracingLogger.isLogEnabled(ServerTraceEvent.MATCH_RUNTIME_RESOURCE)) { tracingLogger.log(ServerTraceEvent.MATCH_RUNTIME_RESOURCE, runtimeResource.getResources().get(0).getPath(), runtimeResource.getResources().get(0).getPathPattern().getRegex(), matchResults.peek().group() .substring(0, matchResults.peek().group().length() - getFinalMatchingGroup().length()), matchResults.peek().group()); } this.matchedRuntimeResources.push(runtimeResource); }
@Override public MultivaluedMap<String, String> getPathParameters() { return getPathParameters(true); }
private int[] getPathParameterBounds(final String name) { final Iterator<UriTemplate> templatesIterator = templates.iterator(); final Iterator<MatchResult> matchResultsIterator = matchResults.iterator(); while (templatesIterator.hasNext()) { MatchResult mr = matchResultsIterator.next(); // Find the index of path parameter final int pIndex = getLastPathParameterIndex(name, templatesIterator.next()); if (pIndex != -1) { int pathLength = mr.group().length(); int segmentIndex = mr.end(pIndex + 1); final int groupLength = segmentIndex - mr.start(pIndex + 1); // Find the absolute position of the end of the // capturing group in the request path while (matchResultsIterator.hasNext()) { mr = matchResultsIterator.next(); segmentIndex += mr.group().length() - pathLength; pathLength = mr.group().length(); } return new int[] {segmentIndex - groupLength, segmentIndex}; } } return null; }
@Override public void setRequestUri(final URI requestUri) throws IllegalStateException { if (!uriRoutingContext.getMatchedURIs().isEmpty()) { throw new IllegalStateException("Method could be called only in pre-matching request filter."); } this.encodedRelativePath = null; this.decodedRelativePath = null; this.absolutePathUri = null; this.uriRoutingContext.invalidateUriComponentViews(); this.requestUri = requestUri; }
@Override public void pushLeftHandPath() { final String rightHandPath = getFinalMatchingGroup(); final int rhpLength = (rightHandPath != null) ? rightHandPath.length() : 0; final String encodedRequestPath = getPath(false); final int length = encodedRequestPath.length() - rhpLength; if (length <= 0) { paths.addFirst(""); } else { paths.addFirst(encodedRequestPath.substring(0, length)); } }
@Override public List<PathSegment> getPathSegments(final String name, final boolean decode) { final int[] bounds = getPathParameterBounds(name); if (bounds != null) { final String path = matchResults.getLast().group(); // Work out how many path segments are up to the start // and end position of the matching path parameter value // This assumes that the path always starts with a '/' int segmentsStart = 0; for (int x = 0; x < bounds[0]; x++) { if (path.charAt(x) == '/') { segmentsStart++; } } int segmentsEnd = segmentsStart; for (int x = bounds[0]; x < bounds[1]; x++) { if (path.charAt(x) == '/') { segmentsEnd++; } } return getPathSegments(decode).subList(segmentsStart - 1, segmentsEnd); } else { return Collections.emptyList(); } }
@Override public List<String> getMatchedURIs() { return getMatchedURIs(true); }
@Override public URI resolve(final URI uri) { return UriTemplate.resolve(getBaseUri(), uri); }
@Override public void pushMatchedRuntimeResource(final RuntimeResource runtimeResource) { if (tracingLogger.isLogEnabled(ServerTraceEvent.MATCH_RUNTIME_RESOURCE)) { tracingLogger.log(ServerTraceEvent.MATCH_RUNTIME_RESOURCE, runtimeResource.getResources().get(0).getPath(), runtimeResource.getResources().get(0).getPathPattern().getRegex(), matchResults.peek().group() .substring(0, matchResults.peek().group().length() - getFinalMatchingGroup().length()), matchResults.peek().group()); } this.matchedRuntimeResources.push(runtimeResource); }
@Override public MultivaluedMap<String, String> getPathParameters() { return getPathParameters(true); }
private int[] getPathParameterBounds(final String name) { final Iterator<UriTemplate> templatesIterator = templates.iterator(); final Iterator<MatchResult> matchResultsIterator = matchResults.iterator(); while (templatesIterator.hasNext()) { MatchResult mr = matchResultsIterator.next(); // Find the index of path parameter final int pIndex = getLastPathParameterIndex(name, templatesIterator.next()); if (pIndex != -1) { int pathLength = mr.group().length(); int segmentIndex = mr.end(pIndex + 1); final int groupLength = segmentIndex - mr.start(pIndex + 1); // Find the absolute position of the end of the // capturing group in the request path while (matchResultsIterator.hasNext()) { mr = matchResultsIterator.next(); segmentIndex += mr.group().length() - pathLength; pathLength = mr.group().length(); } return new int[] {segmentIndex - groupLength, segmentIndex}; } } return null; }
@Override public void setRequestUri(final URI baseUri, final URI requestUri) throws IllegalStateException { if (!uriRoutingContext.getMatchedURIs().isEmpty()) { throw new IllegalStateException("Method could be called only in pre-matching request filter."); } this.encodedRelativePath = null; this.decodedRelativePath = null; this.absolutePathUri = null; this.uriRoutingContext.invalidateUriComponentViews(); this.baseUri = baseUri; this.requestUri = requestUri; OutboundJaxrsResponse.Builder.setBaseUri(baseUri); }