use of javax.ws.rs.core.UriInfo in project che by eclipse.
the class FactoryService method getFactoryByAttribute.
@GET
@Path("/find")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Get factory by attribute, " + "the attribute must match one of the Factory model fields with type 'String', " + "e.g. (factory.name, factory.creator.name)", notes = "If specify more than one value for a single query parameter then will be taken the first one")
@ApiResponses({ @ApiResponse(code = 200, message = "Response contains list requested factories"), @ApiResponse(code = 400, message = "When query does not contain at least one attribute to search for"), @ApiResponse(code = 500, message = "Internal server error") })
public List<FactoryDto> getFactoryByAttribute(@DefaultValue("0") @QueryParam("skipCount") Integer skipCount, @DefaultValue("30") @QueryParam("maxItems") Integer maxItems, @Context UriInfo uriInfo) throws BadRequestException, ServerException {
final Set<String> skip = ImmutableSet.of("token", "skipCount", "maxItems");
final List<Pair<String, String>> query = URLEncodedUtils.parse(uriInfo.getRequestUri()).entrySet().stream().filter(param -> !skip.contains(param.getKey()) && !param.getValue().isEmpty()).map(entry -> Pair.of(entry.getKey(), entry.getValue().iterator().next())).collect(toList());
checkArgument(!query.isEmpty(), "Query must contain at least one attribute");
final List<FactoryDto> factories = new ArrayList<>();
for (Factory factory : factoryManager.getByAttribute(maxItems, skipCount, query)) {
factories.add(injectLinks(asDto(factory), null));
}
return factories;
}
use of javax.ws.rs.core.UriInfo in project jersey by jersey.
the class UriRoutingContextTest method testGetQueryParametersEmptyValues.
/**
* Migrated Jersey 1.x {@code com.sun.jersey.impl.QueryParametersHttpRequestTest}.
*/
@Test
public void testGetQueryParametersEmptyValues() throws Exception {
final UriInfo ui = createContext("/widgets/10?one&two&three", "GET");
MultivaluedMap<String, String> p = ui.getQueryParameters();
assertEquals(p.getFirst("one"), "");
assertEquals(p.getFirst("two"), "");
assertEquals(p.getFirst("three"), "");
}
use of javax.ws.rs.core.UriInfo in project jersey by jersey.
the class UriRoutingContextTest method testGetQueryParametersEncoded.
/**
* Migrated Jersey 1.x {@code com.sun.jersey.impl.QueryParametersHttpRequestTest}.
*/
@Test
public void testGetQueryParametersEncoded() throws Exception {
final UriInfo ui = createContext("/widgets/10?x+=+1%20&%20y+=+2", "GET");
MultivaluedMap<String, String> p = ui.getQueryParameters(false);
assertEquals("+1%20", p.getFirst("x "));
assertEquals("+2", p.getFirst(" y "));
}
use of javax.ws.rs.core.UriInfo in project jersey by jersey.
the class UriRoutingContextTest method testGetPathSegmentsMultipleSlash.
/**
* Migrated Jersey 1.x {@code com.sun.jersey.impl.PathSegmentsHttpRequestTest}.
*/
@Test
public void testGetPathSegmentsMultipleSlash() {
final UriInfo ui = createContext("/p//p//p//", "GET");
List<PathSegment> segments = ui.getPathSegments();
assertEquals(7, segments.size());
final Iterator<PathSegment> psi = segments.iterator();
PathSegment segment;
segment = psi.next();
assertEquals("p", segment.getPath());
assertEquals(0, segment.getMatrixParameters().size());
segment = psi.next();
assertEquals("", segment.getPath());
assertEquals(0, segment.getMatrixParameters().size());
segment = psi.next();
assertEquals("p", segment.getPath());
assertEquals(0, segment.getMatrixParameters().size());
segment = psi.next();
assertEquals("", segment.getPath());
assertEquals(0, segment.getMatrixParameters().size());
segment = psi.next();
assertEquals("p", segment.getPath());
assertEquals(0, segment.getMatrixParameters().size());
segment = psi.next();
assertEquals("", segment.getPath());
assertEquals(0, segment.getMatrixParameters().size());
segment = psi.next();
assertEquals("", segment.getPath());
assertEquals(0, segment.getMatrixParameters().size());
}
use of javax.ws.rs.core.UriInfo in project jersey by jersey.
the class UriRoutingContextTest method testGetPathSegmentsMultipleSlashmulitpleMatrix.
/**
* Migrated Jersey 1.x {@code com.sun.jersey.impl.PathSegmentsHttpRequestTest}.
*/
@Test
public void testGetPathSegmentsMultipleSlashmulitpleMatrix() {
final UriInfo ui = createContext("/;x=1;y=1/;x=2;y=2/;x=3;y=3", "GET");
List<PathSegment> segments = ui.getPathSegments();
assertEquals(3, segments.size());
final Iterator<PathSegment> psi = segments.iterator();
PathSegment segment;
segment = psi.next();
MultivaluedMap<String, String> m = segment.getMatrixParameters();
assertEquals("1", m.getFirst("x"));
assertEquals("1", m.getFirst("y"));
segment = psi.next();
m = segment.getMatrixParameters();
assertEquals("2", m.getFirst("x"));
assertEquals("2", m.getFirst("y"));
segment = psi.next();
m = segment.getMatrixParameters();
assertEquals("3", m.getFirst("x"));
assertEquals("3", m.getFirst("y"));
}
Aggregations