Java Code Examples for org.apache.cxf.transport.http.HTTPConduit

The following examples show how to use org.apache.cxf.transport.http.HTTPConduit. These examples are extracted from open source projects. 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 Project: peer-os   Source File: RestUtil.java    License: Apache License 2.0 7 votes vote down vote up
public static WebClient createTrustedWebClient( String url )
{
    WebClient client = WebClient.create( url );

    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 2
public RestTagClient(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, TagService.class, Arrays.asList(provider));
	} else {
		proxy = JAXRSClientFactory.create(endpoint, TagService.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
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 4
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 5
Source Project: cxf   Source File: JAXRSSoapBookTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetBook123Client() throws Exception {

    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress,
                                                              BookStoreJaxrsJaxws.class);
    HTTPConduit conduit = (HTTPConduit)WebClient.getConfig(proxy).getConduit();

    Book b = proxy.getBook(Long.valueOf("123"));
    assertEquals(123, b.getId());
    assertEquals("CXF in Action", b.getName());

    HTTPConduit conduit2 = (HTTPConduit)WebClient.getConfig(proxy).getConduit();
    assertSame(conduit, conduit2);

    conduit.getClient().setAutoRedirect(true);
    b = proxy.getBook(Long.valueOf("123"));
    assertEquals(123, b.getId());
    assertEquals("CXF in Action", b.getName());
}
 
Example 6
Source Project: peer-os   Source File: RestUtil.java    License: 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 Project: cxf   Source File: HttpConduitConfigApplier.java    License: Apache License 2.0 6 votes vote down vote up
private void applyAuthSupplier(Dictionary<String, String> d, HTTPConduit c) {
    Enumeration<String> keys = d.keys();
    while (keys.hasMoreElements()) {
        String k = keys.nextElement();
        if (k.startsWith("authSupplier")) {
            String v = d.get(k);
            Object obj;
            try {
                obj = Class.forName(v).newInstance();
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
            if (obj instanceof HttpAuthSupplier) {
                c.setAuthSupplier((HttpAuthSupplier)obj);
            }
        }
    }
}
 
Example 8
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
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 10
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 11
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 12
Source Project: syncope   Source File: BatchResponse.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * If asynchronous processing was requested, queries the monitor URI.
 *
 * @param monitor monitor URI
 * @param jwt authorization JWT
 * @param boundary mutipart / mixed boundary
 * @param tlsClientParameters (optional) TLS client parameters
 *
 * @return the last Response received from the Batch service
 */
public static Response poll(
        final URI monitor,
        final String jwt,
        final String boundary,
        final TLSClientParameters tlsClientParameters) {

    WebClient webClient = WebClient.create(monitor).
            header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt).
            type(RESTHeaders.multipartMixedWith(boundary.substring(2)));
    if (tlsClientParameters != null) {
        ClientConfiguration config = WebClient.getConfig(webClient);
        HTTPConduit httpConduit = (HTTPConduit) config.getConduit();
        httpConduit.setTlsClientParameters(tlsClientParameters);
    }

    return webClient.get();
}
 
Example 13
Source Project: cxf   Source File: HttpConduitConfigApplierTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTrustVerificationEnabled() throws IOException {
    HttpConduitConfigApplier configApplier = new HttpConduitConfigApplier();

    Dictionary<String, String> configValues = new Hashtable<>();
    configValues.put("tlsClientParameters.disableCNCheck", "true");
    configValues.put("tlsClientParameters.trustManagers.disableTrustVerification", "false");
    String address = "https://localhost:12345";
    Bus bus = new ExtensionManagerBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress(address);
    HTTPConduit conduit = new URLConnectionHTTPConduit(bus, ei, null);

    configApplier.apply(configValues, conduit, address);

    assertNotNull(conduit.getTlsClientParameters().getTrustManagers());
    assertEquals(conduit.getTlsClientParameters().getTrustManagers().length, 1);
    assertFalse(conduit.getTlsClientParameters().getTrustManagers()[0].getClass()
            .getName().startsWith(InsecureTrustManager.class.getName()));
    assertTrue(conduit.getTlsClientParameters().isDisableCNCheck());
}
 
Example 14
Source Project: cxf   Source File: TransformFeatureTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testClientOutTransformationOnConnectionRefused() throws IOException {
    Service service = Service.create(SERVICE_NAME);
    ServerSocket socket = new ServerSocket(0);
    String endpoint = "http://127.0.0.1:" + socket.getLocalPort() + "/";
    socket.close();
    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpoint);

    Echo port = service.getPort(PORT_NAME, Echo.class);
    Client client = ClientProxy.getClient(port);
    HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
    // We need to disable chunking to make the client write directly to the connection OutputStream
    httpConduit.getClient().setAllowChunking(false);

    XSLTOutInterceptor outInterceptor = new XSLTOutInterceptor(XSLT_REQUEST_PATH);
    client.getOutInterceptors().add(outInterceptor);

    try {
        port.echo("test");
        fail("Connection refused expected");
    } catch (Exception e) {
        String exceptionMessage = e.getMessage();
        assertTrue(exceptionMessage.toLowerCase().contains("connection refused"));
    }
}
 
