Search in sources :

Example 31 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class SpringBeansTest method testClientFromFactory.

@Test
public void testClientFromFactory() throws Exception {
    AbstractFactoryBeanDefinitionParser.setFactoriesAreAbstract(false);
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/jaxws/spring/clients.xml" });
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    Greeter g = factory.create(Greeter.class);
    ClientImpl c = (ClientImpl) ClientProxy.getClient(g);
    for (Interceptor<? extends Message> i : c.getInInterceptors()) {
        if (i instanceof LoggingInInterceptor) {
            ctx.close();
            return;
        }
    }
    ctx.close();
    fail("Did not configure the client");
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Greeter(org.apache.hello_world_soap_http.Greeter) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) ClientImpl(org.apache.cxf.endpoint.ClientImpl) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Test(org.junit.Test)

Example 32 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class SpringBeansTest method testClients.

@Test
public void testClients() throws Exception {
    AbstractFactoryBeanDefinitionParser.setFactoriesAreAbstract(false);
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/jaxws/spring/clients.xml" });
    ClientHolderBean greeters = (ClientHolderBean) ctx.getBean("greeters");
    assertEquals(4, greeters.greeterCount());
    Object bean = ctx.getBean("client1.proxyFactory");
    assertNotNull(bean);
    Greeter greeter = (Greeter) ctx.getBean("client1");
    Greeter greeter2 = (Greeter) ctx.getBean("client1");
    assertNotNull(greeter);
    assertNotNull(greeter2);
    assertSame(greeter, greeter2);
    Client client = ClientProxy.getClient(greeter);
    assertNotNull("expected ConduitSelector", client.getConduitSelector());
    assertTrue("unexpected ConduitSelector", client.getConduitSelector() instanceof NullConduitSelector);
    List<Interceptor<? extends Message>> inInterceptors = client.getInInterceptors();
    boolean saaj = false;
    boolean logging = false;
    for (Interceptor<? extends Message> i : inInterceptors) {
        if (i instanceof SAAJInInterceptor) {
            saaj = true;
        } else if (i instanceof LoggingInInterceptor) {
            logging = true;
        }
    }
    assertTrue(saaj);
    assertTrue(logging);
    saaj = false;
    logging = false;
    for (Interceptor<?> i : client.getOutInterceptors()) {
        if (i instanceof SAAJOutInterceptor) {
            saaj = true;
        } else if (i instanceof LoggingOutInterceptor) {
            logging = true;
        }
    }
    assertTrue(saaj);
    assertTrue(logging);
    assertTrue(client.getEndpoint().getService().getDataBinding() instanceof SourceDataBinding);
    JaxWsProxyFactoryBean factory = (JaxWsProxyFactoryBean) ctx.getBean("wsdlLocation.proxyFactory");
    assertNotNull(factory);
    String wsdlLocation = factory.getWsdlLocation();
    assertEquals("We should get the right wsdl location", wsdlLocation, "wsdl/hello_world.wsdl");
    factory = (JaxWsProxyFactoryBean) ctx.getBean("inlineSoapBinding.proxyFactory");
    assertNotNull(factory);
    BindingConfiguration bc = factory.getBindingConfig();
    assertTrue(bc instanceof SoapBindingConfiguration);
    SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
    assertTrue(sbc.getVersion() instanceof Soap12);
    assertTrue("the soap configure should set isMtomEnabled to be true", sbc.isMtomEnabled());
    Greeter g1 = greeters.getGreet1();
    Greeter g2 = greeters.getGreet2();
    assertNotSame(g1, g2);
    ctx.close();
}
Also used : SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) Soap12(org.apache.cxf.binding.soap.Soap12) Message(org.apache.cxf.message.Message) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) NullConduitSelector(org.apache.cxf.endpoint.NullConduitSelector) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Greeter(org.apache.hello_world_soap_http.Greeter) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) BindingConfiguration(org.apache.cxf.binding.BindingConfiguration) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) Test(org.junit.Test)

Example 33 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class JaxWsClientThreadTest method testRequestContextThreadSafety.

