org.apache.cxf.transports.http.configuration.HTTPClientPolicy Java Examples

The following examples show how to use org.apache.cxf.transports.http.configuration.HTTPClientPolicy. 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: RestUtil.java    From peer-os with 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
Source File: JettyDigestAuthTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private HTTPConduit setupClient(boolean async) throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    greeter = new SOAPService(wsdl, SERVICE_NAME).getPort(Greeter.class);
    BindingProvider bp = (BindingProvider)greeter;
    ClientProxy.getClient(greeter).getInInterceptors().add(new LoggingInInterceptor());
    ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingOutInterceptor());
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                               ADDRESS);
    HTTPConduit cond = (HTTPConduit)ClientProxy.getClient(greeter).getConduit();
    HTTPClientPolicy client = new HTTPClientPolicy();
    cond.setClient(client);
    if (async) {
        if (cond instanceof AsyncHTTPConduit) {
            UsernamePasswordCredentials creds = new UsernamePasswordCredentials("ffang", "pswd");
            bp.getRequestContext().put(Credentials.class.getName(), creds);
            bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);
            client.setAutoRedirect(true);
        } else {
            fail("Not an async conduit");
        }
    } else {
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "ffang");
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
        cond.setAuthSupplier(new DigestAuthSupplier());
    }

    ClientProxy.getClient(greeter).getOutInterceptors()
        .add(new AbstractPhaseInterceptor<Message>(Phase.PRE_STREAM_ENDING) {

            public void handleMessage(Message message) throws Fault {
                Map<String, ?> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
                if (headers.containsKey("Proxy-Authorization")) {
                    throw new RuntimeException("Should not have Proxy-Authorization");
                }
            }
        });
    client.setAllowChunking(false);
    return cond;
}
 
Example #3
Source File: HTTPConduit.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected static int determineConnectionTimeout(Message message,
        HTTPClientPolicy csPolicy) {
    long ctimeout = csPolicy.getConnectionTimeout();
    if (message.get(Message.CONNECTION_TIMEOUT) != null) {
        Object obj = message.get(Message.CONNECTION_TIMEOUT);
        try {
            ctimeout = Long.parseLong(obj.toString());
        } catch (NumberFormatException e) {
            LOG.log(Level.WARNING, "INVALID_TIMEOUT_FORMAT", new Object[] {
                Message.CONNECTION_TIMEOUT, obj.toString()
            });
        }
    }
    if (ctimeout > Integer.MAX_VALUE) {
        ctimeout = Integer.MAX_VALUE;
    }
    return (int)ctimeout;
}
 
Example #4
Source File: HTTPConduit.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected static int determineReceiveTimeout(Message message,
        HTTPClientPolicy csPolicy) {
    long rtimeout = csPolicy.getReceiveTimeout();
    if (message.get(Message.RECEIVE_TIMEOUT) != null) {
        Object obj = message.get(Message.RECEIVE_TIMEOUT);
        try {
            rtimeout = Long.parseLong(obj.toString());
        } catch (NumberFormatException e) {
            LOG.log(Level.WARNING, "INVALID_TIMEOUT_FORMAT", new Object[] {
                Message.RECEIVE_TIMEOUT, obj.toString()
            });
        }
    }
    if (rtimeout > Integer.MAX_VALUE) {
        rtimeout = Integer.MAX_VALUE;
    }
    return (int)rtimeout;
}
 
Example #5
Source File: HTTPClientAssertionBuilderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testHTTPCLientPolicyAssertionEqual() throws Exception {
    HTTPClientAssertionBuilder ab = new HTTPClientAssertionBuilder();
    JaxbAssertion<HTTPClientPolicy>  a = ab.buildAssertion();
    a.setData(new HTTPClientPolicy());
    assertTrue(a.equal(a));
    JaxbAssertion<HTTPClientPolicy> b = ab.buildAssertion();
    b.setData(new HTTPClientPolicy());
    assertTrue(a.equal(b));
    HTTPClientPolicy pa = new HTTPClientPolicy();
    a.setData(pa);
    assertTrue(a.equal(a));
    HTTPClientPolicy pb = new HTTPClientPolicy();
    b.setData(pb);
    assertTrue(a.equal(b));
    pa.setDecoupledEndpoint("http://localhost:9999/decoupled_endpoint");
    assertFalse(a.equal(b));
}
 
