Search in sources :

Example 1 with UseThreadBusFeature

use of org.jboss.wsf.stack.cxf.client.UseThreadBusFeature in project jbossws-cxf by jbossws.

the class ClientServerLifeCycleTestCase method testCustomClientLifeCycleListener.

@Test
@RunAsClient
public void testCustomClientLifeCycleListener() throws Exception {
    Bus bus = BusFactory.newInstance().createBus();
    BusFactory.setThreadDefaultBus(bus);
    try {
        URL wsdlOneURL = new URL(baseURL + "/ServiceOne/EndpointOne?wsdl");
        QName serviceOneName = new QName("http://org.jboss.ws.jaxws.cxf/jbws3098", "ServiceOne");
        Service serviceOne = Service.create(wsdlOneURL, serviceOneName, new UseThreadBusFeature());
        CustomClientLifeCycleListener listener = new CustomClientLifeCycleListener();
        ClientLifeCycleManager mgr = bus.getExtension(ClientLifeCycleManager.class);
        try {
            mgr.registerListener(listener);
            assertEquals(0, listener.getCount());
            EndpointOne portOne = (EndpointOne) serviceOne.getPort(EndpointOne.class);
            assertEquals(1, listener.getCount());
            assertEquals("Foo", portOne.echo("Foo"));
        } finally {
            mgr.unRegisterListener(listener);
        }
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) UseThreadBusFeature(org.jboss.wsf.stack.cxf.client.UseThreadBusFeature) QName(javax.xml.namespace.QName) ClientLifeCycleManager(org.apache.cxf.endpoint.ClientLifeCycleManager) 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 2 with UseThreadBusFeature

use of org.jboss.wsf.stack.cxf.client.UseThreadBusFeature 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 3 with UseThreadBusFeature

use of org.jboss.wsf.stack.cxf.client.UseThreadBusFeature in project jbossws-cxf by jbossws.

the class PolicyAttachmentTestCase method testEndpointWithCustomWSSEAndWSA.

@Test
@RunAsClient
@WrapThreadContextClassLoader
public void testEndpointWithCustomWSSEAndWSA() throws Exception {
    Bus bus = BusFactory.newInstance().createBus();
    BusFactory.setThreadDefaultBus(bus);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(bos);
    try {
        bus.getInInterceptors().add(new LoggingInInterceptor(pw));
        URL wsdlURL = new URL(baseURL + "/ServiceFour?wsdl");
        QName serviceName = new QName("http://org.jboss.ws.jaxws.cxf/jbws3648", "ServiceFour");
        Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
        EndpointFour proxy = (EndpointFour) service.getPort(EndpointFour.class);
        setupWsse((BindingProvider) proxy);
        try {
            assertEquals("Foo4", proxy.echo("Foo4"));
        } catch (Exception e) {
            throw CryptoCheckHelper.checkAndWrapException(e);
        }
        final String m = bos.toString();
        assertTrue("WS-Addressing was not enabled!", m.contains("http://www.w3.org/2005/08/addressing") && m.contains("http://www.w3.org/2005/08/addressing/anonymous"));
        assertTrue("WS-Security was not enabled!", m.contains("http://www.w3.org/2001/04/xmlenc#rsa-1_5") && m.contains("http://www.w3.org/2001/04/xmlenc#aes256-cbc"));
    } finally {
        bus.shutdown(true);
        pw.close();
        bos.close();
    }
}
Also used : Bus(org.apache.cxf.Bus) UseThreadBusFeature(org.jboss.wsf.stack.cxf.client.UseThreadBusFeature) QName(javax.xml.namespace.QName) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) Service(javax.xml.ws.Service) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL) PrintWriter(java.io.PrintWriter) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest) WrapThreadContextClassLoader(org.jboss.wsf.test.WrapThreadContextClassLoader)

Example 4 with UseThreadBusFeature

use of org.jboss.wsf.stack.cxf.client.UseThreadBusFeature in project jbossws-cxf by jbossws.

