public WebApplicationContext createMatchResourceContext(URI u) { final URI base = request.getBaseUri(); if (u.isAbsolute()) { // TODO check if base is a base of u URI r = base.relativize(u); if (r == u) { throw new ContainerException("The URI " + u + " is not relative to the base URI " + base); } } else { u = UriBuilder.fromUri(base). path(u.getRawPath()). replaceQuery(u.getRawQuery()). fragment(u.getRawFragment()). build(); } final ContainerRequest _request = new ContainerRequest(app, HTTP_METHOD_MATCH_RESOURCE, base, u, new InBoundHeaders(), new ByteArrayInputStream(new byte[0])); _request.setSecurityContext(request.getSecurityContext()); // Propagate security context final ContainerResponse _response = new ContainerResponse(app, _request, null); return new WebApplicationContext(app, _request, _response); }
private WebApplicationContext handleMatchResourceRequest(URI u) { final WebApplicationContext oldContext = (WebApplicationContext)context.get(); final WebApplicationContext newContext = oldContext.createMatchResourceContext(u); context.set(newContext); try { _handleRequest(newContext, newContext.getContainerRequest()); return newContext; } finally { context.set(oldContext); } }
public void onHeader(String name, String value) { c.getContainerResponse().getHttpHeaders().add(name, value); } });
public WebApplicationContext(WebApplicationImpl app, ContainerRequest request, ContainerResponse response) { this.app = app; this.isTraceEnabled = app.isTracingEnabled(); this.request = request; this.response = response; this.responseFilters = Collections.EMPTY_LIST; if (isTracingEnabled()) { getProperties().put(TraceInformation.class.getName(), new TraceInformation(this)); } }
@Override public List<PathSegment> getPathSegments(String name, boolean decode) { int[] bounds = getPathParameterBounds(name); if (bounds != null) { 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<PathSegment> getPathSegments(String name) { return getPathSegments(name, true); }
@Override public MultivaluedMap<String, String> getPathParameters() { return getPathParameters(true); }
@Override public List<String> getMatchedURIs() { return getMatchedURIs(true); }
private int[] getPathParameterBounds(String name) { Iterator<UriTemplate> iTemplate = templates.iterator(); Iterator<MatchResult> iMatchResult = matchResults.iterator(); while (iTemplate.hasNext()) { MatchResult mr = iMatchResult.next(); // Find the index of path parameter int pIndex = getLastPathParameterIndex(name, iTemplate.next()); if (pIndex != -1) { int pathLength = mr.group().length(); int segmentIndex = mr.end(pIndex + 1); int groupLength = segmentIndex - mr.start(pIndex + 1); // Find the absolute position of the end of the // capturing group in the request path while (iMatchResult.hasNext()) { mr = iMatchResult.next(); segmentIndex += mr.group().length() - pathLength; pathLength = mr.group().length(); } int[] bounds = {segmentIndex - groupLength, segmentIndex}; return bounds; } } return null; }
public WebApplicationContext(WebApplicationImpl app, ContainerRequest request, ContainerResponse response) { this.app = app; this.isTraceEnabled = app.isTracingEnabled(); this.request = request; this.response = response; this.responseFilters = Collections.EMPTY_LIST; if (isTracingEnabled()) { getProperties().put(TraceInformation.class.getName(), new TraceInformation(this)); } }
@Override public List<PathSegment> getPathSegments(String name, boolean decode) { int[] bounds = getPathParameterBounds(name); if (bounds != null) { 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<PathSegment> getPathSegments(String name) { return getPathSegments(name, true); }
@Override public MultivaluedMap<String, String> getPathParameters() { return getPathParameters(true); }
@Override public List<String> getMatchedURIs() { return getMatchedURIs(true); }
private int[] getPathParameterBounds(String name) { Iterator<UriTemplate> iTemplate = templates.iterator(); Iterator<MatchResult> iMatchResult = matchResults.iterator(); while (iTemplate.hasNext()) { MatchResult mr = iMatchResult.next(); // Find the index of path parameter int pIndex = getLastPathParameterIndex(name, iTemplate.next()); if (pIndex != -1) { int pathLength = mr.group().length(); int segmentIndex = mr.end(pIndex + 1); int groupLength = segmentIndex - mr.start(pIndex + 1); // Find the absolute position of the end of the // capturing group in the request path while (iMatchResult.hasNext()) { mr = iMatchResult.next(); segmentIndex += mr.group().length() - pathLength; pathLength = mr.group().length(); } int[] bounds = {segmentIndex - groupLength, segmentIndex}; return bounds; } } return null; }
private WebApplicationContext handleMatchResourceRequest(URI u) { final WebApplicationContext oldContext = (WebApplicationContext)context.get(); final WebApplicationContext newContext = oldContext.createMatchResourceContext(u); context.set(newContext); try { _handleRequest(newContext, newContext.getContainerRequest()); return newContext; } finally { context.set(oldContext); } }
public WebApplicationContext(WebApplicationImpl app, ContainerRequest request, ContainerResponse response) { this.app = app; this.isTraceEnabled = app.isTracingEnabled(); this.request = request; this.response = response; this.responseFilters = Collections.EMPTY_LIST; if (isTracingEnabled()) { getProperties().put(TraceInformation.class.getName(), new TraceInformation(this)); } }
@Override public List<PathSegment> getPathSegments(String name, boolean decode) { int[] bounds = getPathParameterBounds(name); if (bounds != null) { 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 void handleRequest(ContainerRequest request, ContainerResponse response) throws IOException { final WebApplicationContext localContext = new WebApplicationContext(this, request, response); context.set(localContext); try { _handleRequest(localContext, request, response); } finally { PerRequestFactory.destroy(localContext); closeableFactory.close(localContext); context.set(null); } }
public void onHeader(String name, String value) { c.getContainerResponse().getHttpHeaders().add(name, value); } });