Search in sources :

Example 16 with UriBuilder

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);
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Test(org.junit.Test)

Example 17 with UriBuilder

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());
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) Test(org.junit.Test)

Example 18 with UriBuilder

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());
}
Also used : HashMap(java.util.HashMap) UriBuilder(javax.ws.rs.core.UriBuilder) Test(org.junit.Test)

Example 19 with UriBuilder

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());
            }
        }
    }
}
Also used : Form(javax.ws.rs.core.Form) BadRequestException(javax.ws.rs.BadRequestException) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) List(java.util.List) UriBuilder(javax.ws.rs.core.UriBuilder) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Map(java.util.Map)

Example 20 with UriBuilder

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);
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Test(org.junit.Test)

Aggregations

UriBuilder (javax.ws.rs.core.UriBuilder)123 URI (java.net.URI)45 Test (org.junit.Test)42 HashMap (java.util.HashMap)15 Consumes (javax.ws.rs.Consumes)15 Link (org.eclipse.che.api.core.rest.shared.dto.Link)15 PUT (javax.ws.rs.PUT)11 IOException (java.io.IOException)10 Path (javax.ws.rs.Path)10 ArrayList (java.util.ArrayList)8 Produces (javax.ws.rs.Produces)8 LinksHelper.createLink (org.eclipse.che.api.core.util.LinksHelper.createLink)8 GET (javax.ws.rs.GET)7 URL (java.net.URL)6 ServerException (org.eclipse.che.api.core.ServerException)6 POST (javax.ws.rs.POST)5 ApiException (org.eclipse.che.api.core.ApiException)4 WorkspaceService (org.eclipse.che.api.workspace.server.WorkspaceService)4 ExternalTestContainerFactory (org.glassfish.jersey.test.external.ExternalTestContainerFactory)4 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)3