Search in sources :

Example 61 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class DispatchClientServerTest method doJAXBPayload.

private void doJAXBPayload(Dispatch<Object> disp) throws Exception {
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
    String expected = "Hello Jeeves";
    GreetMe greetMe = new GreetMe();
    greetMe.setRequestType("Jeeves");
    Object response = disp.invoke(greetMe);
    assertNotNull(response);
    String responseValue = ((GreetMeResponse) response).getResponseType();
    assertEquals("Expected string, " + expected, expected, responseValue);
    // Test oneway
    disp.invokeOneWay(greetMe);
    // Test async polling
    Response<Object> response2 = disp.invokeAsync(greetMe);
    assertNotNull(response2);
    GreetMeResponse greetMeResponse = (GreetMeResponse) response2.get();
    String responseValue2 = greetMeResponse.getResponseType();
    assertEquals("Expected string, " + expected, expected, responseValue2);
    // Test async callback
    TestJAXBHandler tjbh = new TestJAXBHandler();
    Future<?> fd = disp.invokeAsync(greetMe, tjbh);
    assertNotNull(fd);
    waitForFuture(fd);
    String responseValue3 = ((GreetMeResponse) tjbh.getResponse()).getResponseType();
    assertEquals("Expected string, " + expected, expected, responseValue3);
    org.apache.hello_world_soap_http.types.TestDocLitFault fr = new org.apache.hello_world_soap_http.types.TestDocLitFault();
    fr.setFaultType(BadRecordLitFault.class.getSimpleName());
    tjbh = new TestJAXBHandler();
    fd = disp.invokeAsync(fr, tjbh);
    waitForFuture(fd);
    try {
        fd.get();
        fail("did not get expected exception");
    } catch (ExecutionException ex) {
    // expected
    }
    GreetMeLater later = new GreetMeLater();
    later.setRequestType(1000);
    HTTPClientPolicy pol = new HTTPClientPolicy();
    pol.setReceiveTimeout(100);
    disp.getRequestContext().put(HTTPClientPolicy.class.getName(), pol);
    Response<Object> o = disp.invokeAsync(later);
    try {
        o.get(10, TimeUnit.SECONDS);
        fail("Should have gotten a SocketTimeoutException");
    } catch (ExecutionException ex) {
        assertTrue(ex.getCause() instanceof SocketTimeoutException);
    }
    later.setRequestType(20000);
    pol.setReceiveTimeout(20000);
    disp.getRequestContext().put(HTTPClientPolicy.class.getName(), pol);
    o = disp.invokeAsync(later);
    try {
        o.get(100, TimeUnit.MILLISECONDS);
        fail("Should have gotten a SocketTimeoutException");
    } catch (TimeoutException ex) {
    // ignore - expected
    }
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault) SocketTimeoutException(java.net.SocketTimeoutException) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ExecutionException(java.util.concurrent.ExecutionException) GreetMeLater(org.apache.hello_world_soap_http.types.GreetMeLater) TimeoutException(java.util.concurrent.TimeoutException) SocketTimeoutException(java.net.SocketTimeoutException)

Example 62 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class UndertowDigestAuthTest method setupClient.

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;
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) DigestAuthSupplier(org.apache.cxf.transport.http.auth.DigestAuthSupplier) Message(org.apache.cxf.message.Message) Fault(org.apache.cxf.interceptor.Fault) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) AsyncHTTPConduit(org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AsyncHTTPConduit(org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Greeter(org.apache.hello_world_soap_http.Greeter) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Map(java.util.Map) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 63 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class ConnectionHelper method setKeepAliveConnection.

public static void setKeepAliveConnection(Object proxy, boolean keepAlive, boolean force) {
    if (force || "HP-UX".equals(System.getProperty("os.name")) || "Windows XP".equals(System.getProperty("os.name"))) {
        Client client = ClientProxy.getClient(proxy);
        HTTPConduit hc = (HTTPConduit) client.getConduit();
        HTTPClientPolicy cp = hc.getClient();
        cp.setConnection(keepAlive ? ConnectionType.KEEP_ALIVE : ConnectionType.CLOSE);
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client)

Example 64 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class JAXRSAsyncClientTest method testPatchBookTimeout.

@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!!!
    }
}
Also used : HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ProcessingException(javax.ws.rs.ProcessingException) WebClient(org.apache.cxf.jaxrs.client.WebClient) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration) Test(org.junit.Test)

Example 65 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class JavaFirstSchemaValidationTest method createClient.

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;
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client)

Aggregations

HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)78 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)53 Client (org.apache.cxf.endpoint.Client)31 Test (org.junit.Test)27 URL (java.net.URL)12 Bus (org.apache.cxf.Bus)10 IOException (java.io.IOException)8 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)8 WebClient (org.apache.cxf.jaxrs.client.WebClient)7 ClientPolicyCalculator (org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator)7 QName (javax.xml.namespace.QName)6 ProxyAuthorizationPolicy (org.apache.cxf.configuration.security.ProxyAuthorizationPolicy)6 ClientConfiguration (org.apache.cxf.jaxrs.client.ClientConfiguration)6 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)5 Greeter (org.apache.hello_world.Greeter)5 SOAPService (org.apache.hello_world.services.SOAPService)5 Map (java.util.Map)4 BindingProvider (javax.xml.ws.BindingProvider)4 Endpoint (org.apache.cxf.endpoint.Endpoint)4 HashMap (java.util.HashMap)3