本文整理匯總了Java中org.apache.cxf.transport.http.HTTPConduit.getClient方法的典型用法代碼示例。如果您正苦於以下問題:Java HTTPConduit.getClient方法的具體用法?Java HTTPConduit.getClient怎麽用?Java HTTPConduit.getClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.cxf.transport.http.HTTPConduit
的用法示例。
在下文中一共展示了HTTPConduit.getClient方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getServiceProxy
import org.apache.cxf.transport.http.HTTPConduit; //導入方法依賴的package包/類
public static JaxWsProxyFactoryBean getServiceProxy(BindingProvider servicePort, String serviceAddr) {
JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
if(serviceAddr != null)
proxyFactory.setAddress(serviceAddr);
proxyFactory.setServiceClass(servicePort.getClass());
proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor());
SoapBindingConfiguration config = new SoapBindingConfiguration();
config.setVersion(Soap12.getInstance());
proxyFactory.setBindingConfig(config);
Client deviceClient = ClientProxy.getClient(servicePort);
HTTPConduit http = (HTTPConduit) deviceClient.getConduit();
// AuthorizationPolicy authPolicy = new AuthorizationPolicy();
// authPolicy.setUserName(username);
// authPolicy.setPassword(password);
// authPolicy.setAuthorizationType("Basic");
// http.setAuthorization(authPolicy);
HTTPClientPolicy httpClientPolicy = http.getClient();
httpClientPolicy.setConnectionTimeout(36000);
httpClientPolicy.setReceiveTimeout(32000);
httpClientPolicy.setAllowChunking(false);
return proxyFactory;
}
示例2: testGZIPServerSideOnlyInterceptorOnClient
import org.apache.cxf.transport.http.HTTPConduit; //導入方法依賴的package包/類
public boolean testGZIPServerSideOnlyInterceptorOnClient() throws Exception
{
Bus bus = BusFactory.newInstance().createBus();
try
{
BusFactory.setThreadDefaultBus(bus);
HelloWorld port = getPort();
Client client = ClientProxy.getClient(port);
HTTPConduit conduit = (HTTPConduit)client.getConduit();
HTTPClientPolicy policy = conduit.getClient();
//enable Accept gzip, otherwise the server will not try to reply using gzip
policy.setAcceptEncoding("gzip;q=1.0, identity; q=0.5, *;q=0");
//add interceptor for decoding gzip message
ClientConfigurer configurer = ClientConfigUtil.resolveClientConfigurer();
configurer.setConfigProperties(port, "jaxws-client-config.xml", "Interceptor Client Config");
return ("foo".equals(port.echo("foo")));
}
finally
{
bus.shutdown(true);
}
}
示例3: testFailureGZIPServerSideOnlyInterceptorOnClient
import org.apache.cxf.transport.http.HTTPConduit; //導入方法依賴的package包/類
public boolean testFailureGZIPServerSideOnlyInterceptorOnClient() throws Exception
{
HelloWorld port = getPort();
Client client = ClientProxy.getClient(port);
HTTPConduit conduit = (HTTPConduit)client.getConduit();
HTTPClientPolicy policy = conduit.getClient();
//enable Accept gzip, otherwise the server will not try to reply using gzip
policy.setAcceptEncoding("gzip;q=1.0, identity; q=0.5, *;q=0");
try
{
port.echo("foo");
return false;
}
catch (Exception e)
{
//expected exception, as the client is not able to decode gzip message
return true;
}
}
示例4: testGZIPServerSideOnlyInterceptorOnClient
import org.apache.cxf.transport.http.HTTPConduit; //導入方法依賴的package包/類
public boolean testGZIPServerSideOnlyInterceptorOnClient() throws Exception
{
Bus bus = BusFactory.newInstance().createBus();
try
{
BusFactory.setThreadDefaultBus(bus);
HelloWorld port = getPort();
Client client = ClientProxy.getClient(port);
HTTPConduit conduit = (HTTPConduit)client.getConduit();
HTTPClientPolicy policy = conduit.getClient();
//enable Accept gzip, otherwise the server will not try to reply using gzip
policy.setAcceptEncoding("gzip;q=1.0, identity; q=0.5, *;q=0");
//add interceptor for decoding gzip message
client.getInInterceptors().add(new GZIPEnforcingInInterceptor());
return ("foo".equals(port.echo("foo")));
}
finally
{
bus.shutdown(true);
}
}
示例5: build
import org.apache.cxf.transport.http.HTTPConduit; //導入方法依賴的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;
}
示例6: creatClient
import org.apache.cxf.transport.http.HTTPConduit; //導入方法依賴的package包/類
public AccountSoapService creatClient() {
String address = baseUrl + "/cxf/soap/accountservice";
JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
proxyFactory.setAddress(address);
proxyFactory.setServiceClass(AccountSoapService.class);
AccountSoapService accountWebServiceProxy = (AccountSoapService) proxyFactory.create();
//(可選)演示重新設定endpoint address.
((BindingProvider) accountWebServiceProxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
address);
//(可選)演示重新設定Timeout時間
Client client = ClientProxy.getClient(accountWebServiceProxy);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy policy = conduit.getClient();
policy.setReceiveTimeout(600000);
return accountWebServiceProxy;
}
示例7: instrumentService
import org.apache.cxf.transport.http.HTTPConduit; //導入方法依賴的package包/類
/**
* Instrument the service port object with authentication information and the appropriate handlers
*
* @param serviceApi
* The service port Object
* @param callbackHandler
* Callback which allows retrieval of authentication information
* @param timeout
* Optional HTTP timeout in milliseconds, if {@link #INDEFINITE_TIMEOUT}, there is no timeout
*/
protected void instrumentService(Object serviceApi, CallbackHandler callbackHandler, long timeout) throws ServerConnectException {
logger.debug("Instrument service: {}", serviceApi.toString());
try {
initAuthProps(callbackHandler);
org.apache.cxf.endpoint.Client client = org.apache.cxf.frontend.ClientProxy.getClient(serviceApi);
client = applyRequestHeaders(client);
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
configureCxfEndpoint(cxfEndpoint);
// Set timeout
setTimeout(serviceApi, timeout);
if (client.getConduit() instanceof HTTPConduit) {
HTTPConduit http = (HTTPConduit) client.getConduit();
http = applyCertificates(http);
HTTPClientPolicy httpClientPolicy = http.getClient();
httpClientPolicy = applyRequestCookies(httpClientPolicy);
httpClientPolicy.setAutoRedirect(true);
}
} catch (Exception e) {
throw new ServerConnectException("Connection to server \"" + serverUrl + "\" failed: " + e.getMessage(), e);
}
}
示例8: getTimeout
import org.apache.cxf.transport.http.HTTPConduit; //導入方法依賴的package包/類
/**
* Get the current HTTP timeout value for a service port
*
* @param serviceApi
* The object representing the service API port
* @return The timeout in milliseconds for the provided API port
*/
protected long getTimeout(Object serviceApi) {
org.apache.cxf.endpoint.Client client = org.apache.cxf.frontend.ClientProxy.getClient(serviceApi);
/* get timeout */
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = http.getClient();
return httpClientPolicy.getConnectionTimeout();
}
示例9: testWrapperWithMap
import org.apache.cxf.transport.http.HTTPConduit; //導入方法依賴的package包/類
@Test
@RunAsClient
public void testWrapperWithMap() throws Exception {
Bus bus = BusFactory.newInstance().createBus();
BusFactory.setThreadDefaultBus(bus);
try {
Map<String, Object> map = new HashMap<String, Object>();
map.put(Constants.CXF_CLIENT_ALLOW_CHUNKING, true);
map.put(Constants.CXF_CLIENT_CHUNKING_THRESHOLD, 8192);
map.put(Constants.CXF_CLIENT_CONNECTION_TIMEOUT, 16384L);
map.put(Constants.CXF_CLIENT_RECEIVE_TIMEOUT, 163840L);
map.put(Constants.CXF_TLS_CLIENT_DISABLE_CN_CHECK, true);
replaceWrapper(map, bus);
URL wsdlURL = new URL(baseURL + "/ServiceOne" + "?wsdl");
Service service = Service.create(wsdlURL, new QName("http://org.jboss.ws.jaxws.cxf/httpConduit", "ServiceOne"));
EndpointOne port = service.getPort(new QName("http://org.jboss.ws.jaxws.cxf/httpConduit", "EndpointOnePort"), EndpointOne.class);
HTTPConduit conduit = (HTTPConduit)ClientProxy.getClient(port).getConduit();
HTTPClientPolicy client = conduit.getClient();
assertNotNull(client);
assertEquals(true, client.isAllowChunking());
assertEquals(8192, client.getChunkingThreshold());
assertEquals(16384, client.getConnectionTimeout());
assertEquals(163840, client.getReceiveTimeout());
assertEquals(true, conduit.getTlsClientParameters().isDisableCNCheck());
assertEquals("Foo", port.echo("Foo"));
} finally {
bus.shutdown(true);
}
}
示例10: testDecoupledEndpointForLongLastingProcessingOfInvocations
import org.apache.cxf.transport.http.HTTPConduit; //導入方法依賴的package包/類
/**
* This shows the usage of decoupled-endpoint for getting back response on a new http connection.
* The CXF client basically creates a destination listening at the provided decoupled endpoint address, using the
* configured http transport factory. The client gets back a HTTP 202 accept response message immediately after
* the call to the server, then once the actual response comes back to the decoupled endpoint, the client is
* notified and returns control to the application code.
*
* @throws Exception
*/
@Test
@RunAsClient
public void testDecoupledEndpointForLongLastingProcessingOfInvocations() throws Exception
{
final Bus bus = BusFactory.newInstance().createBus();
BusFactory.setThreadDefaultBus(bus);
try {
// construct proxy
QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wsaddressing", "AddressingService");
URL wsdlURL = new URL(baseURL + "/jaxws-samples-wsa/AddressingService?wsdl");
Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
ServiceIface proxy = (ServiceIface)service.getPort(ServiceIface.class);
Client client = ClientProxy.getClient(proxy);
HTTPConduit conduit = (HTTPConduit)client.getConduit();
HTTPClientPolicy policy = conduit.getClient();
//set low connection and receive timeouts to ensure the http client can't keep the connection open till the response is received
policy.setConnectionTimeout(5000); //5 secs
policy.setReceiveTimeout(10000); //10 secs
//please note you might want to set the synchronous timeout for long waits, as CXF ClientImpl would simply drop waiting for the response after that (default 60 secs)
// ((ClientImpl)client).setSynchronousTimeout(value);
try {
proxy.sayHello("Sleepy"); //this takes at least 30 secs
fail("Timeout exception expected");
} catch (WebServiceException e) {
assertTrue(e.getCause() instanceof SocketTimeoutException);
}
policy.setDecoupledEndpoint("http://" + getServerHost() + ":18181/jaxws-samples-wsa/decoupled-endpoint");
String response = proxy.sayHello("Sleepy"); //this takes at least 30 secs... but now the client doesn't time out
assertEquals("Hello Sleepy!", response);
} finally {
bus.shutdown(true);
}
}
示例11: createService
import org.apache.cxf.transport.http.HTTPConduit; //導入方法依賴的package包/類
private <T> T createService(final Class<T> clazz,
final QName service,
final QName portName,
final String address,
final String userName,
final String password,
final String connectionTimeout,
final String readTimeout) {
Preconditions.checkNotNull(service, "service");
Preconditions.checkNotNull(portName, "portName");
Preconditions.checkNotNull(address, "address");
Preconditions.checkNotNull(userName, "username");
Preconditions.checkNotNull(password, "password");
// Delegate logging to slf4j (see also https://github.com/killbill/killbill-platform/tree/master/osgi-bundles/libs/slf4j-osgi)
LogUtils.setLoggerClass(Slf4jLogger.class);
final Service result = Service.create(null, service);
result.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);
final T port = result.getPort(portName, clazz);
final Client client = ClientProxy.getClient(port);
client.getEndpoint().put("jaxb-validation-event-handler", new IgnoreUnexpectedElementsEventHandler());
final HTTPConduit conduit = (HTTPConduit) client.getConduit();
final HTTPClientPolicy clientPolicy = conduit.getClient();
clientPolicy.setAllowChunking(config.getAllowChunking());
if (config.getTrustAllCertificates()) {
final TLSClientParameters tcp = new TLSClientParameters();
tcp.setTrustManagers(new TrustManager[]{new TrustAllX509TrustManager()});
conduit.setTlsClientParameters(tcp);
}
if (connectionTimeout != null) {
clientPolicy.setConnectionTimeout(Long.valueOf(connectionTimeout));
}
if (readTimeout != null) {
clientPolicy.setReceiveTimeout(Long.valueOf(readTimeout));
}
if (config.getProxyServer() != null) {
clientPolicy.setProxyServer(config.getProxyServer());
}
if (config.getProxyPort() != null) {
clientPolicy.setProxyServerPort(config.getProxyPort());
}
if (config.getProxyType() != null) {
clientPolicy.setProxyServerType(ProxyServerType.fromValue(config.getProxyType().toUpperCase()));
}
((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
final Endpoint endpoint = client.getEndpoint();
endpoint.getInInterceptors().add(loggingInInterceptor);
endpoint.getOutInterceptors().add(loggingOutInterceptor);
endpoint.getOutInterceptors().add(httpHeaderInterceptor);
return port;
}
示例12: getClient
import org.apache.cxf.transport.http.HTTPConduit; //導入方法依賴的package包/類
/**
* JAX-WS client factory
* @param clientBuilder ClientBuilder.
* @param <T> Service interface type.
* @return JAX-WS client proxy.
*/
public <T> T getClient(ClientBuilder<T> clientBuilder) {
JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
proxyFactory.setServiceClass(clientBuilder.getServiceClass());
proxyFactory.setAddress(clientBuilder.getAddress());
// JAX-WS handlers
if (clientBuilder.getHandlers() != null) {
for (Handler h : clientBuilder.getHandlers()) {
proxyFactory.getHandlers().add(h);
}
}
// CXF interceptors
if (clientBuilder.getCxfInInterceptors() != null) {
proxyFactory.getInInterceptors().addAll(clientBuilder.getCxfInInterceptors());
}
if (clientBuilder.getCxfInFaultInterceptors() != null) {
proxyFactory.getInFaultInterceptors().addAll(clientBuilder.getCxfInFaultInterceptors());
}
if (clientBuilder.getCxfOutInterceptors() != null) {
proxyFactory.getOutInterceptors().addAll(clientBuilder.getCxfOutInterceptors());
}
if (clientBuilder.getCxfOutFaultInterceptors() != null) {
proxyFactory.getOutFaultInterceptors().addAll(clientBuilder.getCxfOutFaultInterceptors());
}
T proxy = clientBuilder.getServiceClass().cast(proxyFactory.create());
// MTOM support
if (clientBuilder.isMtomEnabled()) {
BindingProvider bp = (BindingProvider)proxy;
SOAPBinding binding = (SOAPBinding)bp.getBinding();
binding.setMTOMEnabled(true);
}
HTTPConduit http = (HTTPConduit)ClientProxy.getClient(proxy).getConduit();
HTTPClientPolicy client = http.getClient();
client.setConnectionTimeout(clientBuilder.getConnectTimeout());
client.setReceiveTimeout(clientBuilder.getReceiveTimeout());
return proxy;
}