Example #6
Source File: HttpConduitConfigurationTest.java    From cxf with 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 #7
Source File: HTTPConduit.java    From cxf with Apache License 2.0 6 votes vote down vote up
public HTTPClientPolicy getClient(Message message) {
    ClientPolicyCalculator cpc = new ClientPolicyCalculator();
    HTTPClientPolicy pol = message.get(HTTPClientPolicy.class);
    updateClientPolicy(message);
    if (pol != null) {
        pol = cpc.intersect(pol, clientSidePolicy);
    } else {
        pol = clientSidePolicy;
    }

    PolicyDataEngine policyDataEngine = bus.getExtension(PolicyDataEngine.class);
    if (policyDataEngine == null) {
        return pol;
    }
    return policyDataEngine.getPolicy(message, pol, cpc);
}
 
Example #8
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 #9
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 #10
Source File: RestBookmarkClient.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
public RestBookmarkClient(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, BookmarkService.class, Arrays.asList(provider));
	} else {
		proxy = JAXRSClientFactory.create(endpoint, BookmarkService.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 #11
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 #12
Source File: RestTagClient.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #13
Source File: BusShutdownTest.java    From cxf with 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 #14
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 #15
Source File: JAXRSAsyncClientTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testPatchBookTimeout() throws Exception {
    String address = "http://localhost:" + PORT + "/bookstore/patch";
    WebClient wc = WebClient.create(address);
    wc.type("application/xml");
    ClientConfiguration clientConfig = WebClient.getConfig(wc);
    clientConfig.getRequestContext().put("use.async.http.conduit", true);
    HTTPClientPolicy clientPolicy = clientConfig.getHttpConduit().getClient();
    clientPolicy.setReceiveTimeout(500);
    clientPolicy.setConnectionTimeout(500);
    try {
        Book book = wc.invoke("PATCH", new Book("Timeout", 123L), Book.class);
        fail("should throw an exception due to timeout, instead got " + book);
    } catch (javax.ws.rs.ProcessingException e) {
        //expected!!!
    }
}
 
Example #16
Source File: AhcWebSocketConduit.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
protected void setupConnection(Message message, Address address, HTTPClientPolicy csPolicy)
    throws IOException {

    URI currentURL = address.getURI();
    String s = currentURL.getScheme();
    if (!"ws".equals(s) && !"wss".equals(s)) {
        throw new MalformedURLException("unknown protocol: " + s);
    }

    message.put("http.scheme", currentURL.getScheme());
    String httpRequestMethod =
            (String)message.get(Message.HTTP_REQUEST_METHOD);
    if (httpRequestMethod == null) {
        httpRequestMethod = "POST";
        message.put(Message.HTTP_REQUEST_METHOD, httpRequestMethod);
    }

    final AhcWebSocketConduitRequest request = new AhcWebSocketConduitRequest(currentURL, httpRequestMethod);
    final int rtimeout = determineReceiveTimeout(message, csPolicy);
    request.setReceiveTimeout(rtimeout);
    message.put(AhcWebSocketConduitRequest.class, request);


}
 
Example #17
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 #18
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 #19
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 #20
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 #21
Source File: URLConnectionHTTPConduit.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void setupNewConnection(String newURL) throws IOException {
    HTTPClientPolicy cp = getClient(outMessage);
    Address address;
    try {
        if (defaultAddress.getString().equals(newURL)) {
            address = defaultAddress;
        } else {
            address = new Address(newURL);
        }
    } catch (URISyntaxException e) {
        throw new IOException(e);
    }
    setupConnection(outMessage, address, cp);
    this.url = address.getURI();
    connection = (HttpURLConnection)outMessage.get(KEY_HTTP_CONNECTION);
}
 
Example #22
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 #23
Source File: OpenTracingTracingTest.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 OpenTracingClientFeature(tracer)), 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(()-> REPORTER.getSpans().size() == 2);
        assertThat(REPORTER.getSpans().toString(), REPORTER.getSpans().size(), equalTo(2));
        assertThat(REPORTER.getSpans().get(0).getOperationName(), equalTo("GET " + client.getCurrentURI()));
        assertThat(REPORTER.getSpans().get(0).getTags(), hasItem(Tags.ERROR.getKey(), Boolean.TRUE));
        assertThat(REPORTER.getSpans().get(1).getOperationName(), equalTo("GET /bookstore/books/long"));
    }
}
 
Example #24
Source File: ClientPolicyCalculatorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompatibleClientPolicies() {
    ClientPolicyCalculator calc = new ClientPolicyCalculator();
    HTTPClientPolicy p1 = new HTTPClientPolicy();
    assertTrue("Policy is not compatible with itself.", calc.compatible(p1, p1));
    HTTPClientPolicy p2 = new HTTPClientPolicy();
    assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
    p1.setBrowserType("browser");
    assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
    p1.setBrowserType(null);
    p1.setConnectionTimeout(10000);
    assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
    p1.setAllowChunking(false);
    p2.setAllowChunking(true);
    assertFalse("Policies are compatible.", calc.compatible(p1, p2));
    p2.setAllowChunking(false);
    assertTrue("Policies are compatible.", calc.compatible(p1, p2));
}
 
