Java Code Examples for org.apache.cxf.transports.http.configuration.HTTPClientPolicy#setReceiveTimeout()

The following examples show how to use org.apache.cxf.transports.http.configuration.HTTPClientPolicy#setReceiveTimeout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PerUserPerServiceClientFactory.java    From yes-cart with Apache License 2.0 6 votes vote down vote up
private void configureClient(final String userName,
                             final String passw,
                             final long timeout,
                             final Client client) {

    final HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(timeout);
    httpClientPolicy.setAllowChunking(false);
    httpClientPolicy.setReceiveTimeout(timeout);

    ((HTTPConduit) client.getConduit()).setClient(httpClientPolicy);

    final Endpoint endpoint = client.getEndpoint();

    final WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(new HashMap<String, Object>() {{
        put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
        put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
        put(WSHandlerConstants.USER, userName);
        put(WSHandlerConstants.PW_CALLBACK_REF, new PWCallbackHandler(passw));
    }});
    endpoint.getOutInterceptors().add(wssOut);
}
 
Example 2
Source File: RestDocumentClient.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
public RestDocumentClient(String endpoint, String username, String password, int timeout) {
	super(endpoint, username, password, timeout);

	JacksonJsonProvider provider = new JacksonJsonProvider();

	if ((username == null) || (password == null)) {
		proxy = JAXRSClientFactory.create(endpoint, DocumentService.class, Arrays.asList(provider));
	} else {
		proxy = JAXRSClientFactory.create(endpoint, DocumentService.class, Arrays.asList(provider), username,
				password, null);
	}

	if (timeout > 0) {
		HTTPConduit conduit = WebClient.getConfig(proxy).getHttpConduit();
		HTTPClientPolicy policy = new HTTPClientPolicy();
		policy.setReceiveTimeout(timeout);
		conduit.setClient(policy);
	}
}
 
Example 3
Source File: RestFolderClient.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
public RestFolderClient(String endpoint, String username, String password, int timeout) {
	super(endpoint, username, password, timeout);

	JacksonJsonProvider provider = new JacksonJsonProvider();

	if ((username == null) || (password == null)) {
		proxy = JAXRSClientFactory.create(endpoint, FolderService.class, Arrays.asList(provider));
	} else {
		// proxy = JAXRSClientFactory.create(endpoint, FolderService.class,
		// Arrays.asList(provider));
		// create(String baseAddress, Class<T> cls, List<?> providers,
		// String username, String password, String configLocation)
		proxy = JAXRSClientFactory.create(endpoint, FolderService.class, Arrays.asList(provider), username,
				password, null);
	}

	if (timeout > 0) {
		HTTPConduit conduit = WebClient.getConfig(proxy).getHttpConduit();
		HTTPClientPolicy policy = new HTTPClientPolicy();
		policy.setReceiveTimeout(timeout);
		conduit.setClient(policy);
	}
}
 
Example 4
Source File: RestSearchClient.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Constructor
 * 
 * @param endpoint  Connection URL
 * @param username the username
 * @param password the password
 * @param timeout Timeout for the RESTful requests
 */
public RestSearchClient(String endpoint, String username, String password, int timeout) {
	super(endpoint, username, password, timeout);

	JacksonJsonProvider provider = new JacksonJsonProvider();
	
	if ((username == null) || (password == null)) {
		proxy = JAXRSClientFactory.create(endpoint, SearchService.class, Arrays.asList(provider));
	} else {
		proxy = JAXRSClientFactory.create(endpoint, SearchService.class, Arrays.asList(provider), username, password, null);
	}
	
	if (timeout > 0) {
		HTTPConduit conduit = WebClient.getConfig(proxy).getHttpConduit();
		HTTPClientPolicy policy = new HTTPClientPolicy();
		policy.setReceiveTimeout(timeout);
		conduit.setClient(policy);
	}
}
 
Example 5
Source File: JaxRsClientStarter.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
public T start(Class<T> cls, String url, boolean trustAllCerts, String trustStore, String trustStorePassword, 
	List<?> providers, int connectTimeout, int receiveTimeout) {

	try {
		
		T resource = JAXRSClientFactory.create(url, cls, providers);
	    HTTPConduit conduit = WebClient.getConfig(resource).getHttpConduit();
	    WebClient.getConfig(resource).getInInterceptors().add(new LoggingInInterceptor());
	    WebClient.getConfig(resource).getOutInterceptors().add(new LoggingOutInterceptor());
		configureHTTPS(resource, conduit, trustAllCerts, trustStore, trustStorePassword);
		
	    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); 
	    httpClientPolicy.setConnectionTimeout(connectTimeout); 
	    httpClientPolicy.setReceiveTimeout(receiveTimeout); 
	    conduit.setClient(httpClientPolicy);
		
		return resource;
		
	} catch (Exception e) {
		LOG.error(" rest client '{}': NOT STARTED", url);
		return null;
	}
	
}
 