@Test
public void testRequestContextThreadSafety() throws Throwable {
    URL url = getClass().getResource("/wsdl/hello_world.wsdl");
    javax.xml.ws.Service s = javax.xml.ws.Service.create(url, serviceName);
    final Greeter greeter = s.getPort(portName, Greeter.class);
    final InvocationHandler handler = Proxy.getInvocationHandler(greeter);
    ((BindingProvider) handler).getRequestContext().put(JaxWsClientProxy.THREAD_LOCAL_REQUEST_CONTEXT, Boolean.TRUE);
    Map<String, Object> requestContext = ((BindingProvider) handler).getRequestContext();
    String address = (String) requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
    final Throwable[] errorHolder = new Throwable[1];
    Runnable r = new Runnable() {

        public void run() {
            try {
                final String protocol = "http-" + Thread.currentThread().getId();
                for (int i = 0; i < 10; i++) {
                    String threadSpecificaddress = protocol + "://localhost:80/" + i;
                    Map<String, Object> requestContext = ((BindingProvider) handler).getRequestContext();
                    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, threadSpecificaddress);
                    assertEquals("we get what we set", threadSpecificaddress, requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY));
                    try {
                        greeter.greetMe("Hi");
                    } catch (WebServiceException expected) {
                        // expected.getCause().printStackTrace();
                        MalformedURLException mue = (MalformedURLException) expected.getCause();
                        if (mue == null || mue.getMessage() == null) {
                            throw expected;
                        }
                        assertTrue("protocol contains thread id from context", mue.getMessage().indexOf(protocol) != 0);
                    }
                    requestContext.remove(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
                    assertTrue("property is null", requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY) == null);
                }
            } catch (Throwable t) {
                // capture assert failures
                errorHolder[0] = t;
            }
        }
    };
    final int numThreads = 5;
    Thread[] threads = new Thread[numThreads];
    for (int i = 0; i < numThreads; i++) {
        threads[i] = new Thread(r);
    }
    for (int i = 0; i < numThreads; i++) {
        threads[i].start();
    }
    for (int i = 0; i < numThreads; i++) {
        threads[i].join();
    }
    if (errorHolder[0] != null) {
        throw errorHolder[0];
    }
    // main thread contextValues are un changed
    assertTrue("address from existing context has not changed", address.equals(requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY)));
    // get the latest values
    ((ClientImpl.EchoContext) ((WrappedMessageContext) requestContext).getWrappedMap()).reload();
    assertTrue("address is different", !address.equals(requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY)));
    // verify value reflects what other threads were doing
    assertTrue("property is null from last thread execution", requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY) == null);
}
Also used : MalformedURLException(java.net.MalformedURLException) WebServiceException(javax.xml.ws.WebServiceException) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) InvocationHandler(java.lang.reflect.InvocationHandler) URL(java.net.URL) Greeter(org.apache.hello_world_soap_http.Greeter) Test(org.junit.Test) AbstractCXFTest(org.apache.cxf.test.AbstractCXFTest)

Example 34 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class ClientServerWebSocketTest method testTimeoutConfigutation.

@Test
public void testTimeoutConfigutation() throws Exception {
    SOAPService service = new SOAPService();
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateGreeterAddress(greeter, PORT);
    ((javax.xml.ws.BindingProvider) greeter).getRequestContext().put("javax.xml.ws.client.receiveTimeout", "1");
    try {
        greeter.greetMe("test");
    // remove fail() check to let this test pass in the powerful machine
    } catch (Throwable ex) {
        Object cause = null;
        if (ex.getCause() != null) {
            cause = ex.getCause();
        }
        assertTrue("Timeout cause is expected", cause instanceof java.net.SocketTimeoutException);
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Greeter(org.apache.hello_world_soap_http.Greeter) Test(org.junit.Test)

Example 35 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class ClientServerWebSocketTest method testFaults.

@Test
public void testFaults() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    ExecutorService ex = Executors.newFixedThreadPool(1);
    service.setExecutor(ex);
    assertNotNull(service);
    String noSuchCodeFault = "NoSuchCodeLitFault";
    String badRecordFault = "BadRecordLitFault";
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateGreeterAddress(greeter, PORT);
    for (int idx = 0; idx < 2; idx++) {
        try {
            greeter.testDocLitFault(noSuchCodeFault);
            fail("Should have thrown NoSuchCodeLitFault exception");
        } catch (NoSuchCodeLitFault nslf) {
            assertNotNull(nslf.getFaultInfo());
            assertNotNull(nslf.getFaultInfo().getCode());
        }
        try {
            greeter.testDocLitFault(badRecordFault);
            fail("Should have thrown BadRecordLitFault exception");
        } catch (BadRecordLitFault brlf) {
            BindingProvider bp = (BindingProvider) greeter;
            Map<String, Object> responseContext = bp.getResponseContext();
            String contentType = (String) responseContext.get(Message.CONTENT_TYPE);
            assertEquals("text/xml; charset=utf-8", contentType.toLowerCase());
            Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
            assertEquals(500, responseCode.intValue());
            assertNotNull(brlf.getFaultInfo());
            assertEquals("BadRecordLitFault", brlf.getFaultInfo());
        }
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault) NoSuchCodeLitFault(org.apache.hello_world_soap_http.NoSuchCodeLitFault) Greeter(org.apache.hello_world_soap_http.Greeter) ExecutorService(java.util.concurrent.ExecutorService) BindingProvider(javax.xml.ws.BindingProvider) Map(java.util.Map) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Greeter (org.apache.hello_world_soap_http.Greeter)104 Test (org.junit.Test)78 SOAPService (org.apache.hello_world_soap_http.SOAPService)55 URL (java.net.URL)47 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)24 BindingProvider (javax.xml.ws.BindingProvider)23 SOAPServiceBogusAddressTest (org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest)21 SOAPServiceMultiPortTypeTest (org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest)21 Service (javax.xml.ws.Service)19 Client (org.apache.cxf.endpoint.Client)17 Endpoint (javax.xml.ws.Endpoint)13 QName (javax.xml.namespace.QName)10 Bus (org.apache.cxf.Bus)10 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)10 ExecutorService (java.util.concurrent.ExecutorService)9 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)7 File (java.io.File)6 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)6 GreetMeLaterResponse (org.apache.hello_world_soap_http.types.GreetMeLaterResponse)6 InvocationHandler (java.lang.reflect.InvocationHandler)5