Example #25
Source File: CXF6655Test.java    From cxf with 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 #26
Source File: PolicyUtilsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
void testAssertClientPolicy(boolean outbound) {
    Message message = control.createMock(Message.class);
    HTTPClientPolicy ep = new HTTPClientPolicy();
    HTTPClientPolicy cmp = new HTTPClientPolicy();

    cmp.setConnectionTimeout(60000L);
    HTTPClientPolicy icmp = new HTTPClientPolicy();
    icmp.setAllowChunking(false);

    AssertionInfo eai = getClientPolicyAssertionInfo(ep);
    AssertionInfo cmai = getClientPolicyAssertionInfo(cmp);
    AssertionInfo icmai = getClientPolicyAssertionInfo(icmp);

    AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST,
                                                               PolicyAssertion.class));
    Collection<AssertionInfo> ais = new ArrayList<>();
    ais.add(eai);
    ais.add(cmai);
    ais.add(icmai);
    aim.put(new ClientPolicyCalculator().getDataClassName(), ais);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
    Exchange ex = control.createMock(Exchange.class);
    EasyMock.expect(message.getExchange()).andReturn(ex).atLeastOnce();
    EasyMock.expect(ex.getOutMessage()).andReturn(outbound ? message : null).atLeastOnce();
    if (!outbound) {
        EasyMock.expect(ex.getOutFaultMessage()).andReturn(null).atLeastOnce();
    }

    control.replay();
    PolicyDataEngine pde = new PolicyDataEngineImpl(null);
    pde.assertMessage(message, ep, new ClientPolicyCalculator());
    assertTrue(eai.isAsserted());
    assertTrue(cmai.isAsserted());
    assertTrue(icmai.isAsserted());
    control.verify();
}
 
Example #27
Source File: ProtocolVariationsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void initDecoupledEndpoint(Client c) {
    // programatically configure decoupled endpoint that is guaranteed to
    // be unique across all test cases
    decoupledEndpoint = "http://localhost:"
        + allocatePort("decoupled-" + decoupledCount++) + "/decoupled_endpoint";

    HTTPConduit hc = (HTTPConduit)(c.getConduit());
    HTTPClientPolicy cp = hc.getClient();
    cp.setDecoupledEndpoint(decoupledEndpoint);

    LOG.fine("Using decoupled endpoint: " + cp.getDecoupledEndpoint());
}
 
Example #28
Source File: ClientPolicyCalculatorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testEqualClientPolicies() {
    ClientPolicyCalculator calc = new ClientPolicyCalculator();
    HTTPClientPolicy p1 = new HTTPClientPolicy();
    assertTrue(calc.equals(p1, p1));
    HTTPClientPolicy p2 = new HTTPClientPolicy();
    assertTrue(calc.equals(p1, p2));
    p1.setDecoupledEndpoint("http://localhost:8080/decoupled");
    assertFalse(calc.equals(p1, p2));
    p2.setDecoupledEndpoint("http://localhost:8080/decoupled");
    assertTrue(calc.equals(p1, p2));
    p1.setReceiveTimeout(10000L);
    assertFalse(calc.equals(p1, p2));
}
 
Example #29
Source File: JavaFirstSchemaValidationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static <T> T createClient(String port, Class<T> serviceClass, SchemaValidationType type,
        Feature ... features) {
    JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
    clientFactory.setServiceClass(serviceClass);


    clientFactory.setAddress(getAddress(port, serviceClass));

    if (features != null) {
        Collections.addAll(clientFactory.getFeatures(), features);
    }

    @SuppressWarnings("unchecked")
    T newClient = (T)clientFactory.create();

    Client proxy = ClientProxy.getClient(newClient);

    if (type != null) {
        proxy.getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, type);
    }

    HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
    // give me longer debug times
    HTTPClientPolicy clientPolicy = new HTTPClientPolicy();
    clientPolicy.setConnectionTimeout(1000000);
    clientPolicy.setReceiveTimeout(1000000);
    conduit.setClient(clientPolicy);

    return newClient;
}
 
Example #30
Source File: SequenceTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void initDecoupledEndpoint(Client c) {
    // programatically configure decoupled endpoint that is guaranteed to
    // be unique across all test cases
    decoupledEndpoint = "http://localhost:"
        + allocatePort("decoupled-" + decoupledCount++) + "/decoupled_endpoint";

    HTTPConduit hc = (HTTPConduit)(c.getConduit());
    HTTPClientPolicy cp = hc.getClient();
    cp.setDecoupledEndpoint(decoupledEndpoint);

    LOG.fine("Using decoupled endpoint: " + cp.getDecoupledEndpoint());
}