本文整理匯總了Java中io.dropwizard.client.JerseyClientBuilder類的典型用法代碼示例。如果您正苦於以下問題:Java JerseyClientBuilder類的具體用法?Java JerseyClientBuilder怎麽用?Java JerseyClientBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JerseyClientBuilder類屬於io.dropwizard.client包,在下文中一共展示了JerseyClientBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
@Override
public void run(final BloopServerConfiguration configuration,
final Environment environment) {
final DBIFactory factory = new DBIFactory();
final DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "postgresql");
final FlagDAO flagDAO = jdbi.onDemand(FlagDAO.class);
final NearbyFlagDAO nearbyFlagDAO = jdbi.onDemand(NearbyFlagDAO.class);
final PlayerDAO playerDAO = jdbi.onDemand(PlayerDAO.class);
final Client client = new JerseyClientBuilder(environment).using(configuration.getJerseyClientConfiguration())
.build(getName());
final String firebaseKey = configuration.getFirebaseKey();
environment.jersey().register(new FlagResource(flagDAO, nearbyFlagDAO, playerDAO, client, firebaseKey));
environment.jersey().register(new PlayerResource(playerDAO, flagDAO));
}
示例2: getNewSecureClient
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
protected Client getNewSecureClient(String keyStoreResourcePath) throws Exception {
TlsConfiguration tlsConfiguration = new TlsConfiguration();
tlsConfiguration.setKeyStorePath(new File(resourceFilePath(keyStoreResourcePath)));
tlsConfiguration.setKeyStorePassword("notsecret");
tlsConfiguration.setTrustStorePath(new File(resourceFilePath("tls/test-truststore.jks")));
tlsConfiguration.setTrustStorePassword("notsecret");
tlsConfiguration.setVerifyHostname(false);
tlsConfiguration.setSupportedCiphers(Lists.newArrayList("TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"));
tlsConfiguration.setSupportedProtocols(Lists.newArrayList("TLSv1.2"));
JerseyClientConfiguration configuration = new JerseyClientConfiguration();
configuration.setTlsConfiguration(tlsConfiguration);
configuration.setTimeout(Duration.seconds(30));
configuration.setConnectionTimeout(Duration.seconds(30));
configuration.setConnectionRequestTimeout(Duration.seconds(30));
return new JerseyClientBuilder(USER_INFO_APP_RULE.getEnvironment())
.using(configuration)
.build(UUID.randomUUID().toString());
}
示例3: shouldReturn400WhenPassedNoEntityIdForMultiTenantApplication
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
@Test
public void shouldReturn400WhenPassedNoEntityIdForMultiTenantApplication() throws Exception {
multiTenantApplication.before();
Client client = new JerseyClientBuilder(multiTenantApplication.getEnvironment()).build("Test Client");
setupComplianceToolWithEntityId(client, MULTI_ENTITY_ID_1);
Response authnResponse = client
.target(URI.create(String.format("http://localhost:%d/generate-request", multiTenantApplication.getLocalPort())))
.request()
.buildPost(Entity.json(new RequestGenerationBody(LevelOfAssurance.LEVEL_2, null)))
.invoke();
assertThat(authnResponse.getStatus()).isEqualTo(BAD_REQUEST.getStatusCode());
multiTenantApplication.after();
}
示例4: shouldReturn400WhenPassedInvalidEntityIdForMultiTenantApplication
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
@Test
public void shouldReturn400WhenPassedInvalidEntityIdForMultiTenantApplication() throws Exception {
multiTenantApplication.before();
Client client = new JerseyClientBuilder(multiTenantApplication.getEnvironment()).build("Test Client");
setupComplianceToolWithEntityId(client, MULTI_ENTITY_ID_1);
Response authnResponse = client
.target(URI.create(String.format("http://localhost:%d/generate-request", multiTenantApplication.getLocalPort())))
.request()
.buildPost(Entity.json(new RequestGenerationBody(LevelOfAssurance.LEVEL_2, "not a valid entityID")))
.invoke();
assertThat(authnResponse.getStatus()).isEqualTo(BAD_REQUEST.getStatusCode());
multiTenantApplication.after();
}
示例5: shouldFailHealthcheckWhenMsaMetadataUnavailable
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
@Test
public void shouldFailHealthcheckWhenMsaMetadataUnavailable() {
wireMockServer.stubFor(
get(urlEqualTo("/matching-service/metadata"))
.willReturn(aResponse()
.withStatus(500)
)
);
applicationTestSupport.before();
Client client = new JerseyClientBuilder(applicationTestSupport.getEnvironment()).build("test client");
Response response = client
.target(URI.create(String.format(HEALTHCHECK_URL, applicationTestSupport.getLocalPort())))
.request()
.buildGet()
.invoke();
String expectedResult = "\"msaMetadata\":{\"healthy\":false";
wireMockServer.verify(getRequestedFor(urlEqualTo("/matching-service/metadata")));
assertThat(response.getStatus()).isEqualTo(INTERNAL_SERVER_ERROR.getStatusCode());
assertThat(response.readEntity(String.class)).contains(expectedResult);
}
示例6: shouldPassHealthcheckWhenMsaMetadataAvailable
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
@Test
public void shouldPassHealthcheckWhenMsaMetadataAvailable() {
wireMockServer.stubFor(
get(urlEqualTo("/matching-service/metadata"))
.willReturn(aResponse()
.withStatus(200)
.withBody(MockMsaServer.msaMetadata())
)
);
applicationTestSupport.before();
Client client = new JerseyClientBuilder(applicationTestSupport.getEnvironment()).build("test client");
Response response = client
.target(URI.create(String.format(HEALTHCHECK_URL, applicationTestSupport.getLocalPort())))
.request()
.buildGet()
.invoke();
String expectedResult = "\"msaMetadata\":{\"healthy\":true";
wireMockServer.verify(getRequestedFor(urlEqualTo("/matching-service/metadata")));
assertThat(response.getStatus()).isEqualTo(OK.getStatusCode());
assertThat(response.readEntity(String.class)).contains(expectedResult);
}
示例7: shouldFailHealthcheckWhenHubMetadataUnavailable
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
@Test
public void shouldFailHealthcheckWhenHubMetadataUnavailable() {
wireMockServer.stubFor(
get(urlEqualTo("/SAML2/metadata"))
.willReturn(aResponse()
.withStatus(500)
)
);
applicationTestSupport.before();
Client client = new JerseyClientBuilder(applicationTestSupport.getEnvironment()).build("test client");
Response response = client
.target(URI.create(String.format(HEALTHCHECK_URL, applicationTestSupport.getLocalPort())))
.request()
.buildGet()
.invoke();
String expectedResult = "\"hubMetadata\":{\"healthy\":false";
wireMockServer.verify(getRequestedFor(urlEqualTo("/SAML2/metadata")));
assertThat(response.getStatus()).isEqualTo(INTERNAL_SERVER_ERROR.getStatusCode());
assertThat(response.readEntity(String.class)).contains(expectedResult);
}
示例8: run
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
@Override
public void run(HelloWorldConfiguration configuration,
Environment environment) throws Exception {
final Optional<HttpTracing> tracing = configuration.getZipkinFactory()
.build(environment);
final Client client;
if (tracing.isPresent()) {
client = new ZipkinClientBuilder(environment, tracing.get())
.build(configuration.getZipkinClient());
} else {
final ZipkinClientConfiguration clientConfig = configuration
.getZipkinClient();
client = new JerseyClientBuilder(environment).using(clientConfig)
.build(clientConfig.getServiceName());
}
// Register resources
final HelloWorldResource resource = new HelloWorldResource(client);
environment.jersey().register(resource);
}
示例9: testHandleForward
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
@Test
public void testHandleForward() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test forward client");
client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);
Response response = client.target(
String.format("http://localhost:%d/nominatim?q=berlin", RULE.getLocalPort()))
.request()
.get();
assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getLocale().equals("en"));
}
示例10: testCorrectLocale
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
@Test
public void testCorrectLocale() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("testCorrectLocale");
client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);
Response response = client.target(
String.format("http://localhost:%d/nominatim?q=berlin&locale=de", RULE.getLocalPort()))
.request()
.get();
assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getLocale().equals("de"));
}
示例11: testCorrectLocaleCountry
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
@Test
public void testCorrectLocaleCountry() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("testCorrectLocaleCountry");
client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);
Response response = client.target(
String.format("http://localhost:%d/nominatim?q=berlin&locale=de-ch", RULE.getLocalPort()))
.request()
.get();
assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getLocale().equals("de-CH"));
}
示例12: testIncorrectLocale
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
@Test
public void testIncorrectLocale() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("testIncorrectLocale");
client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);
Response response = client.target(
String.format("http://localhost:%d/nominatim?q=berlin&locale=IAmNotValid", RULE.getLocalPort()))
.request()
.get();
assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getLocale().equals("en"));
}
示例13: testIncorrectLocaleCountry
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
@Test
public void testIncorrectLocaleCountry() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("testIncorrectLocaleCountry");
client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);
Response response = client.target(
String.format("http://localhost:%d/nominatim?q=berlin&locale=de-zz", RULE.getLocalPort()))
.request()
.get();
assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getLocale().equals("en"));
}
示例14: run
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
@Override
public void run(HaraHachiBuConfiguration config, Environment environment) throws Exception {
// Set up the Jersey client - required for HTTP client interactions
final Client client = new JerseyClientBuilder(environment)
.using(config.getJerseyClient())
.build(getName());
// Build the disk space checker instance -
// this may add new resources and healthchecks to the environment.
final DiskSpaceChecker checker = new DiskSpaceCheckerBuilder(environment, client, config.getDiskSpace()).build();
// Set up the disk space filter
environment.servlets()
.addFilter("diskSpaceFilter", new DiskSpaceFilter(checker, config.getProxy(), "/setSpace"))
.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
// Set up the proxy servlet - requires some additional configuration
ServletRegistration.Dynamic diskSpaceProxyServlet = environment.servlets().addServlet("diskSpaceProxyServlet", new DiskSpaceProxyServlet());
diskSpaceProxyServlet.setInitParameter(DiskSpaceProxyServlet.DESTINATION_SERVER_PARAM, config.getProxy().getDestinationServer());
diskSpaceProxyServlet.addMapping(DiskSpaceProxyServlet.PROXY_PATH_PREFIX + "/*");
// Add healthcheck
environment.healthChecks().register("Generic disk space checker", new DiskSpaceCheckerHealthCheck(checker));
}
示例15: BaseClient
import io.dropwizard.client.JerseyClientBuilder; //導入依賴的package包/類
public BaseClient(Environment environment, ClientConfiguration clientConfiguration,
JerseyClientConfiguration jerseyClientConfiguration, String clientName) {
httpClient = new JerseyClientBuilder(environment)
.using(jerseyClientConfiguration)
.build(clientName);
StringBuilder targetBuilder = new StringBuilder();
String target = targetBuilder.append(clientConfiguration.host)
.append(':')
.append(clientConfiguration.port)
.append('/')
.append(clientConfiguration.serviceContext).toString();
webTarget = httpClient.target(target);
}