Search in sources :

Example 6 with UseThreadBusFeature

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

the class Helper method getPort.

private HelloWorld getPort(WebServiceFeature... features) throws MalformedURLException {
    URL wsdlURL = new URL(gzipFeatureEndpointURL + "?wsdl");
    QName serviceName = new QName("http://org.jboss.ws/jaxws/cxf/jbws3879", "HelloWorldService");
    Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
    QName portQName = new QName("http://org.jboss.ws/jaxws/cxf/jbws3879", "HelloWorldImplPort");
    return (HelloWorld) service.getPort(portQName, HelloWorld.class, features);
}
Also used : UseThreadBusFeature(org.jboss.wsf.stack.cxf.client.UseThreadBusFeature) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL)

Example 7 with UseThreadBusFeature

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

the class MessageLoggingTestCase method testClientLogging.

@Test
@RunAsClient
public void testClientLogging() throws Exception {
    URL wsdlURL = new URL(baseURL + "/jaxws-cxf-logging/LoggingFeatureService/LoggingFeatureEndpoint?wsdl");
    QName serviceName = new QName("http://logging.cxf.jaxws.ws.test.jboss.org/", "LoggingFeatureService");
    Bus bus = BusFactory.newInstance().createBus();
    try {
        // install the a LoggingInInterceptor in the bus used for the client
        LoggingInInterceptor myLoggingInterceptor = new LoggingInInterceptor();
        OutputStream out = new ByteArrayOutputStream();
        myLoggingInterceptor.setPrintWriter(new PrintWriter(out, true));
        bus.getInInterceptors().add(myLoggingInterceptor);
        BusFactory.setThreadDefaultBus(bus);
        Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
        QName portQName = new QName("http://logging.cxf.jaxws.ws.test.jboss.org/", "LoggingFeatureEndpointPort");
        LoggingEndpoint port = (LoggingEndpoint) service.getPort(portQName, LoggingEndpoint.class);
        String content = "foo";
        port.echo(content);
        String s = out.toString();
        assertTrue("'" + content + "' not found in captured message: \n" + s, s.contains(content));
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) UseThreadBusFeature(org.jboss.wsf.stack.cxf.client.UseThreadBusFeature) QName(javax.xml.namespace.QName) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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)

Example 8 with UseThreadBusFeature

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

the class CXFServiceObjectFactoryJAXWS method instantiateService.

private Service instantiateService(final UnifiedServiceRefMetaData serviceRefMD, final Class<?> serviceClass) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, WSFException {
    final List<WebServiceFeature> featuresList = getFeatures(serviceRefMD);
    // force THREAD_BUS strategy so that the bus created before for this specific ref is used
    if (!ClientBusSelector.getDefaultStrategy().equals(Constants.THREAD_BUS_STRATEGY)) {
        featuresList.add(new UseThreadBusFeature());
    }
    final WebServiceFeature[] features = featuresList.size() == 0 ? null : featuresList.toArray(new WebServiceFeature[] {});
    final QName serviceQName = this.getServiceQName(serviceRefMD, serviceClass);
    URL wsdlURL = this.getWsdlURL(serviceRefMD, serviceClass);
    if (wsdlURL == null) {
        final String deployedServiceAddress = serviceRefMD.getDeployedServiceAddress(serviceQName);
        if (deployedServiceAddress != null) {
            try {
                wsdlURL = new URL(deployedServiceAddress + "?wsdl");
            } catch (MalformedURLException e) {
                // ignore
                Logger.getLogger(CXFServiceObjectFactoryJAXWS.class).trace(e);
            }
        }
    }
    Service target = null;
    if (serviceClass == Service.class) {
        // Generic javax.xml.ws.Service
        if (wsdlURL != null) {
            if (features != null) {
                target = Service.create(wsdlURL, serviceQName, features);
            } else {
                target = Service.create(wsdlURL, serviceQName);
            }
        } else {
            throw Messages.MESSAGES.cannotCreateServiceWithoutWsdlLocation(serviceRefMD);
        }
    } else {
        // Generated javax.xml.ws.Service subclass
        if (wsdlURL != null) {
            if (features != null) {
                try {
                    Constructor<?> ctor = serviceClass.getConstructor(new Class[] { URL.class, QName.class, WebServiceFeature[].class });
                    target = (Service) ctor.newInstance(new Object[] { wsdlURL, serviceQName, features });
                } catch (NoSuchMethodException nsme) {
                    throw org.jboss.wsf.stack.cxf.Messages.MESSAGES.missingJAXWS22ServiceConstructor(serviceClass.getName(), nsme);
                }
            } else {
                Constructor<?> ctor = serviceClass.getConstructor(new Class[] { URL.class, QName.class });
                target = (Service) ctor.newInstance(new Object[] { wsdlURL, serviceQName });
            }
        } else {
            if (features != null) {
                try {
                    Constructor<?> ctor = serviceClass.getConstructor(new Class[] { WebServiceFeature[].class });
                    target = (Service) ctor.newInstance(new Object[] { features });
                } catch (NoSuchMethodException nsme) {
                    throw org.jboss.wsf.stack.cxf.Messages.MESSAGES.missingJAXWS22ServiceConstructor(serviceClass.getName(), nsme);
                }
            } else {
                target = (Service) serviceClass.newInstance();
            }
        }
    }
    return target;
}
Also used : MalformedURLException(java.net.MalformedURLException) UseThreadBusFeature(org.jboss.wsf.stack.cxf.client.UseThreadBusFeature) QName(javax.xml.namespace.QName) WebServiceFeature(javax.xml.ws.WebServiceFeature) Service(javax.xml.ws.Service) URL(java.net.URL)

