Search in sources :

Example 1 with JerseyClientBuilder

use of io.dropwizard.client.JerseyClientBuilder in project dropwizard by dropwizard.

the class App1Test method custom404OnViewRenderMissingMustacheTemplate.

@Test
public void custom404OnViewRenderMissingMustacheTemplate() {
    final Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test client 2");
    final String url = String.format("http://localhost:%d/view-with-missing-tpl", RULE.getLocalPort());
    final Response response = client.target(url).request().get();
    assertThat(response.getStatus()).isEqualTo(404);
}
Also used : Response(javax.ws.rs.core.Response) Client(javax.ws.rs.client.Client) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Example 2 with JerseyClientBuilder

use of io.dropwizard.client.JerseyClientBuilder in project dropwizard by dropwizard.

the class FormsAppTest method canSubmitFormAndReceiveResponse.

@Test
public void canSubmitFormAndReceiveResponse() {
    config.setChunkedEncodingEnabled(false);
    final Client client = new JerseyClientBuilder(RULE.getEnvironment()).using(config).build("test client 1");
    final MultiPart mp = new FormDataMultiPart().bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("file").fileName("fileName").build(), "CONTENT"));
    final String url = String.format("http://localhost:%d/uploadFile", RULE.getLocalPort());
    final String response = client.target(url).register(MultiPartFeature.class).request().post(Entity.entity(mp, mp.getMediaType()), String.class);
    assertThat(response).isEqualTo("fileName:\nCONTENT");
}
Also used : MultiPart(org.glassfish.jersey.media.multipart.MultiPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) Client(javax.ws.rs.client.Client) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Example 3 with JerseyClientBuilder

use of io.dropwizard.client.JerseyClientBuilder in project dropwizard by dropwizard.

the class FormsAppTest method failOnNoChunkedEncoding.

/** Test confirms that chunked encoding has to be disabled in order for sending forms to work.
     *  Maybe someday this requirement will be relaxed and this test can be updated for the new
     *  behavior. For more info, see issues #1013 and #1094 */
@Test
public void failOnNoChunkedEncoding() {
    final Client client = new JerseyClientBuilder(RULE.getEnvironment()).using(config).build("test client 2");
    final MultiPart mp = new FormDataMultiPart().bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("file").fileName("fileName").build(), "CONTENT"));
    final String url = String.format("http://localhost:%d/uploadFile", RULE.getLocalPort());
    final Response response = client.target(url).register(MultiPartFeature.class).request().post(Entity.entity(mp, mp.getMediaType()));
    assertThat(response.getStatus()).isEqualTo(400);
    assertThat(response.readEntity(ErrorMessage.class)).isEqualTo(new ErrorMessage(400, "HTTP 400 Bad Request"));
}
Also used : Response(javax.ws.rs.core.Response) MultiPart(org.glassfish.jersey.media.multipart.MultiPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) Client(javax.ws.rs.client.Client) ErrorMessage(io.dropwizard.jersey.errors.ErrorMessage) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Example 4 with JerseyClientBuilder

use of io.dropwizard.client.JerseyClientBuilder in project dropwizard by dropwizard.

the class AbstractRequestLogPatternIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    final JerseyClientConfiguration configuration = new JerseyClientConfiguration();
    configuration.setTimeout(Duration.seconds(2));
    client = new JerseyClientBuilder(dropwizardAppRule.getEnvironment()).using(configuration).build("test-request-logs");
}
Also used : JerseyClientConfiguration(io.dropwizard.client.JerseyClientConfiguration) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Before(org.junit.Before)

Example 5 with JerseyClientBuilder

use of io.dropwizard.client.JerseyClientBuilder in project dropwizard by dropwizard.

the class DropwizardSSLConnectionSocketFactoryTest method shouldBeOkIfHostnameVerificationOffAndServerHostnameDoesntMatch.

@Test
public void shouldBeOkIfHostnameVerificationOffAndServerHostnameDoesntMatch() throws Exception {
    tlsConfiguration.setVerifyHostname(false);
    final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).build("bad_host_working");
    final Response response = client.target(String.format("https://localhost:%d", TLS_APP_RULE.getPort(3))).request().get();
    assertThat(response.getStatus()).isEqualTo(200);
}
Also used : ClientResponse(org.glassfish.jersey.client.ClientResponse) Response(javax.ws.rs.core.Response) Client(javax.ws.rs.client.Client) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Aggregations

JerseyClientBuilder (io.dropwizard.client.JerseyClientBuilder)19 Client (javax.ws.rs.client.Client)18 Test (org.junit.Test)18 Response (javax.ws.rs.core.Response)11 ClientResponse (org.glassfish.jersey.client.ClientResponse)7 File (java.io.File)3 ProcessingException (javax.ws.rs.ProcessingException)3 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)3 FormDataBodyPart (org.glassfish.jersey.media.multipart.FormDataBodyPart)2 FormDataMultiPart (org.glassfish.jersey.media.multipart.FormDataMultiPart)2 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JerseyClientConfiguration (io.dropwizard.client.JerseyClientConfiguration)1 ErrorMessage (io.dropwizard.jersey.errors.ErrorMessage)1 NoopHostnameVerifier (org.apache.http.conn.ssl.NoopHostnameVerifier)1 Before (org.junit.Before)1