Example 6
Source File: RestUtil.java    From peer-os with Apache License 2.0 6 votes vote down vote up
public static WebClient createTrustedWebClient( String url, Object provider )
{
    WebClient client = WebClient.create( url, Arrays.asList( provider ) );

    HTTPConduit httpConduit = ( HTTPConduit ) WebClient.getConfig( client ).getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout( defaultConnectionTimeout );
    httpClientPolicy.setReceiveTimeout( defaultReceiveTimeout );
    httpClientPolicy.setMaxRetransmits( defaultMaxRetransmits );


    httpConduit.setClient( httpClientPolicy );

    SSLManager sslManager = new SSLManager( null, null, null, null );

    TLSClientParameters tlsClientParameters = new TLSClientParameters();
    tlsClientParameters.setDisableCNCheck( true );
    tlsClientParameters.setTrustManagers( sslManager.getClientFullTrustManagers() );
    httpConduit.setTlsClientParameters( tlsClientParameters );

    return client;
}
 
Example 7
Source File: BraveTracingTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatNewSpanIsCreatedOnClientTimeout() {
    final WebClient client = WebClient
        .create("http://localhost:" + PORT + "/bookstore/books/long", Collections.emptyList(),
            Arrays.asList(new BraveClientFeature(brave)), null)
        .accept(MediaType.APPLICATION_JSON);

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(100);
    httpClientPolicy.setReceiveTimeout(100);
    WebClient.getConfig(client).getHttpConduit().setClient(httpClientPolicy);

    expectedException.expect(ProcessingException.class);
    try {
        client.get();
    } finally {
        await().atMost(Duration.ofSeconds(1L)).until(()-> TestSpanReporter.getAllSpans().size() == 2);
        assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2));
        assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get " + client.getCurrentURI()));
        assertThat(TestSpanReporter.getAllSpans().get(0).tags(), hasKey("error"));
        assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books/long"));
    }
}
 
Example 8
Source File: JaxRsClientStarter.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
public T start(Class<T> cls, String url, boolean trustAllCerts, String trustStore, String trustStorePassword, 
	List<?> providers, int connectTimeout, int receiveTimeout) {

	try {
		
		T resource = JAXRSClientFactory.create(url, cls, providers);
	    HTTPConduit conduit = WebClient.getConfig(resource).getHttpConduit();
	    WebClient.getConfig(resource).getInInterceptors().add(new LoggingInInterceptor());
	    WebClient.getConfig(resource).getOutInterceptors().add(new LoggingOutInterceptor());
		configureHTTPS(resource, conduit, trustAllCerts, trustStore, trustStorePassword);
		
	    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); 
	    httpClientPolicy.setConnectionTimeout(connectTimeout); 
	    httpClientPolicy.setReceiveTimeout(receiveTimeout); 
	    conduit.setClient(httpClientPolicy);
		
		return resource;
		
	} catch (Exception e) {
		LOG.error(" rest client '{}': NOT STARTED", url);
		return null;
	}
	
}
 
Example 9
Source File: ClientPolicyCalculatorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testIntersectClientPolicies() {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    ClientPolicyCalculator calc = new ClientPolicyCalculator();
    HTTPClientPolicy p1 = new HTTPClientPolicy();
    HTTPClientPolicy p2 = new HTTPClientPolicy();
    HTTPClientPolicy p = null;

    p1.setBrowserType("browser");
    p = calc.intersect(p1, p2);
    assertEquals("browser", p.getBrowserType());
    p1.setBrowserType(null);

    long connectionRequestTimeout = random.nextLong(0, 10000);
    p1.setConnectionRequestTimeout(connectionRequestTimeout);
    p = calc.intersect(p1, p2);
    assertEquals(connectionRequestTimeout, p.getConnectionRequestTimeout());

    long receiveTimeout = random.nextLong(0, 10000);
    p1.setReceiveTimeout(receiveTimeout);
    p = calc.intersect(p1, p2);
    assertEquals(receiveTimeout, p.getReceiveTimeout());

    long connectionTimeout = random.nextLong(0, 10000);
    p1.setConnectionTimeout(connectionTimeout);
    p = calc.intersect(p1, p2);
    assertEquals(connectionTimeout, p.getConnectionTimeout());

    p1.setAllowChunking(false);
    p2.setAllowChunking(false);
    p = calc.intersect(p1, p2);
    assertFalse(p.isAllowChunking());
}
 
