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

The following examples show how to use org.apache.cxf.transports.http.configuration.HTTPClientPolicy#setAllowChunking() . 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: 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 3
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 4
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 5
Source File: OnvifDevice.java    From onvif with Apache License 2.0 5 votes vote down vote up
public JaxWsProxyFactoryBean getServiceProxy(BindingProvider servicePort, String serviceAddr) {

    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.getHandlers();

    if (serviceAddr != null) proxyFactory.setAddress(serviceAddr);
    proxyFactory.setServiceClass(servicePort.getClass());

    SoapBindingConfiguration config = new SoapBindingConfiguration();

    config.setVersion(Soap12.getInstance());
    proxyFactory.setBindingConfig(config);
    Client deviceClient = ClientProxy.getClient(servicePort);

    if (verbose) {
      // these logging interceptors are depreciated, but should be fine for debugging/development
      // use.
      proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor());
      proxyFactory.getInInterceptors().add(new LoggingInInterceptor());
    }

    HTTPConduit http = (HTTPConduit) deviceClient.getConduit();
    if (securityHandler != null) proxyFactory.getHandlers().add(securityHandler);
    HTTPClientPolicy httpClientPolicy = http.getClient();
    httpClientPolicy.setConnectionTimeout(36000);
    httpClientPolicy.setReceiveTimeout(32000);
    httpClientPolicy.setAllowChunking(false);

    return proxyFactory;
  }
 
Example 6
Source File: AsyncHTTPConduitTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCall() throws Exception {
    updateAddressPort(g, PORT);
    assertEquals("Hello " + request, g.greetMe(request));
    HTTPConduit c = (HTTPConduit)ClientProxy.getClient(g).getConduit();
    HTTPClientPolicy cp = new HTTPClientPolicy();
    cp.setAllowChunking(false);
    c.setClient(cp);
    assertEquals("Hello " + request, g.greetMe(request));
}
 
Example 7
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 8
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 9
Source File: BatchEEJAXRS1CxfClient.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
private static HTTPClientPolicy defaultClientPolicy() {
    final HTTPClientPolicy client = new HTTPClientPolicy();
    client.setConnection(ConnectionType.CLOSE);
    client.setAllowChunking(false);
    client.setConnectionTimeout(0);
    client.setReceiveTimeout(0);
    return client;
}
 
Example 10
Source File: UndertowDigestAuthTest.java    From cxf with Apache License 2.0 4 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();
    client.setConnectionTimeout(600000);
    client.setReceiveTimeout(600000);
    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 11
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;
}