use of javax.ws.rs.core.PathSegment in project scheduling by ow2-proactive.
the class WorkflowVariablesTransformerTest method testTwoVariablesMap.
@Test
public void testTwoVariablesMap() {
Map<String, String> expectedVariables = Maps.newHashMap();
expectedVariables.put("KEY1", "VALUE1");
expectedVariables.put("KEY2", "VALUE2");
PathSegment pathSegment = mock(PathSegment.class);
MultivaluedMap<String, String> multivalueMap = new MultivaluedHashMap();
multivalueMap.put("KEY1", Lists.newArrayList("VALUE1"));
multivalueMap.put("KEY2", Lists.newArrayList("VALUE2"));
when(pathSegment.getMatrixParameters()).thenReturn(multivalueMap);
Map<String, String> variables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);
assertThat(variables, is(expectedVariables));
}
use of javax.ws.rs.core.PathSegment in project Payara by payara.
the class Util method getBasePathFromUri.
private static String getBasePathFromUri(UriInfo uriInfo) {
List<PathSegment> pathSegments = uriInfo.getPathSegments();
// Discard the last segment if it is empty. This happens if some one accesses the resource
// with trailing '/' at end like in htto://host:port/mangement/domain/.../pathelement/
PathSegment lastSegment = pathSegments.get(pathSegments.size() - 1);
if (lastSegment.getPath().isEmpty()) {
pathSegments = pathSegments.subList(0, pathSegments.size() - 1);
}
List<PathSegment> candidatePathSegment = null;
if (pathSegments.size() != 1) {
// Discard "domain"
candidatePathSegment = pathSegments.subList(1, pathSegments.size());
} else {
// We are being called for a config change at domain level.
// CLI "set" requires name to be of form domain.<attribute-name>.
// Preserve "domain"
candidatePathSegment = pathSegments;
}
final StringBuilder sb = new StringBuilder();
for (PathSegment pathSegment : candidatePathSegment) {
sb.append(pathSegment.getPath());
sb.append('.');
}
return sb.toString();
}
use of javax.ws.rs.core.PathSegment in project druid by druid-io.
the class DatasourceResourceFilter 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("datasources");
}
}) + 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 druid by druid-io.
the class TaskResourceFilter 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 taskId = Preconditions.checkNotNull(request.getPathSegments().get(Iterables.indexOf(request.getPathSegments(), new Predicate<PathSegment>() {
@Override
public boolean apply(PathSegment input) {
return input.getPath().equals("task");
}
}) + 1).getPath());
Optional<Task> taskOptional = taskStorageQueryAdapter.getTask(taskId);
if (!taskOptional.isPresent()) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(String.format("Cannot find any task with id: [%s]", taskId)).build());
}
final String dataSourceName = Preconditions.checkNotNull(taskOptional.get().getDataSource());
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 TaxonomyServiceTest method testGetSubTerms_instance.
@Test
public void testGetSubTerms_instance() 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");
JsonSerializer serializer = createStrictMock(JsonSerializer.class);
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");
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("testTerm2");
expect(termResourceProvider.getResourceById(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");
Request request = requestCapture.getValue();
assertEquals(request.getQueryProperties().size(), 1);
TermPath termPath = (TermPath) request.getQueryProperties().get("termPath");
assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm.testTerm2");
assertNull(request.getQueryString());
assertEquals(response.getStatus(), 200);
assertEquals(response.getEntity(), "Taxonomy Term Get Response");
verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3);
}
Aggregations