Example 10
Source File: WebServiceProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
  protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException {
  	ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean();
  	proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString());
  	proxyFactoryBean.setServiceClass(serviceType);
  	proxyFactoryBean.setBus(bus);
  	T ref = (T) proxyFactoryBean.create();
  	Client proxy = ClientProxy.getClient(ref);  
HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT));
policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
conduit.setClient(policy);
      return ref;
  }
 
Example 11
Source File: RestUtil.java    From peer-os with Apache License 2.0 5 votes vote down vote up
public static WebClient createWebClient( String url, long connectTimeout, long receiveTimeout, int maxRetries )
{
    WebClient client = WebClient.create( url );

    HTTPConduit httpConduit = ( HTTPConduit ) WebClient.getConfig( client ).getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout( connectTimeout );
    httpClientPolicy.setReceiveTimeout( receiveTimeout );
    httpClientPolicy.setMaxRetransmits( maxRetries );

    httpConduit.setClient( httpClientPolicy );
    return client;
}
 
Example 12
Source File: AsyncHTTPConduit.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void propagateJaxwsSpecTimeoutSettings(Message message, HTTPClientPolicy csPolicy) {
    int receiveTimeout = determineReceiveTimeout(message, csPolicy);
    if (csPolicy.getReceiveTimeout() == 60000) {
        csPolicy.setReceiveTimeout(receiveTimeout);
    }
    int connectionTimeout = determineConnectionTimeout(message, csPolicy);
    if (csPolicy.getConnectionTimeout() == 30000) {
        csPolicy.setConnectionTimeout(connectionTimeout);
    }
}
 
Example 13
Source File: WebServiceProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
  protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException {
  	ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean();
  	proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString());
  	proxyFactoryBean.setServiceClass(serviceType);
  	proxyFactoryBean.setBus(bus);
  	T ref = (T) proxyFactoryBean.create();
  	Client proxy = ClientProxy.getClient(ref);  
HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT));
policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
conduit.setClient(policy);
      return ref;
  }
 
Example 14
Source File: NetSuiteClientService.java    From components with Apache License 2.0 5 votes vote down vote up
/**
 * Set HTTP client policy for given port.
 *
 * @param port port
 */
protected void setHttpClientPolicy(PortT port) {
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(connectionTimeout);
    httpClientPolicy.setReceiveTimeout(receiveTimeout);
    setHttpClientPolicy(port, httpClientPolicy);
}
 
Example 15
Source File: JAXRSSoapBookTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void doTestHelloSoapCustomDataBinding(String address) throws Exception {
    final QName serviceName = new QName("http://hello.com", "HelloWorld");
    final QName portName = new QName("http://hello.com", "HelloWorldPort");

    Service service = Service.create(serviceName);
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);

    HelloWorld hw = service.getPort(HelloWorld.class);

    Client cl = ClientProxy.getClient(hw);

    HTTPConduit http = (HTTPConduit) cl.getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(0);
    httpClientPolicy.setReceiveTimeout(0);

    http.setClient(httpClientPolicy);

    User user = new UserImpl("Barry");
    User user2 = hw.echoUser(user);

    assertNotSame(user, user2);
    assertEquals("Barry", user2.getName());
}
 
