use of javax.ws.rs.core.UriBuilder in project jersey by jersey.
the class JerseyUriBuilderTest method testReplaceQueryParamsEncoded3.
@Test
public void testReplaceQueryParamsEncoded3() throws URISyntaxException {
final UriBuilder ubu = UriBuilder.fromUri("http://localhost/").replaceQuery("limit=10&sql=select+*+from+users");
ubu.replaceQueryParam("limit", 100);
final URI uri = ubu.build();
Assert.assertEquals(URI.create("http://localhost/?limit=100&sql=select+%2A+from+users"), uri);
}
use of javax.ws.rs.core.UriBuilder in project jersey by jersey.
the class JerseyUriBuilderTest method testQueryParamEncoded3.
@Test
public void testQueryParamEncoded3() {
final UriBuilder uriBuilder = UriBuilder.fromUri("http://localhost:8080/path");
uriBuilder.queryParam("query", "{param}");
Assert.assertEquals("http://localhost:8080/path?query=%2525test", uriBuilder.build("%25test").toString());
}
use of javax.ws.rs.core.UriBuilder in project jersey by jersey.
the class JerseyUriBuilderTest method resolveTemplatesEncodeSlash.
@Test
public void resolveTemplatesEncodeSlash() {
final UriBuilder uriBuilder = UriBuilder.fromPath("http://localhost:8080").path("{a}").path("{b}").path("{c}").queryParam("query", "{q}");
final Map<String, Object> resolveMap = new HashMap<String, Object>();
resolveMap.put("a", "x/y/z%3F%20");
resolveMap.put("q", "q?%20%26");
resolveMap.put("c", "paramc1/paramc2");
uriBuilder.resolveTemplates(resolveMap, false);
final Map<String, Object> buildMap = new HashMap<String, Object>();
buildMap.put("b", "param-b/aaa");
Assert.assertEquals("http://localhost:8080/x/y/z%253F%2520/param-b/aaa/paramc1/paramc2?query=q%3F%2520%2526", uriBuilder.buildFromMap(buildMap, false).toString());
}
use of javax.ws.rs.core.UriBuilder in project jersey by jersey.
the class HttpMethodOverrideFilter method filter.
@Override
public void filter(final ContainerRequestContext request) {
if (!request.getMethod().equalsIgnoreCase("POST")) {
return;
}
final String header = getParamValue(Source.HEADER, request.getHeaders(), "X-HTTP-Method-Override");
final String query = getParamValue(Source.QUERY, request.getUriInfo().getQueryParameters(), "_method");
final String override;
if (header == null) {
override = query;
} else {
override = header;
if (query != null && !query.equals(header)) {
// inconsistent query and header param values
throw new BadRequestException();
}
}
if (override != null) {
request.setMethod(override);
if (override.equals("GET")) {
if (request.getMediaType() != null && MediaType.APPLICATION_FORM_URLENCODED_TYPE.getType().equals(request.getMediaType().getType())) {
final UriBuilder ub = request.getUriInfo().getRequestUriBuilder();
final Form f = ((ContainerRequest) request).readEntity(Form.class);
for (final Map.Entry<String, List<String>> param : f.asMap().entrySet()) {
ub.queryParam(param.getKey(), param.getValue().toArray());
}
request.setRequestUri(request.getUriInfo().getBaseUri(), ub.build());
}
}
}
}
use of javax.ws.rs.core.UriBuilder in project jersey by jersey.
the class JerseyUriBuilderTest method testClone.
@Test
public void testClone() {
final UriBuilder ub = UriBuilder.fromUri("http://user@localhost:8080/?query#fragment").path("a");
final URI full = ub.clone().path("b").build();
final URI base = ub.build();
Assert.assertEquals(URI.create("http://user@localhost:8080/a?query#fragment"), base);
Assert.assertEquals(URI.create("http://user@localhost:8080/a/b?query#fragment"), full);
}
Aggregations