Search in sources :

Example 16 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 17 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 18 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 19 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)

Example 20 with HTTPConduit

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

the class Helper method testGZIPServerSideOnlyInterceptorOnClient.

public boolean testGZIPServerSideOnlyInterceptorOnClient() throws Exception {
    Bus bus = BusFactory.newInstance().createBus();
    try {
        BusFactory.setThreadDefaultBus(bus);
        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");
        // add interceptor for decoding gzip message
        ClientConfigurer configurer = ClientConfigUtil.resolveClientConfigurer();
        configurer.setConfigProperties(port, "jaxws-client-config.xml", "Interceptor Client Config");
        return ("foo".equals(port.echo("foo")));
    } finally {
        bus.shutdown(true);
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Bus(org.apache.cxf.Bus) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ClientConfigurer(org.jboss.ws.api.configuration.ClientConfigurer) Client(org.apache.cxf.endpoint.Client)

Aggregations

HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)158 Client (org.apache.cxf.endpoint.Client)65 Test (org.junit.Test)60 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)52 URL (java.net.URL)43 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)43 Bus (org.apache.cxf.Bus)36 QName (javax.xml.namespace.QName)24 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)23 KeyStore (java.security.KeyStore)21 Greeter (org.apache.hello_world.Greeter)21 SOAPService (org.apache.hello_world.services.SOAPService)21 Service (javax.xml.ws.Service)18 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)17 InputStream (java.io.InputStream)15 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)15 IOException (java.io.IOException)13 ExecutionException (java.util.concurrent.ExecutionException)13 TrustManager (javax.net.ssl.TrustManager)13 WebClient (org.apache.cxf.jaxrs.client.WebClient)11