Example 16
Source File: WebClientBuilder.java    From peer-os with Apache License 2.0 4 votes vote down vote up
public static WebClient buildEnvironmentWebClient( final PeerInfo peerInfo, final String path,
                                                   final Object provider, long connectTimeoutMs, long readTimeoutMs,
                                                   int maxAttempts )
{
    String effectiveUrl = String.format( ENVIRONMENT_URL_TEMPLATE, peerInfo.getIp(), peerInfo.getPublicSecurePort(),
            path.startsWith( "/" ) ? path : "/" + path );
    WebClient client = WebClient.create( effectiveUrl, Arrays.asList( provider ) );
    client.type( MediaType.APPLICATION_JSON );
    client.accept( MediaType.APPLICATION_JSON );
    HTTPConduit httpConduit = ( HTTPConduit ) WebClient.getConfig( client ).getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout( connectTimeoutMs );
    httpClientPolicy.setReceiveTimeout( readTimeoutMs );
    httpClientPolicy.setMaxRetransmits( maxAttempts );

    httpConduit.setClient( httpClientPolicy );

    KeyStoreTool keyStoreManager = new KeyStoreTool();
    KeyStoreData keyStoreData = new KeyStoreData();
    keyStoreData.setupKeyStorePx2();
    keyStoreData.setAlias( SecuritySettings.KEYSTORE_PX2_ROOT_ALIAS );
    KeyStore keyStore = keyStoreManager.load( keyStoreData );

    LOG.debug( String.format( "Getting key with alias: %s for url: %s", SecuritySettings.KEYSTORE_PX2_ROOT_ALIAS,
            effectiveUrl ) );

    KeyStoreData trustStoreData = new KeyStoreData();
    trustStoreData.setupTrustStorePx2();
    KeyStore trustStore = keyStoreManager.load( trustStoreData );

    SSLManager sslManager = new SSLManager( keyStore, keyStoreData, trustStore, trustStoreData );

    TLSClientParameters tlsClientParameters = new TLSClientParameters();
    tlsClientParameters.setDisableCNCheck( true );
    tlsClientParameters.setTrustManagers( sslManager.getClientTrustManagers() );
    tlsClientParameters.setKeyManagers( sslManager.getClientKeyManagers() );
    tlsClientParameters.setCertAlias( SecuritySettings.KEYSTORE_PX2_ROOT_ALIAS );
    httpConduit.setTlsClientParameters( tlsClientParameters );
    return client;
}
 
Example 17
Source File: JAXWSEnvironment.java    From dropwizard-jaxws with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
        }
    }

    // ClientProxyFactoryBean bindingId
    if (clientBuilder.getBindingId() != null) {
        proxyFactory.setBindingId(clientBuilder.getBindingId());
    }

    // 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;
}
 
Example 18
Source File: HttpClient.java    From peer-os with Apache License 2.0 4 votes vote down vote up
public static WebClient createTrustedWebClientWithAuth( String url, KeyStore keyStore, char[] keyStorePassword,
                                                        byte[] serverFingerprint ) throws BazaarManagerException
{
    try
    {
        WebClient client = WebClient.create( url );

        // A client certificate is not provided in SSL context if async connection is used.
        // See details: #311 - Registration failure due to inability to find fingerprint.
        Map<String, Object> requestContext = WebClient.getConfig( client ).getRequestContext();
        requestContext.put( "use.async.http.conduit", Boolean.FALSE );

        HTTPConduit httpConduit = ( HTTPConduit ) WebClient.getConfig( client ).getConduit();

        HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();

        httpClientPolicy.setConnectionTimeout( SECONDS_30 );

        httpClientPolicy.setReceiveTimeout( SECONDS_60 );

        httpClientPolicy.setMaxRetransmits( DEFAULT_MAX_RETRANSMITS );

        httpConduit.setClient( httpClientPolicy );

        KeyManagerFactory keyManagerFactory =
                KeyManagerFactory.getInstance( KeyManagerFactory.getDefaultAlgorithm() );

        keyManagerFactory.init( keyStore, keyStorePassword );

        TLSClientParameters tlsClientParameters = new TLSClientParameters();

        tlsClientParameters.setDisableCNCheck( true );

        tlsClientParameters
                .setTrustManagers( new TrustManager[] { new FingerprintTrustManager( serverFingerprint ) } );

        tlsClientParameters.setKeyManagers( keyManagerFactory.getKeyManagers() );

        httpConduit.setTlsClientParameters( tlsClientParameters );

        return client;
    }
    catch ( Exception e )
    {
        throw new BazaarManagerException( e );
    }
}
 
Example 19
Source File: ClientPolicyCalculator.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a new HTTPClientPolicy that is compatible with the two specified
 * policies or null if no compatible policy can be determined.
 *
 * @param p1 one policy
 * @param p2 another policy
 * @return the compatible policy
 */
