Java Code Examples for com.sun.jersey.spi.container.ContainerRequest#getPath()
The following examples show how to use
com.sun.jersey.spi.container.ContainerRequest#getPath() .
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: URITranslator.java From secure-data-service with Apache License 2.0 | 6 votes |
public void translate(ContainerRequest request) { String uri = request.getPath(); List<PathSegment> segments = request.getPathSegments(); String version = PathConstants.V1; if (!segments.isEmpty()) { version = segments.get(0).getPath(); } for (Map.Entry<String, URITranslation> entry : uriTranslationMap.entrySet()) { String key = entry.getKey(); if (uri.contains(key)) { String newPath = uriTranslationMap.get(key).translate(request.getPath()); if (!newPath.equals(uri)) { request.setUris(request.getBaseUri(), request.getBaseUriBuilder().path(version).path(newPath).build()); } } } }
Example 2
Source File: DateSearchFilter.java From secure-data-service with Apache License 2.0 | 6 votes |
/** * Verifies that if a date range is specified that the request URI * is allowed to be searched via date ranges * @param request */ private void validateDateSearchUri(ContainerRequest request) { String requestPath = request.getPath(); Matcher m = ID_REPLACEMENT_PATTERN.matcher(requestPath); if (m.matches()){ // transform requestPath from "v1.x/foo/2344,3453,5345/bar" to "v1.x/foo/{id}/bar" requestPath = m.group(1) + PathConstants.ID_PLACEHOLDER + m.group(2); } if (this.resourceEndPoint.getDateRangeDisallowedEndPoints().contains(requestPath)) { List<String> schoolYears = request.getQueryParameters().get(ParameterConstants.SCHOOL_YEARS); if (schoolYears != null && schoolYears.size() > 0){ throw new QueryParseException("Date range filtering not allowed", request.getPath()); } } }
Example 3
Source File: PreProcessFilter.java From secure-data-service with Apache License 2.0 | 6 votes |
/** * Validate the request URL is not blocked * * @param request */ private void validateNotBlockGetRequest(ContainerRequest request) { if (!request.getMethod().equals(RequestMethod.GET.name())) { return; } String requestPath = request.getPath(); Matcher m = ID_REPLACEMENT_PATTERN.matcher(requestPath); if (m.matches()) { // transform requestPath from "v1.x/foo/2344,3453,5345/bar" to // "v1.x/foo/{id}/bar" requestPath = m.group(1) + PathConstants.ID_PLACEHOLDER + m.group(2); } if (this.resourceEndPoint.getBlockGetRequestEndPoints().contains(requestPath)) { throw new RequestBlockedException(request.getPath()); } }
Example 4
Source File: DateSearchFilter.java From secure-data-service with Apache License 2.0 | 5 votes |
private void validateNonTwoPartUri(ContainerRequest request) { String requestPath = request.getPath(); Matcher m = TWO_PART_URI_PATTERN.matcher(requestPath); if (m.find()){ throw new QueryParseException("Date range filtering not allowed", request.getPath()); } }
Example 5
Source File: DateSearchFilter.java From secure-data-service with Apache License 2.0 | 5 votes |
/** * Dissallows any date range searches for v1.0 URIs * @param request */ private void validateNotVersionOneZero(ContainerRequest request) { List<PathSegment> segments = request.getPathSegments(); if (segments.size() > 0) { String version = segments.get(0).getPath(); if (PathConstants.V1_0.equals(version)) { List<String> schoolYears = request.getQueryParameters().get(ParameterConstants.SCHOOL_YEARS); if (schoolYears != null && schoolYears.size() > 0){ throw new QueryParseException("Date range filtering not allowed", request.getPath()); } } } }
Example 6
Source File: PostProcessFilter.java From secure-data-service with Apache License 2.0 | 4 votes |
@Override public ContainerResponse filter(ContainerRequest request, ContainerResponse response) { if (isRead(request.getMethod()) && isSuccessfulRead(response.getStatus())) { if (contextValidator.isUrlBlocked(request)) { throw new APIAccessDeniedException(String.format("url %s is not accessible.", request.getAbsolutePath().toString())); } SLIPrincipal principal = (SLIPrincipal) SecurityContextHolder.getContext().getAuthentication() .getPrincipal(); principal.setSubEdOrgHierarchy(edOrgHelper.getStaffEdOrgsAndChildren()); contextValidator.validateContextToUri(request, principal); } SecurityContextHolder.clearContext(); if ("true".equals(apiPerformanceTracking)) { logApiDataToDb(request, response); } TenantContext.cleanup(); printElapsed(request); expireCache(); String queryString = ""; if (null != request.getRequestUri().getQuery()) { queryString = "?" + request.getRequestUri().getQuery(); } String executedPath = request.getPath() + queryString; // Truncate the executed path to avoid issues with response header length being too long for the servlet container if (executedPath != null && executedPath.length() > maxResponseHeaderXexecutedPath) { executedPath = executedPath.substring(0, Math.min(executedPath.length(), maxResponseHeaderXexecutedPath)); } response.getHttpHeaders().add("X-RequestedPath", request.getProperties().get("requestedPath")); response.getHttpHeaders().add("X-ExecutedPath", executedPath); // Map<String,Object> body = (Map<String, Object>) response.getEntity(); // body.put("requestedPath", request.getProperties().get("requestedPath")); // body.put("executedPath", request.getPath()); return response; }