Search in sources :

Example 1 with Greeter

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

the class CamelTransportClientServerTest method testClientInvocation.

@Test
public void testClientInvocation() throws MalformedURLException {
    Client client = new Client("http://localhost:" + port + "/GreeterContext/GreeterPort");
    Greeter port = client.getProxy();
    assertNotNull("The proxy should not be null", port);
    String resp = port.sayHi();
    assertEquals("Get a wrong response ", "Bonjour from EndpointA", resp);
    resp = port.sayHi();
    assertEquals("Get a wrong response ", "Bonjour from EndpointB", resp);
    resp = port.greetMe("Mike");
    assertEquals("Get a wrong response ", "Hello Mike from EndpointA", resp);
    resp = port.greetMe("James");
    assertEquals("Get a wrong response ", "Hello James from EndpointB", resp);
    port.greetMeOneWay(System.getProperty("user.name"));
    try {
        port.pingMe("hello");
        fail("exception expected but none thrown");
    } catch (PingMeFault ex) {
        assertEquals("Wrong exception message received", "PingMeFault raised by server EndpointB", ex.getMessage());
        FaultDetail detail = ex.getFaultInfo();
        assertEquals("Wrong FaultDetail major:", 2, detail.getMajor());
        assertEquals("Wrong FaultDetail minor:", 1, detail.getMinor());
    }
}
Also used : PingMeFault(org.apache.hello_world_soap_http.PingMeFault) Greeter(org.apache.hello_world_soap_http.Greeter) FaultDetail(org.apache.hello_world_soap_http.types.FaultDetail) Test(org.junit.Test)

Example 2 with Greeter

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

the class Client method invoke.

public void invoke() throws Exception {
    System.out.println("Acquiring router port ...");
    Greeter port = getProxy();
    String resp;
    System.out.println("Invoking sayHi...");
    resp = port.sayHi();
    System.out.println("Server responded with: " + resp);
    System.out.println();
    System.out.println("Invoking greetMe...");
    resp = port.greetMe(System.getProperty("user.name"));
    System.out.println("Server responded with: " + resp);
    System.out.println();
    System.out.println("Invoking greetMeOneWay...");
    port.greetMeOneWay(System.getProperty("user.name"));
    System.out.println("No response from server as method is OneWay");
    System.out.println();
    try {
        System.out.println("Invoking pingMe, expecting exception...");
        port.pingMe("hello");
    } catch (PingMeFault ex) {
        System.out.println("Expected exception: PingMeFault has occurred: " + ex.getMessage());
        FaultDetail detail = ex.getFaultInfo();
        System.out.println("FaultDetail major:" + detail.getMajor());
        System.out.println("FaultDetail minor:" + detail.getMinor());
    }
}
Also used : PingMeFault(org.apache.hello_world_soap_http.PingMeFault) Greeter(org.apache.hello_world_soap_http.Greeter) FaultDetail(org.apache.hello_world_soap_http.types.FaultDetail)

Example 3 with Greeter

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

the class CxfConsumerWSRMTest method testInvokeGreeter.

@Test
public void testInvokeGreeter() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    Bus clientBus = context.getRegistry().lookupByNameAndType("client-bus", Bus.class);
    assertNotNull(clientBus);
    BusFactory.setThreadDefaultBus(clientBus);
    try {
        Service service = Service.create(SERVICE_NAME);
        service.addPort(PORT_NAME, "http://schemas.xmlsoap.org/soap/", "http://localhost:" + CXFTestSupport.getPort1() + "/CxfConsumerWSRMTest/router");
        Greeter greeter = service.getPort(PORT_NAME, Greeter.class);
        greeter.greetMeOneWay("test");
    } finally {
        BusFactory.setThreadDefaultBus(null);
    }
    assertMockEndpointsSatisfied();
}
Also used : Bus(org.apache.cxf.Bus) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Greeter(org.apache.hello_world_soap_http.Greeter) Service(javax.xml.ws.Service) Test(org.junit.Test)

Example 4 with Greeter

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

the class GreeterClientTest method sendMessageWithUsernameToken.

protected String sendMessageWithUsernameToken(String username, String password, String message) throws Exception {
    final javax.xml.ws.Service svc = javax.xml.ws.Service.create(WSDL_LOC, SERVICE_QNAME);
    final Greeter greeter = svc.getPort(PORT_QNAME, Greeter.class);
    Client client = ClientProxy.getClient(greeter);
    Map<String, Object> props = new HashMap<String, Object>();
    props.put("action", "UsernameToken");
    props.put("user", username);
    // Set the the password type to be plain text, 
    // so we can keep using the password to authenticate with spring security
    props.put("passwordType", "PasswordText");
    WSS4JOutInterceptor wss4jOut = new WSS4JOutInterceptor(props);
    client.getOutInterceptors().add(wss4jOut);
    ((BindingProvider) greeter).getRequestContext().put("password", password);
    return greeter.greetMe(message);
}
Also used : HashMap(java.util.HashMap) Greeter(org.apache.hello_world_soap_http.Greeter) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client)

Example 5 with Greeter

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

the class WSAddressingTest method testWSAddressing.

@Test
public void testWSAddressing() throws Exception {
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(getClientAddress());
    clientBean.setServiceClass(Greeter.class);
    SpringBusFactory bf = new SpringBusFactory();
    URL cxfConfig = null;
    if (getCxfClientConfig() != null) {
        cxfConfig = ClassLoaderUtils.getResource(getCxfClientConfig(), this.getClass());
    }
    proxyFactory.setBus(bf.createBus(cxfConfig));
    Greeter client = (Greeter) proxyFactory.create();
    String result = client.greetMe("world!");
    assertEquals("Get a wrong response", "Hello world!", result);
}
Also used : SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) Greeter(org.apache.hello_world_soap_http.Greeter) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) 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