Example 15
Source Project: cxf   Source File: BusShutdownTest.java    License: Apache License 2.0 6 votes vote down vote up
private void doWork(URL wsdlUrl, String address) {
    SOAPService service = new SOAPService(wsdlUrl);
    assertNotNull(service);
    Greeter greeter = service.getSoapPort();

    // overwrite client address
    InvocationHandler handler = Proxy.getInvocationHandler(greeter);
    BindingProvider bp = (BindingProvider)handler;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                               address);
    Client client = ClientProxy.getClient(greeter);
    HTTPConduit c = (HTTPConduit)client.getConduit();
    c.setClient(new HTTPClientPolicy());
    c.getClient().setConnection(ConnectionType.CLOSE);

    // invoke twoway call
    greeter.sayHi();
}
 
Example 16
Source Project: cxf   Source File: SSLNettyServerTest.java    License: Apache License 2.0 6 votes vote down vote up
private static void setupTLS(Greeter port)
    throws FileNotFoundException, IOException, GeneralSecurityException {
    String keyStoreLoc =
        "/keys/clientstore.jks";
    HTTPConduit httpConduit = (HTTPConduit) ClientProxy.getClient(port).getConduit();

    TLSClientParameters tlsCP = new TLSClientParameters();
    String keyPassword = "ckpass";
    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(SSLNettyServerTest.class.getResourceAsStream(keyStoreLoc), "cspass".toCharArray());
    KeyManager[] myKeyManagers = getKeyManagers(keyStore, keyPassword);
    tlsCP.setKeyManagers(myKeyManagers);


    KeyStore trustStore = KeyStore.getInstance("JKS");
    trustStore.load(SSLNettyServerTest.class.getResourceAsStream(keyStoreLoc), "cspass".toCharArray());
    TrustManager[] myTrustStoreKeyManagers = getTrustManagers(trustStore);
    tlsCP.setTrustManagers(myTrustStoreKeyManagers);

    tlsCP.setDisableCNCheck(true);
    httpConduit.setTlsClientParameters(tlsCP);
}
 
Example 17
Source Project: cxf   Source File: CXF6655Test.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConnectionWithProxy() throws Exception {
    QName serviceName = new QName("http://cxf.apache.org/systest/jaxws/", "HelloService");
    HelloService service = new HelloService(null, serviceName);
    assertNotNull(service);
    Hello hello = service.getHelloPort();

    Client client = ClientProxy.getClient(hello);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    HTTPConduit http = (HTTPConduit)client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setAllowChunking(false);
    httpClientPolicy.setReceiveTimeout(0);
    httpClientPolicy.setProxyServerType(ProxyServerType.HTTP);
    httpClientPolicy.setProxyServer("localhost");
    httpClientPolicy.setProxyServerPort(PROXY_PORT);
    http.setClient(httpClientPolicy);

    ((BindingProvider)hello).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                                     "http://localhost:" + PORT + "/hello");
    assertEquals("getSayHi", hello.sayHi("SayHi"));

}
 