public HTTPClientPolicy intersect(HTTPClientPolicy p1, HTTPClientPolicy p2) {

    // incompatibilities

    if (!compatible(p1, p2)) {
        return null;
    }

    // ok - compute compatible policy

    HTTPClientPolicy p = new HTTPClientPolicy();
    p.setAccept(StringUtils.combine(p1.getAccept(), p2.getAccept()));
    p.setAcceptEncoding(StringUtils.combine(p1.getAcceptEncoding(), p2.getAcceptEncoding()));
    p.setAcceptLanguage(StringUtils.combine(p1.getAcceptLanguage(), p2.getAcceptLanguage()));
    if (p1.isSetAllowChunking()) {
        p.setAllowChunking(p1.isAllowChunking());
    } else if (p2.isSetAllowChunking()) {
        p.setAllowChunking(p2.isAllowChunking());
    }
    if (p1.isSetAutoRedirect()) {
        p.setAutoRedirect(p1.isAutoRedirect());
    } else if (p2.isSetAutoRedirect()) {
        p.setAutoRedirect(p2.isAutoRedirect());
    }
    p.setBrowserType(StringUtils.combine(p1.getBrowserType(), p2.getBrowserType()));
    if (p1.isSetCacheControl()) {
        p.setCacheControl(p1.getCacheControl());
    } else if (p2.isSetCacheControl()) {
        p.setCacheControl(p2.getCacheControl());
    }
    if (p1.isSetConnection()) {
        p.setConnection(p1.getConnection());
    } else if (p2.isSetConnection()) {
        p.setConnection(p2.getConnection());
    }
    if (p1.isSetContentType()) {
        p.setContentType(p1.getContentType());
    } else if (p2.isSetContentType()) {
        p.setContentType(p2.getContentType());
    }
    p.setCookie(StringUtils.combine(p1.getCookie(), p2.getCookie()));
    p.setDecoupledEndpoint(StringUtils.combine(p1.getDecoupledEndpoint(), p2.getDecoupledEndpoint()));
    p.setHost(StringUtils.combine(p1.getHost(), p2.getHost()));
    p.setProxyServer(StringUtils.combine(p1.getProxyServer(), p2.getProxyServer()));
    if (p1.isSetProxyServerPort()) {
        p.setProxyServerPort(p1.getProxyServerPort());
    } else if (p2.isSetProxyServerPort()) {
        p.setProxyServerPort(p2.getProxyServerPort());
    }
    if (p1.isSetProxyServerType()) {
        p.setProxyServerType(p1.getProxyServerType());
    } else if (p2.isSetProxyServerType()) {
        p.setProxyServerType(p2.getProxyServerType());
    }
    p.setReferer(StringUtils.combine(p1.getReferer(), p2.getReferer()));
    if (p1.isSetConnectionTimeout()) {
        p.setConnectionTimeout(p1.getConnectionTimeout());
    } else if (p2.isSetConnectionTimeout()) {
        p.setConnectionTimeout(p2.getConnectionTimeout());
    }
    if (p1.isSetConnectionRequestTimeout()) {
        p.setConnectionRequestTimeout(p1.getConnectionRequestTimeout());
    } else if (p2.isSetConnectionRequestTimeout()) {
        p.setConnectionRequestTimeout(p2.getConnectionRequestTimeout());
    }
    if (p1.isSetReceiveTimeout()) {
        p.setReceiveTimeout(p1.getReceiveTimeout());
    } else if (p2.isSetReceiveTimeout()) {
        p.setReceiveTimeout(p2.getReceiveTimeout());
    }

    return p;
}
 
Example 20
Source File: SignatureWhitespaceTest.java    From cxf with Apache License 2.0 2 votes vote down vote up
@org.junit.Test
public void testTrailingWhitespaceInSOAPBody() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SignatureWhitespaceTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = SignatureWhitespaceTest.class.getResource("DoubleItAction.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSignaturePort2");

    Dispatch<StreamSource> dispatch =
        service.createDispatch(portQName, StreamSource.class, Service.Mode.MESSAGE);

    Client client = ((DispatchImpl<StreamSource>) dispatch).getClient();

    HTTPConduit http = (HTTPConduit) client.getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(0);
    httpClientPolicy.setReceiveTimeout(0);
    http.setClient(httpClientPolicy);


    // Creating a DOMSource Object for the request

    URL requestFile =
        SignatureWhitespaceTest.class.getResource("request-with-trailing-whitespace.xml");

    StreamSource request = new StreamSource(new File(requestFile.getPath()));

    updateAddressPort(dispatch, test.getPort());

    // Make a successful request
    StreamSource response = dispatch.invoke(request);
    assertNotNull(response);

    Document doc = StaxUtils.read(response.getInputStream());
    assertEquals("50", doc.getElementsByTagNameNS(null, "doubledNumber").item(0).getTextContent());

    ((java.io.Closeable)dispatch).close();
}