Search in sources :

Example 6 with RequestContextBuilder

use of org.glassfish.jersey.server.RequestContextBuilder in project jersey by jersey.

the class EncodedParamsTest method testCombinedEncodedOnPostClass.

@Test
public void testCombinedEncodedOnPostClass() throws ExecutionException, InterruptedException {
    initiateWebApplication(EncodedOnPostClass.class);
    Form form = new Form();
    form.param("f", ":f");
    form.param("f2", ":f2");
    RequestContextBuilder requestBuilder = RequestContextBuilder.from("/%20u/combined;m=%20m?q=%20q", "POST").type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).entity(form);
    assertEquals("content", apply(requestBuilder.build()).getEntity());
}
Also used : Form(javax.ws.rs.core.Form) RequestContextBuilder(org.glassfish.jersey.server.RequestContextBuilder) Test(org.junit.Test)

Example 7 with RequestContextBuilder

use of org.glassfish.jersey.server.RequestContextBuilder in project jersey by jersey.

the class EncodingFilterTest method testEncoding.

private void testEncoding(String expected, String... accepted) throws IOException {
    EncodingFilter filter = initializeAndGetFilter();
    RequestContextBuilder builder = RequestContextBuilder.from("/resource", "GET");
    for (String a : accepted) {
        builder.header(HttpHeaders.ACCEPT_ENCODING, a);
    }
    ContainerRequest request = builder.build();
    ContainerResponse response = new ContainerResponse(request, Response.ok("OK!").build());
    filter.filter(request, response);
    if (response.getStatus() != 200) {
        throw new WebApplicationException(Response.status(response.getStatus()).build());
    }
    assertEquals(expected, response.getHeaderString(HttpHeaders.CONTENT_ENCODING));
    assertEquals(HttpHeaders.ACCEPT_ENCODING, response.getHeaderString(HttpHeaders.VARY));
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) WebApplicationException(javax.ws.rs.WebApplicationException) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) RequestContextBuilder(org.glassfish.jersey.server.RequestContextBuilder)

Aggregations

RequestContextBuilder (org.glassfish.jersey.server.RequestContextBuilder)7 Form (javax.ws.rs.core.Form)3 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)2 WebApplicationException (javax.ws.rs.WebApplicationException)1