private static Client buildClient() { final ObjectMapper objectMapper = JsonMapper.INSTANCE.mapper; objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false); objectMapper.registerModule(new Jdk8Module()); final JacksonMessageBodyProvider jsonProvider = new JacksonMessageBodyProvider(objectMapper); return ClientBuilder.newBuilder().register(jsonProvider).build(); } }
public HttpsClient(String host, String project) { SslConfigurator sslConfig = SslConfigurator.newInstance(); SSLContext ssl = sslConfig.createSSLContext(); this.target = ClientBuilder.newBuilder().sslContext(ssl).build().target(UriBuilder.fromUri("https://" + host).build()); if (project != null) { this.target = this.target.path(project); } }
public SlackImpl(SlackConfig slackConfig) { this.client = ClientBuilder.newBuilder().build(); this.target = client.target(slackConfig.webhook()); this.mapper = new ObjectMapper(); this.slackConfig = slackConfig; if (!Strings.isNullOrEmpty(slackConfig.startupMsg())) { post(slackConfig.startupMsg()); } }
public static void main(String[] args) { try { System.out.println("\"Hello World\" Jersey OpenTracing Example App"); prepare(); final ResourceConfig resourceConfig = new ResourceConfig(TracedResource.class, OpenTracingFeature.class, ReqFilterA.class, ReqFilterB.class, RespFilterA.class, RespFilterB.class); final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig, false); Runtime.getRuntime().addShutdownHook(new Thread(server::shutdownNow)); server.start(); System.out.println(String.format("Application started.\nTry out %s/application.wadl\n" + "Stop the application using CTRL+C", BASE_URI)); // do the first "example" request with tracing-enabled client to show something in Jaegger UI, // include some weird headers and accepted types, that will be visible in the span's tags Client client = ClientBuilder.newBuilder().register(OpenTracingFeature.class).build(); client.target(BASE_URI).path("resource/managedClient").request() .accept("text/plain", "application/json", "*/*") .header("foo", "bar") .header("foo", "baz") .header("Hello", "World").get(); Thread.currentThread().join(); } catch (IOException | InterruptedException ex) { Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex); } }
public void get(final GetStatusConfig config) { final SSLContext sslContext = config.getSslContext(); final ClientBuilder clientBuilder = ClientBuilder.newBuilder(); if (sslContext != null) { clientBuilder.sslContext(sslContext); } final ClientConfig clientConfig = new ClientConfig(); clientConfig.property(ClientProperties.CONNECT_TIMEOUT, 10000); clientConfig.property(ClientProperties.READ_TIMEOUT, 10000); clientBuilder.withConfig(clientConfig); final Client client = clientBuilder.build(); final WebTarget target = client.target(config.getUrl()); final Response response = target.request().get(); System.out.println("Response Code - " + response.getStatus()); }
@SuppressWarnings("unused") // Part of public API public static Client buildClient() { final ObjectMapper objectMapper = JsonMapper.INSTANCE.mapper; objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true); objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true); objectMapper.registerModule(new Jdk8Module()); final JacksonMessageBodyProvider jsonProvider = new JacksonMessageBodyProvider(objectMapper); return ClientBuilder.newBuilder().register(jsonProvider).build(); }
.register(filterFeature) .register(JacksonFeature.class) .build();
jerseyClientConfig.register(jacksonJaxbJsonProvider()); clientBuilder.withConfig(jerseyClientConfig); this.client = clientBuilder.build();
.keyPassword("asdfgh"); final Client client = ClientBuilder.newBuilder().sslContext(sslConfig.createSSLContext()).build(); client.property(ClientProperties.CONNECT_TIMEOUT, 2000) .register(new MoxyJsonFeature())
private static Client initializeClient(DirectoryServerConfiguration directoryServerConfiguration) throws CertificateException { KeyStore trustStore = initializeKeyStore(directoryServerConfiguration.getReplicationCaCertificate()); SSLContext sslContext = SslConfigurator.newInstance() .securityProtocol("TLSv1.2") .trustStore(trustStore) .createSSLContext(); return ClientBuilder.newBuilder() .register(HttpAuthenticationFeature.basic("signal", directoryServerConfiguration.getReplicationPassword().getBytes())) .sslContext(sslContext) .build(); }
client = clientBuilder.build();
/** * A helper method for creating clients. The client will be created using * the given configuration and security context. Additionally, the client * will be automatically configured for JSON serialization/deserialization. * * @param config client configuration * @param ctx security context, which may be null for non-secure client * creation * @return a Client instance */ private static Client createClientHelper(final ClientConfig config, final SSLContext ctx) { ClientBuilder clientBuilder = ClientBuilder.newBuilder(); if (config != null) { clientBuilder = clientBuilder.withConfig(config); } if (ctx != null) { // Apache http DefaultHostnameVerifier that checks subject alternative names against the hostname of the URI clientBuilder = clientBuilder.sslContext(ctx).hostnameVerifier(new DefaultHostnameVerifier()); } clientBuilder = clientBuilder.register(ObjectMapperResolver.class).register(JacksonJaxbJsonProvider.class); return clientBuilder.build(); }
private OAuth1AuthorizationFlowImpl(final OAuth1Parameters params, final OAuth1Secrets secrets, final String requestTokenUri, final String accessTokenUri, final String authorizationUri, final String callbackUri, final Client client, final boolean enableLogging) { this.parameters = params; this.secrets = secrets; this.requestTokenUri = requestTokenUri; this.accessTokenUri = accessTokenUri; this.authorizationUri = authorizationUri; if (client != null) { this.client = client; } else { this.client = ClientBuilder.newBuilder().build(); } final Configuration config = this.client.getConfiguration(); if (enableLogging && !config.isRegistered(LoggingFeature.class)) { this.client.register(new LoggingFeature(LOGGER, LoggingFeature.Verbosity.PAYLOAD_ANY)); } if (!config.isRegistered(OAuth1ClientFeature.class)) { this.client.register(new OAuth1ClientFeature(params, secrets)); } if (callbackUri != null) { this.parameters.callback(callbackUri); } if (secrets.getConsumerSecret() == null || parameters.getConsumerKey() == null) { throw new IllegalStateException(LocalizationMessages.ERROR_CONFIGURATION_MISSING_CONSUMER()); } }
@BeforeClass public static void setup() throws IOException { httpServer = GrizzlyHttpServerFactory.createHttpServer( SERVER_URI, createResourceConfig(), false); httpServer.start(); client = ClientBuilder.newBuilder() .register(GsonMessageBodyProvider.class) .register(PURE_GSON_TEXT_PLAIN) .build(); }
clientBuilder.register(new Jersey2EurekaIdentityHeaderFilter(identity)); JerseyClient jersey2Client = (JerseyClient) clientBuilder.build();
public synchronized Client getNativeClientClient() { if (myNativeClient == null) { ClientBuilder builder = ClientBuilder.newBuilder(); myNativeClient = builder.build(); } if (registeredComponents != null && !registeredComponents.isEmpty()) { for (Class<?> c : registeredComponents) { myNativeClient = myNativeClient.register(c); } } return myNativeClient; }
@BeforeClass public static void startRestClient() { // create the client client = ClientBuilder.newBuilder() .register(MultiPartFeature.class) .register(RestJsonProvider.class) .register(JacksonFeature.class) .build(); target = client.target("http://127.0.0.1:" + testRestPort + "/fscrawler"); }
@Test public void testGetBookSslContext() throws Exception { ClientBuilder builder = ClientBuilder.newBuilder(); SSLContext sslContext = createSSLContext(); builder.sslContext(sslContext); builder.hostnameVerifier(new AllowAllHostnameVerifier()); Client client = builder.build(); WebTarget target = client.target("https://localhost:" + PORT + "/bookstore/securebooks/123"); Book b = target.request().accept(MediaType.APPLICATION_XML_TYPE).get(Book.class); assertEquals(123, b.getId()); }