use of javax.ws.rs.core.PathSegment in project druid by druid-io.
the class RulesResourceFilter method filter.
@Override
public ContainerRequest filter(ContainerRequest request) {
if (getAuthConfig().isEnabled()) {
// This is an experimental feature, see - https://github.com/druid-io/druid/pull/2424
final String dataSourceName = request.getPathSegments().get(Iterables.indexOf(request.getPathSegments(), new Predicate<PathSegment>() {
@Override
public boolean apply(PathSegment input) {
return input.getPath().equals("rules");
}
}) + 1).getPath();
Preconditions.checkNotNull(dataSourceName);
final AuthorizationInfo authorizationInfo = (AuthorizationInfo) getReq().getAttribute(AuthConfig.DRUID_AUTH_TOKEN);
Preconditions.checkNotNull(authorizationInfo, "Security is enabled but no authorization info found in the request");
final Access authResult = authorizationInfo.isAuthorized(new Resource(dataSourceName, ResourceType.DATASOURCE), getAction(request));
if (!authResult.isAllowed()) {
throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity(String.format("Access-Check-Result: %s", authResult.toString())).build());
}
}
return request;
}
use of javax.ws.rs.core.PathSegment in project incubator-atlas by apache.
the class TaxonomyService method getSubTerms.
@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);
}
}
use of javax.ws.rs.core.PathSegment in project incubator-atlas by apache.
the class TaxonomyServiceTest method testGetSubTerms_collection.
@Test
public void testGetSubTerms_collection() throws Exception {
MetadataService metadataService = createStrictMock(MetadataService.class);
AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class);
ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
UriInfo uriInfo = createNiceMock(UriInfo.class);
URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm/terms/testTerm2/terms?name:testTaxonomy.testTerm.testTerm2.testTerm3");
JsonSerializer serializer = createStrictMock(JsonSerializer.class);
// would actually be more segments but at this time only the last segment is used
PathSegment segment1 = createNiceMock(PathSegment.class);
PathSegment segment2 = createNiceMock(PathSegment.class);
PathSegment segment3 = createNiceMock(PathSegment.class);
Capture<Request> requestCapture = newCapture();
Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>();
Map<String, Object> propertyMap = new HashMap<>();
propertyMap.put("name", "testTaxonomy.testTerm.testTerm2.testTerm3");
resultPropertyMaps.add(propertyMap);
Result result = new Result(resultPropertyMaps);
// set mock expectations
expect(uriInfo.getRequestUri()).andReturn(uri);
expect(uriInfo.getPathSegments()).andReturn(Arrays.asList(segment1, segment2, segment3));
expect(segment3.getPath()).andReturn("terms");
expect(termResourceProvider.getResources(capture(requestCapture))).andReturn(result);
expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Term Get Response");
expect(metadataService.getTypeDefinition(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE)).andReturn(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE + "-definition");
replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3);
// instantiate service and invoke method being tested
TestTaxonomyService service = new TestTaxonomyService(metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer);
Response response = service.getSubTerms(null, uriInfo, "testTaxonomy", "testTerm", "/terms/testTerm2/terms");
Request request = requestCapture.getValue();
assertEquals(request.getQueryProperties().size(), 1);
TermPath termPath = (TermPath) request.getQueryProperties().get("termPath");
assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm.testTerm2.");
assertEquals(request.getQueryString(), "name:testTaxonomy.testTerm.testTerm2.testTerm3");
assertEquals(response.getStatus(), 200);
assertEquals(response.getEntity(), "Taxonomy Term Get Response");
verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3);
}
use of javax.ws.rs.core.PathSegment in project cxf by apache.
the class RequestDispatcherProvider method setRequestParameters.
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"));
}
}
use of javax.ws.rs.core.PathSegment in project cxf by apache.
the class XSLTJaxbProvider method createTemplates.
protected Templates createTemplates(Templates templates, Map<String, Object> configuredParams, Map<String, String> outProps) {
if (templates == null) {
if (supportJaxbOnly) {
return null;
}
LOG.severe("No template is available");
throw ExceptionUtils.toInternalServerErrorException(null, null);
}
TemplatesImpl templ = new TemplatesImpl(templates, uriResolver);
MessageContext mc = getContext();
if (mc != null) {
UriInfo ui = mc.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);
}
templ.setTransformerParameter(entry.getKey(), value);
}
List<PathSegment> segments = ui.getPathSegments();
if (!segments.isEmpty()) {
setTransformParameters(templ, segments.get(segments.size() - 1).getMatrixParameters());
}
setTransformParameters(templ, ui.getQueryParameters());
templ.setTransformerParameter(ABSOLUTE_PATH_PARAMETER, ui.getAbsolutePath().toString());
templ.setTransformerParameter(RELATIVE_PATH_PARAMETER, ui.getPath());
templ.setTransformerParameter(BASE_PATH_PARAMETER, ui.getBaseUri().toString());
if (configuredParams != null) {
for (Map.Entry<String, Object> entry : configuredParams.entrySet()) {
templ.setTransformerParameter(entry.getKey(), entry.getValue());
}
}
}
if (outProps != null) {
templ.setOutProperties(outProps);
}
return templ;
}
Aggregations