Example 18
Source Project: cxf   Source File: HttpConduitConfigurationTest.java    License: Apache License 2.0 6 votes vote down vote up
private void verifyConduit(HTTPConduit conduit) {
    AuthorizationPolicy authp = conduit.getAuthorization();
    assertNotNull(authp);
    assertEquals("Betty", authp.getUserName());
    assertEquals("password", authp.getPassword());
    TLSClientParameters tlscps = conduit.getTlsClientParameters();
    assertNotNull(tlscps);
    assertTrue(tlscps.isDisableCNCheck());
    assertEquals(3600000, tlscps.getSslCacheTimeout());

    KeyManager[] kms = tlscps.getKeyManagers();
    assertTrue(kms != null && kms.length == 1);
    assertTrue(kms[0] instanceof X509KeyManager);

    TrustManager[] tms = tlscps.getTrustManagers();
    assertTrue(tms != null && tms.length == 1);
    assertTrue(tms[0] instanceof X509TrustManager);

    FiltersType csfs = tlscps.getCipherSuitesFilter();
    assertNotNull(csfs);
    assertEquals(1, csfs.getInclude().size());
    assertEquals(1, csfs.getExclude().size());
    HTTPClientPolicy clientPolicy = conduit.getClient();
    assertEquals(10240, clientPolicy.getChunkLength());
}
 
Example 19
Source Project: cxf   Source File: JaxwsBasicAuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testUseBasicAuthFromClient() throws Exception {
    // setup the feature by using JAXWS front-end API
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    // set a fake address to kick off the failover feature
    factory.setAddress("http://localhost:" + PORT + "/SoapContext/GreeterPort");
    factory.setServiceClass(Greeter.class);
    Greeter proxy = factory.create(Greeter.class);

    Client clientProxy = ClientProxy.getClient(proxy);
    HTTPConduit conduit = (HTTPConduit) clientProxy.getConduit();
    conduit.getAuthorization().setAuthorizationType("Basic");
    conduit.getAuthorization().setUserName("user");
    conduit.getAuthorization().setPassword("test");
    
    final BindingProvider bindingProvider = (BindingProvider) proxy;
    bindingProvider.getRequestContext().put("encode.basicauth.with.iso8859", true);

    String response = proxy.greetMe("cxf");
    assertThat("CXF is protected: cxf", equalTo(response));
}
 
Example 20
Source Project: cxf   Source File: HttpConduitConfigApplier.java    License: Apache License 2.0 6 votes vote down vote up
private void applyProxyAuthorization(Dictionary<String, String> d, HTTPConduit c) {
    Enumeration<String> keys = d.keys();
    ProxyAuthorizationPolicy p = c.getProxyAuthorization();
    while (keys.hasMoreElements()) {
        String k = keys.nextElement();
        if (k.startsWith("proxyAuthorization.")) {
            if (p == null) {
                p = new ProxyAuthorizationPolicy();
                c.setProxyAuthorization(p);
            }
            String v = d.get(k);
            k = k.substring("proxyAuthorization.".length());

            if ("UserName".equals(k)) {
                p.setUserName(v);
            } else if ("Password".equals(k)) {
                p.setPassword(v);
            } else if ("Authorization".equals(k)) {
                p.setAuthorization(v);
            } else if ("AuthorizationType".equals(k)) {
                p.setAuthorizationType(v);
            }
        }
    }
}
 
