本文整理汇总了Java中org.apache.cxf.jaxrs.client.ClientConfiguration类的典型用法代码示例。如果您正苦于以下问题:Java ClientConfiguration类的具体用法?Java ClientConfiguration怎么用?Java ClientConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClientConfiguration类属于org.apache.cxf.jaxrs.client包,在下文中一共展示了ClientConfiguration类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setClientAuthentication
import org.apache.cxf.jaxrs.client.ClientConfiguration; //导入依赖的package包/类
private static void setClientAuthentication(Object client, String userName, String password) {
// Properties p = new Properties(); //PropertiesLoader.getPropertiesFromFile("config.properties");
ClientConfiguration config = WebClient.getConfig(client);
HTTPConduit httpConduit = (HTTPConduit) config.getConduit();
AuthorizationPolicy authorization = new AuthorizationPolicy();
authorization.setUserName(userName);
authorization.setPassword(password);
httpConduit.setAuthorization(authorization);
TLSClientParameters tlsParams = new TLSClientParameters();
TrustManager[] trustAllCerts = new TrustManager[] { new TrustManager() };
tlsParams.setTrustManagers(trustAllCerts);
// disables verification of the common name (the host for which the certificate has been issued)
tlsParams.setDisableCNCheck(true);
httpConduit.setTlsClientParameters(tlsParams);
}
示例2: build
import org.apache.cxf.jaxrs.client.ClientConfiguration; //导入依赖的package包/类
/**
* Build a client proxy, for a specific proxy type.
*
* @param proxyType proxy type class
* @return client proxy stub
*/
protected <T> T build(Class<T> proxyType) {
String address = generateAddress();
T rootResource;
// Synchronized on the class to correlate with the scope of clientStaticResources
// We want to ensure that the shared bean isn't set concurrently in multiple callers
synchronized (AmbariClientBuilder.class) {
JAXRSClientFactoryBean bean = cleanFactory(clientStaticResources.getUnchecked(proxyType));
bean.setAddress(address);
if (username != null) {
bean.setUsername(username);
bean.setPassword(password);
}
if (enableLogging) {
bean.setFeatures(Arrays.<AbstractFeature> asList(new LoggingFeature()));
}
rootResource = bean.create(proxyType);
}
boolean isTlsEnabled = address.startsWith("https://");
ClientConfiguration config = WebClient.getConfig(rootResource);
HTTPConduit conduit = (HTTPConduit) config.getConduit();
if (isTlsEnabled) {
TLSClientParameters tlsParams = new TLSClientParameters();
if (!validateCerts) {
tlsParams.setTrustManagers(new TrustManager[] { new AcceptAllTrustManager() });
} else if (trustManagers != null) {
tlsParams.setTrustManagers(trustManagers);
}
tlsParams.setDisableCNCheck(!validateCn);
conduit.setTlsClientParameters(tlsParams);
}
HTTPClientPolicy policy = conduit.getClient();
policy.setConnectionTimeout(connectionTimeoutUnits.toMillis(connectionTimeout));
policy.setReceiveTimeout(receiveTimeoutUnits.toMillis(receiveTimeout));
return rootResource;
}
示例3: getService
import org.apache.cxf.jaxrs.client.ClientConfiguration; //导入依赖的package包/类
/**
* Creates an instance of the given service class, with configured content type and authentication.
*
* @param <T> any service class
* @param serviceClass service class reference
* @return service instance of the given reference class
*/
public <T> T getService(final Class<T> serviceClass) {
synchronized (restClientFactory) {
restClientFactory.setServiceClass(serviceClass);
T serviceInstance = restClientFactory.create(serviceClass);
Client client = WebClient.client(serviceInstance);
client.type(mediaType).accept(mediaType);
ClientConfiguration config = WebClient.getConfig(client);
config.getRequestContext().put(HEADER_SPLIT_PROPERTY, true);
config.getRequestContext().put(URLConnectionHTTPConduit.HTTPURL_CONNECTION_METHOD_REFLECTION, true);
if (useCompression) {
config.getInInterceptors().add(new GZIPInInterceptor());
config.getOutInterceptors().add(new GZIPOutInterceptor());
}
return serviceInstance;
}
}
示例4: setup
import org.apache.cxf.jaxrs.client.ClientConfiguration; //导入依赖的package包/类
@Before
public void setup() {
JacksonJsonProvider provider = new JacksonJsonProvider();
List providers = new ArrayList();
providers.add(provider);
api = JAXRSClientFactory.create("http://localhost", RemoteAccessApi.class, providers);
org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
ClientConfiguration config = WebClient.getConfig(client);
}
示例5: setup
import org.apache.cxf.jaxrs.client.ClientConfiguration; //导入依赖的package包/类
@Before
public void setup() {
JacksonJsonProvider provider = new JacksonJsonProvider();
List providers = new ArrayList();
providers.add(provider);
api = JAXRSClientFactory.create("http://localhost", BlueOceanApi.class, providers);
org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
ClientConfiguration config = WebClient.getConfig(client);
}
示例6: closeClient
import org.apache.cxf.jaxrs.client.ClientConfiguration; //导入依赖的package包/类
/**
* Closes the transport level conduit in the client. Reopening a new connection, requires creating a new client
* object using the build() method in this builder.
*
* @param root The resource returned by the build() method of this builder class
*/
public static void closeClient(ApiRootResource root) {
ClientConfiguration config = WebClient.getConfig(root);
HTTPConduit conduit = config.getHttpConduit();
if (conduit == null) {
throw new IllegalArgumentException("Client is not using the HTTP transport");
}
conduit.close();
}
示例7: getQuestionnaireResource
import org.apache.cxf.jaxrs.client.ClientConfiguration; //导入依赖的package包/类
private QuestionnaireResource getQuestionnaireResource() {
QuestionnaireResource questionnaireResource = JAXRSClientFactory.create(BASE_URI, QuestionnaireResource.class,
Collections.singletonList(getJacksonProvider()), null);
Client client = WebClient.client(questionnaireResource);
ClientConfiguration config = WebClient.getConfig(client);
String apiKey = "FGFQM8T6YPVSW4Q";
String secret = "39JYOYPWYR46R38OAOTVRZJMEXNJ46HL";
config.getOutInterceptors().add(new HmacAuthInterceptor(apiKey, secret));
return questionnaireResource;
}
示例8: createQuestionnairResource
import org.apache.cxf.jaxrs.client.ClientConfiguration; //导入依赖的package包/类
@Produces
@GazpachoResource
@RequestScoped
public QuestionnaireResource createQuestionnairResource(HttpServletRequest request) {
RespondentAccount principal = (RespondentAccount) request.getUserPrincipal();
String apiKey = principal.getApiKey();
String secret = principal.getSecret();
logger.info("Getting QuestionnaireResource using api key {}/{} ", apiKey, secret);
JacksonJsonProvider jacksonProvider = new JacksonJsonProvider();
ObjectMapper mapper = new ObjectMapper();
// mapper.findAndRegisterModules();
mapper.registerModule(new JSR310Module());
mapper.setSerializationInclusion(Include.NON_EMPTY);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
jacksonProvider.setMapper(mapper);
QuestionnaireResource resource = JAXRSClientFactory.create(BASE_URI, QuestionnaireResource.class,
Collections.singletonList(jacksonProvider), null);
// proxies
// WebClient.client(resource).header("Authorization", "GZQ " + apiKey);
Client client = WebClient.client(resource);
ClientConfiguration config = WebClient.getConfig(client);
config.getOutInterceptors().add(new HmacAuthInterceptor(apiKey, secret));
return resource;
}
示例9: prepareClient
import org.apache.cxf.jaxrs.client.ClientConfiguration; //导入依赖的package包/类
protected WebClient prepareClient(String username, String password) {
List providers = new ArrayList<>();
providers.add(getProvider());
WebClient client = WebClient.create(ENDPOINT_ADDRESS, providers);// ,
// provider);
ClientConfiguration clientConfig = WebClient.getConfig(client);
clientConfig.getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
client.accept(getAcceptHeader());
client.type(getContentType());
createAuthorizationHeader(client, username, password);
return client;
}
示例10: initialize
import org.apache.cxf.jaxrs.client.ClientConfiguration; //导入依赖的package包/类
@Override
public void initialize(InterceptorProvider interceptorProv, Bus bus) {
if (interceptorProv instanceof ClientConfiguration) {
initialize(interceptorProv, this.restClientHookInInterceptor, this.restClientProcessInInterceptor, this.restClientOutInterceptor);
}
}