Example 9 with UseThreadBusFeature

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

the class BusTestCase method testReuse.

@Test
@RunAsClient
@OperateOnDeployment(WSDL_SERVER)
public void testReuse() throws Exception {
    // odd wsdl GETs return WSDL doc with invalid soap:address
    // even wsdl GETs return WSDL doc with valid soap:address
    // invalid
    final String wsdl1 = readWsdl(baseURL);
    // valid
    final String wsdl2 = readWsdl(baseURL);
    // invalid
    final String wsdl3 = readWsdl(baseURL);
    // valid
    final String wsdl4 = readWsdl(baseURL);
    assertEquals(wsdl1, wsdl3);
    assertEquals(wsdl2, wsdl4);
    assertFalse(wsdl1.equals(wsdl2));
    Bus bus = BusFactory.newInstance().createBus();
    try {
        BusFactory.setThreadDefaultBus(bus);
        // invalid
        Endpoint port = getPort(baseURL, bus, new UseThreadBusFeature());
        try {
            performInvocation(port);
            fail("Failure expected, as the wsdl soap:address is not valid!");
        } catch (WebServiceException wse) {
            assertTrue(wse.getCause().getMessage().contains("InvalidEndpoint"));
        }
        // valid
        port = getPort(baseURL, bus, new UseNewBusFeature());
        // the port should now actually be built against the valid wsdl
        // as a new bus should have been started (with a new WSDLManager)
        // so the invocation is expected to succeed
        performInvocation(port);
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) WebServiceException(javax.xml.ws.WebServiceException) UseThreadBusFeature(org.jboss.wsf.stack.cxf.client.UseThreadBusFeature) UseNewBusFeature(org.jboss.wsf.stack.cxf.client.UseNewBusFeature) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 10 with UseThreadBusFeature

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

the class FastInfosetTestCase method testInfosetUsingFastInfosetAnnotation.

@Test
@RunAsClient
@OperateOnDeployment(DEP1)
public void testInfosetUsingFastInfosetAnnotation() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ByteArrayOutputStream in = new ByteArrayOutputStream();
    PrintWriter pwIn = new PrintWriter(in);
    PrintWriter pwOut = new PrintWriter(out);
    Bus bus = BusFactory.newInstance().createBus();
    BusFactory.setThreadDefaultBus(bus);
    try {
        bus.getInInterceptors().add(new LoggingInInterceptor(pwIn));
        bus.getOutInterceptors().add(new LoggingOutInterceptor(pwOut));
        URL wsdlURL = new URL(baseURL + "HelloWorldService/HelloWorldFIImpl?wsdl");
        QName serviceName = new QName("http://org.jboss.ws/jaxws/cxf/fastinfoset", "HelloWorldFIService");
        Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
        QName portQName = new QName("http://org.jboss.ws/jaxws/cxf/fastinfoset", "HelloWorldFIImplPort");
        HelloWorldFI port = (HelloWorldFI) service.getPort(portQName, HelloWorldFI.class);
        assertEquals("helloworld", port.echo("helloworld"));
        assertTrue("request is expected fastinfoset", out.toString().indexOf("application/fastinfoset") > -1);
        assertTrue("response is expected fastinfoset", in.toString().indexOf("application/fastinfoset") > -1);
    } finally {
        bus.shutdown(true);
        pwOut.close();
        pwIn.close();
    }
}
Also used : Bus(org.apache.cxf.Bus) UseThreadBusFeature(org.jboss.wsf.stack.cxf.client.UseThreadBusFeature) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) 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) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

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