Search in sources :

Example 51 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project jbossws-cxf by jbossws.

the class Helper method testFailureGZIPServerSideOnlyInterceptorOnClient.

public boolean testFailureGZIPServerSideOnlyInterceptorOnClient() throws Exception {
    HelloWorld port = getPort();
    Client client = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();
    HTTPClientPolicy policy = conduit.getClient();
    // enable Accept gzip, otherwise the server will not try to reply using gzip
    policy.setAcceptEncoding("gzip;q=1.0, identity; q=0.5, *;q=0");
    try {
        port.echo("foo");
        return false;
    } catch (Exception e) {
        // expected exception, as the client is not able to decode gzip message
        return true;
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client) MalformedURLException(java.net.MalformedURLException)

Example 52 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project jbossws-cxf by jbossws.

the class HTTPConduitTestCase method testWrapperWithMap.

@Test
@RunAsClient
public void testWrapperWithMap() throws Exception {
    Bus bus = BusFactory.newInstance().createBus();
    BusFactory.setThreadDefaultBus(bus);
    try {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(Constants.CXF_CLIENT_ALLOW_CHUNKING, true);
        map.put(Constants.CXF_CLIENT_CHUNKING_THRESHOLD, 8192);
        map.put(Constants.CXF_CLIENT_CONNECTION_TIMEOUT, 16384L);
        map.put(Constants.CXF_CLIENT_RECEIVE_TIMEOUT, 163840L);
        map.put(Constants.CXF_TLS_CLIENT_DISABLE_CN_CHECK, true);
        replaceWrapper(map, bus);
        URL wsdlURL = new URL(baseURL + "/ServiceOne" + "?wsdl");
        Service service = Service.create(wsdlURL, new QName("http://org.jboss.ws.jaxws.cxf/httpConduit", "ServiceOne"));
        EndpointOne port = service.getPort(new QName("http://org.jboss.ws.jaxws.cxf/httpConduit", "EndpointOnePort"), EndpointOne.class);
        HTTPConduit conduit = (HTTPConduit) ClientProxy.getClient(port).getConduit();
        HTTPClientPolicy client = conduit.getClient();
        assertNotNull(client);
        assertEquals(true, client.isAllowChunking());
        assertEquals(8192, client.getChunkingThreshold());
        assertEquals(16384, client.getConnectionTimeout());
        assertEquals(163840, client.getReceiveTimeout());
        assertEquals(true, conduit.getTlsClientParameters().isDisableCNCheck());
        assertEquals("Foo", port.echo("Foo"));
    } finally {
        bus.shutdown(true);
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Service(javax.xml.ws.Service) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 53 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project jbossws-cxf by jbossws.

the class HelloDigestTestCase method testDigestAuthFail.

@Test
@RunAsClient
public void testDigestAuthFail() throws Exception {
    final Bus bus = BusFactory.newInstance().createBus();
    BusFactory.setThreadDefaultBus(bus);
    try {
        QName serviceName = new QName("http://jboss.org/http/security", "HelloService");
        URL wsdlURL = getResourceURL("jaxws/cxf/httpauth/WEB-INF/wsdl/hello.wsdl");
        Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
        Hello proxy = (Hello) service.getPort(Hello.class);
        ((BindingProvider) proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, baseURL.toString());
        ((BindingProvider) proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "jbossws");
        ((BindingProvider) proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "wrongPwd");
        HTTPConduit cond = (HTTPConduit) ClientProxy.getClient(proxy).getConduit();
        cond.setAuthSupplier(new DigestAuthSupplier());
        try {
            proxy.helloRequest("number");
            fail("Authorization exception expected!");
        } catch (Exception e) {
            assertTrue(e.getCause().getMessage().contains("Authorization"));
        }
    } finally {
        bus.shutdown(true);
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Bus(org.apache.cxf.Bus) DigestAuthSupplier(org.apache.cxf.transport.http.auth.DigestAuthSupplier) UseThreadBusFeature(org.jboss.wsf.stack.cxf.client.UseThreadBusFeature) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 54 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project jbossws-cxf by jbossws.

the class HTTPProxyTestCaseForked method testHttpProxy.

@Test
@RunAsClient
public void testHttpProxy() throws Exception {
    if (checkNativeLibraries()) {
        initProxyServer();
    } else {
        return;
    }
    final String testHost = "unreachable-testHttpProxy";
    HelloWorld port = getPort(getResourceURL("jaxws/cxf/httpproxy/HelloWorldService.wsdl"), testHost);
    final String hi = "Hi!";
    // first try without setting up the proxy -> request fails because the host is not known/reachable
    try {
        port.echo(hi);
        fail("Exception expected");
    } catch (Exception e) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(baos));
        assertTrue(baos.toString().contains(testHost));
    }
    // then setup the proxy, but provide no authentication/authorization info -> request fails because of HTTP 407
    setProxySystemProperties();
    port = getPort(getResourceURL("jaxws/cxf/httpproxy/HelloWorldService.wsdl"), testHost);
    try {
        port.echo(hi);
        fail("Exception expected");
    } catch (Exception e) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(baos));
        assertTrue(baos.toString().contains("407: Proxy Authentication Required"));
    }
    // finally setup everything
    port = getPort(getResourceURL("jaxws/cxf/httpproxy/HelloWorldService.wsdl"), testHost);
    Client client = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();
    ProxyAuthorizationPolicy policy = new ProxyAuthorizationPolicy();
    policy.setAuthorizationType("Basic");
    policy.setUserName(PROXY_USER);
    policy.setPassword(PROXY_PWD);
    conduit.setProxyAuthorization(policy);
    assertEquals(hi, port.echo(hi));
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) PrintStream(java.io.PrintStream) ProxyAuthorizationPolicy(org.apache.cxf.configuration.security.ProxyAuthorizationPolicy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Client(org.apache.cxf.endpoint.Client) MalformedURLException(java.net.MalformedURLException) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 55 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project jbossws-cxf by jbossws.

the class HTTPProxyTestCaseForked method testHttpProxyUsingHTTPClientPolicy.

@Test
@RunAsClient
public void testHttpProxyUsingHTTPClientPolicy() throws Exception {
    if (checkNativeLibraries()) {
        initProxyServer();
    } else {
        return;
    }
    final String testHost = "unreachable-testHttpProxyUsingHTTPClientPolicy";
    HelloWorld port = getPort(getResourceURL("jaxws/cxf/httpproxy/HelloWorldService.wsdl"), testHost);
    final String hi = "Hi!";
    // first try without setting up the proxy -> request fails because the host is not known/reachable
    try {
        port.echo(hi);
        fail("Exception expected");
    } catch (Exception e) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(baos));
        assertTrue(baos.toString().contains(testHost));
    }
    // then setup the proxy, but provide no authentication/authorization info -> request fails because of HTTP 407
    Client client = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();
    HTTPClientPolicy clientPolicy = conduit.getClient();
    clientPolicy.setProxyServerType(ProxyServerType.HTTP);
    clientPolicy.setProxyServer(getServerHost());
    clientPolicy.setProxyServerPort(proxyPort);
    try {
        port.echo(hi);
        fail("Exception expected");
    } catch (Exception e) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(baos));
        assertTrue(baos.toString().contains("407: Proxy Authentication Required"));
    }
    // finally setup authorization info too
    ProxyAuthorizationPolicy authPolicy = new ProxyAuthorizationPolicy();
    authPolicy.setAuthorizationType("Basic");
    authPolicy.setUserName(PROXY_USER);
    authPolicy.setPassword(PROXY_PWD);
    conduit.setProxyAuthorization(authPolicy);
    assertEquals(hi, port.echo(hi));
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) PrintStream(java.io.PrintStream) ProxyAuthorizationPolicy(org.apache.cxf.configuration.security.ProxyAuthorizationPolicy) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Client(org.apache.cxf.endpoint.Client) MalformedURLException(java.net.MalformedURLException) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Aggregations

HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)125 Client (org.apache.cxf.endpoint.Client)52 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)47 Test (org.junit.Test)42 URL (java.net.URL)35 Bus (org.apache.cxf.Bus)32 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)32 QName (javax.xml.namespace.QName)22 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)20 Service (javax.xml.ws.Service)16 KeyStore (java.security.KeyStore)15 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)15 Greeter (org.apache.hello_world.Greeter)14 SOAPService (org.apache.hello_world.services.SOAPService)14 TrustManager (javax.net.ssl.TrustManager)13 IOException (java.io.IOException)12 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)11 InputStream (java.io.InputStream)8 X509TrustManager (javax.net.ssl.X509TrustManager)8 BindingProvider (javax.xml.ws.BindingProvider)8