the class PolicyAttachmentTestCase method testEndpointWithWSSEAndWSA.

@Test
@RunAsClient
@WrapThreadContextClassLoader
public void testEndpointWithWSSEAndWSA() throws Exception {
    Bus bus = BusFactory.newInstance().createBus();
    BusFactory.setThreadDefaultBus(bus);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(bos);
    try {
        bus.getInInterceptors().add(new LoggingInInterceptor(pw));
        URL wsdlURL = new URL(baseURL + "/ServiceThree?wsdl");
        QName serviceName = new QName("http://org.jboss.ws.jaxws.cxf/jbws3648", "ServiceThree");
        Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
        EndpointThree proxy = (EndpointThree) service.getPort(EndpointThree.class);
        setupWsse((BindingProvider) proxy);
        assertEquals("Foo3", proxy.echo("Foo3"));
        final String m = bos.toString();
        assertTrue("WS-Addressing was not enabled!", m.contains("http://www.w3.org/2005/08/addressing") && m.contains("http://www.w3.org/2005/08/addressing/anonymous"));
        assertTrue("WS-Security was not enabled!", m.contains("http://www.w3.org/2001/04/xmlenc#rsa-1_5") && m.contains("http://www.w3.org/2001/04/xmlenc#tripledes-cbc"));
    } finally {
        bus.shutdown(true);
        pw.close();
        bos.close();
    }
}
Also used : Bus(org.apache.cxf.Bus) UseThreadBusFeature(org.jboss.wsf.stack.cxf.client.UseThreadBusFeature) QName(javax.xml.namespace.QName) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) Service(javax.xml.ws.Service) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL) PrintWriter(java.io.PrintWriter) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest) WrapThreadContextClassLoader(org.jboss.wsf.test.WrapThreadContextClassLoader)

Example 5 with UseThreadBusFeature

use of org.jboss.wsf.stack.cxf.client.UseThreadBusFeature in project jbossws-cxf by jbossws.

the class Helper method testEndpoint.

public boolean testEndpoint() throws Exception {
    Bus bus = setBindingCustomizationOnClientSide();
    try {
        URL wsdlURL = new URL(endpointAddress + "?wsdl");
        QName serviceName = new QName("http://org.jboss.ws/cxf/jaxbintros", "EndpointBeanService");
        Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
        Endpoint port = service.getPort(Endpoint.class);
        UserType user = new UserType();
        QName qname = new QName("ns", "local", "prefix");
        user.setQname(qname);
        user.setString("Foo");
        UserType result = port.echo(user);
        if (!"Foo".equals(result.getString())) {
            return false;
        }
        if (!qname.equals(result.getQname())) {
            return false;
        }
    } finally {
        bus.shutdown(true);
    }
    return true;
}
Also used : Bus(org.apache.cxf.Bus) UseThreadBusFeature(org.jboss.wsf.stack.cxf.client.UseThreadBusFeature) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL)

Aggregations

UseThreadBusFeature (org.jboss.wsf.stack.cxf.client.UseThreadBusFeature)18 Service (javax.xml.ws.Service)17 URL (java.net.URL)16 QName (javax.xml.namespace.QName)16 Bus (org.apache.cxf.Bus)14 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)12 JBossWSTest (org.jboss.wsf.test.JBossWSTest)12 Test (org.junit.Test)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 PrintWriter (java.io.PrintWriter)6 LoggingInInterceptor (org.apache.cxf.interceptor.LoggingInInterceptor)6 LoggingOutInterceptor (org.apache.cxf.interceptor.LoggingOutInterceptor)3 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)3 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)3 WebServiceException (javax.xml.ws.WebServiceException)2 DigestAuthSupplier (org.apache.cxf.transport.http.auth.DigestAuthSupplier)2 WrapThreadContextClassLoader (org.jboss.wsf.test.WrapThreadContextClassLoader)2 OutputStream (java.io.OutputStream)1 MalformedURLException (java.net.MalformedURLException)1 SocketTimeoutException (java.net.SocketTimeoutException)1