Example 21
Source Project: cxf   Source File: NettyHttpConduitFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public HTTPConduit createConduit(HTTPTransportFactory f,
                                 Bus bus,
                                 EndpointInfo localInfo,
                                 EndpointReferenceType target)
    throws IOException {
    // need to check if the EventLoopGroup is created or not
    // if not create a new EventLoopGroup for it
    EventLoopGroup eventLoopGroup = bus.getExtension(EventLoopGroup.class);
    if (eventLoopGroup == null) {
        final EventLoopGroup group = new NioEventLoopGroup();
        // register a BusLifeCycleListener for it
        bus.setExtension(group, EventLoopGroup.class);
        registerBusLifeListener(bus, group);
    }
    return new NettyHttpConduit(bus, localInfo, target, this);
}
 
Example 22
Source Project: cxf   Source File: ClientConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
public long getSynchronousTimeout() {
    Conduit conduit = getConduit();
    if (conduit instanceof HTTPConduit) {
        return ((HTTPConduit)conduit).getClient().getReceiveTimeout();
    }
    return synchronousTimeout;
}
 
Example 23
/**
 * Configures the timeout (in seconds)
 */
protected void configureTimeout(int timeout) {
	if (timeout <= 0)
		return;

	HTTPClientPolicy policy = new HTTPClientPolicy();
	policy.setConnectionTimeout(timeout * 1000);
	policy.setReceiveTimeout(timeout * 1000);

	org.apache.cxf.endpoint.Client cl = ClientProxy.getClient(client);
	HTTPConduit httpConduit = (HTTPConduit) cl.getConduit();
	httpConduit.setClient(policy);
}
 
Example 24
Source Project: cxf-jaxws   Source File: ClientConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public HTTPConduit ticketAgentConduit()
    throws NoSuchAlgorithmException, KeyStoreException,
    CertificateException, IOException {
  Client client = ClientProxy.getClient(ticketAgentProxy());

  HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
  httpConduit.setTlsClientParameters(tlsClientParameters());

  return httpConduit;
}
 
Example 25
Source Project: cxf-jaxws   Source File: ClientConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public HTTPConduit ticketAgentConduit() {
  HTTPConduit httpConduit =
      (HTTPConduit) ticketAgentClientProxy().getConduit();
  httpConduit.setAuthorization(basicAuthorization());

  return httpConduit;
}
 
Example 26
Source Project: dubbox   Source File: WebServiceProtocol.java    License: 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 27
Source Project: dubbox-hystrix   Source File: WebServiceProtocol.java    License: 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 28
Source Project: uavstack   Source File: CECXFClient.java    License: Apache License 2.0 5 votes vote down vote up
private void configHttpConduit(Object port) {

        // 设置客户端的配置信息,超时等.
        Client proxy = ClientProxy.getClient(port);
        HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
        HTTPClientPolicy policy = new HTTPClientPolicy();

        // 连接服务器超时时间
        policy.setConnectionTimeout(this.connectTimeout);
        // 等待服务器响应超时时间
        policy.setReceiveTimeout(this.receiveTimeout);

        conduit.setClient(policy);
    }
 
Example 29
Source Project: cxf   Source File: AsyncHTTPConduitTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testTimeout() throws Exception {
    updateAddressPort(g, PORT);
    HTTPConduit c = (HTTPConduit)ClientProxy.getClient(g).getConduit();
    c.getClient().setReceiveTimeout(3000);
    try {
        assertEquals("Hello " + request, g.greetMeLater(-5000));
        fail();
    } catch (Exception ex) {
        //expected!!!
    }
}
 
Example 30
Source Project: peer-os   Source File: WebClientBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public static WebClient buildEnvironmentWebClient( final PeerInfo peerInfo, final String path,
                                                   final Object provider )
{
    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( DEFAULT_CONNECTION_TIMEOUT );
    httpClientPolicy.setReceiveTimeout( DEFAULT_RECEIVE_TIMEOUT );
    httpClientPolicy.setMaxRetransmits( DEFAULT_MAX_RETRANSMITS );

    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;
}