本文整理了Java中javax.ws.rs.client.ClientBuilder.newBuilder()
方法的一些代码示例,展示了ClientBuilder.newBuilder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClientBuilder.newBuilder()
方法的具体详情如下:
包路径:javax.ws.rs.client.ClientBuilder
类名称:ClientBuilder
方法名:newBuilder
[英]Create a new ClientBuilder instance using the default client builder implementation class provided by the JAX-RS implementation provider.
[中]使用JAX-RS实现提供程序提供的默认客户端生成器实现类创建新的ClientBuilder实例。
代码示例来源:origin: confluentinc/ksql
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();
}
}
代码示例来源:origin: Pay-Group/best-pay-sdk
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);
}
}
代码示例来源:origin: spotify/apollo
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());
}
}
代码示例来源:origin: jersey/jersey
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);
}
}
代码示例来源:origin: apache/nifi
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());
}
代码示例来源:origin: oracle/helidon
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
代码示例来源:origin: confluentinc/ksql
@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();
}
代码示例来源:origin: jersey/jersey
final Client client = ClientBuilder.newBuilder()
.register(filterFeature)
.register(JacksonFeature.class)
代码示例来源:origin: spotify/docker-client
this.client = ClientBuilder.newBuilder()
.withConfig(config)
.build();
.setSocketTimeout((int) NO_TIMEOUT)
.build();
this.noTimeoutClient = ClientBuilder.newBuilder()
.withConfig(config)
.property(ApacheClientProperties.CONNECTION_MANAGER, noTimeoutCm)
代码示例来源:origin: apache/nifi
final HostnameVerifier hostnameVerifier = clientConfig.getHostnameVerifier();
final ClientBuilder clientBuilder = ClientBuilder.newBuilder();
if (sslContext != null) {
clientBuilder.sslContext(sslContext);
代码示例来源:origin: aol/micro-server
protected Client initClient(int rt, int ct) {
ClientConfig clientConfig = new ClientConfig();
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, ct);
clientConfig.property(ClientProperties.READ_TIMEOUT, rt);
ClientBuilder.newBuilder().register(JacksonFeature.class);
Client client = ClientBuilder.newClient(clientConfig);
client.register(JacksonFeature.class);
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
provider.setMapper(JacksonUtil.getMapper());
client.register(provider);
return client;
}
代码示例来源:origin: aol/micro-server
protected Client initClient(int rt, int ct) {
ClientConfig clientConfig = new ClientConfig();
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, ct);
clientConfig.property(ClientProperties.READ_TIMEOUT, rt);
ClientBuilder.newBuilder().register(JacksonFeature.class);
Client client = ClientBuilder.newClient(clientConfig);
client.register(JacksonFeature.class);
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
provider.setMapper(JacksonUtil.getMapper());
client.register(provider);
return client;
}
代码示例来源:origin: jersey/jersey
.keyPassword("asdfgh");
final Client client = ClientBuilder.newBuilder().sslContext(sslConfig.createSSLContext()).build();
client.property(ClientProperties.CONNECT_TIMEOUT, 2000)
.register(new MoxyJsonFeature())
代码示例来源:origin: signalapp/Signal-Server
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();
}
代码示例来源:origin: docker-java/docker-java
ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig);
代码示例来源:origin: apache/nifi
/**
* 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();
}
代码示例来源:origin: jersey/jersey
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());
}
}
代码示例来源:origin: immutables/immutables
@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();
}
代码示例来源:origin: Netflix/eureka
@Override
public Jersey2ApplicationClientFactory build() {
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
ClientConfig clientConfig = new ClientConfig();
代码示例来源:origin: jamesagnew/hapi-fhir
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;
}
内容来源于网络,如有侵权,请联系作者删除!