Java Code Examples for javax.ws.rs.core.UriInfo#getPathSegments()
The following examples show how to use
javax.ws.rs.core.UriInfo#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: RequestDispatcherProvider.java From cxf with Apache License 2.0 | 6 votes |
protected void setRequestParameters(HttpServletRequestFilter request) { if (getMessageContext() != null) { UriInfo ui = getMessageContext().getUriInfo(); MultivaluedMap<String, String> params = ui.getPathParameters(); for (Map.Entry<String, List<String>> entry : params.entrySet()) { String value = entry.getValue().get(0); int ind = value.indexOf(';'); if (ind > 0) { value = value.substring(0, ind); } request.setParameter(entry.getKey(), value); } List<PathSegment> segments = ui.getPathSegments(); if (!segments.isEmpty()) { doSetRequestParameters(request, segments.get(segments.size() - 1).getMatrixParameters()); } doSetRequestParameters(request, ui.getQueryParameters()); request.setParameter(ABSOLUTE_PATH_PARAMETER, ui.getAbsolutePath().toString()); request.setParameter(RELATIVE_PATH_PARAMETER, ui.getPath()); request.setParameter(BASE_PATH_PARAMETER, ui.getBaseUri().toString()); request.setParameter(WEBAPP_BASE_PATH_PARAMETER, (String)getMessageContext().get("http.base.path")); } }
Example 2
Source File: GetResponseBuilder.java From secure-data-service with Apache License 2.0 | 6 votes |
/** * Throws a QueryParseException if the end user tried to query an endpoint that does * not support querying. * * * @param uriInfo */ protected void validatePublicResourceQuery(final UriInfo uriInfo) { List<PathSegment> uriPathSegments = uriInfo.getPathSegments(); if (uriPathSegments != null) { // if of the form "v1/foo" if (uriPathSegments.size() == 2) { String endpoint = uriPathSegments.get(1).getPath(); // if that endpoint does not allow querying if (this.resourceEndPoint.getQueryingDisallowedEndPoints().contains(endpoint)) { ApiQuery apiQuery = new ApiQuery(uriInfo); // if the user tried to execute a query/filter if (apiQuery.getCriteria().size() > 0) { throw new QueryParseException("Querying not allowed", apiQuery.toString()); } } } } }
Example 3
Source File: TaxonomyService.java From incubator-atlas with Apache License 2.0 | 5 votes |
@GET @Path("{taxonomyName}/terms/{rootTerm}/{remainder:.*}") @Produces(Servlets.JSON_MEDIA_TYPE) public Response getSubTerms(@Context HttpHeaders headers, @Context UriInfo ui, @PathParam("taxonomyName") String taxonomyName, @PathParam("rootTerm") String rootTerm, @PathParam("remainder") String remainder) throws CatalogException { AtlasPerfTracer perf = null; try { if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.getSubTerms(" + taxonomyName + ", " + rootTerm + ", " + remainder + ")"); } Result result; String termName = String.format("%s%s", rootTerm, remainder.replaceAll("/?terms/?([.]*)", "$1.")); String queryString = decode(getQueryString(ui)); TermPath termPath = new TermPath(taxonomyName, termName); Map<String, Object> properties = new HashMap<>(); properties.put("termPath", termPath); List<PathSegment> pathSegments = ui.getPathSegments(); int lastIndex = pathSegments.size() - 1; String lastSegment = pathSegments.get(lastIndex).getPath(); if (lastSegment.equals("terms") || (lastSegment.isEmpty() && pathSegments.get(lastIndex - 1).getPath().equals("terms"))) { result = getResources(termResourceProvider, new CollectionRequest(properties, queryString)); } else { result = getResource(termResourceProvider, new InstanceRequest(properties)); } return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); } finally { AtlasPerfTracer.log(perf); } }