Search in sources :

Example 1 with JaxwsTestHandler

use of org.apache.camel.wsdl_first.JaxwsTestHandler in project camel by apache.

the class AbstractCxfWsdlFirstTest method testInvokingServiceFromCXFClient.

@Test
public void testInvokingServiceFromCXFClient() throws Exception {
    JaxwsTestHandler fromHandler = getMandatoryBean(JaxwsTestHandler.class, "fromEndpointJaxwsHandler");
    fromHandler.reset();
    JaxwsTestHandler toHandler = getMandatoryBean(JaxwsTestHandler.class, "toEndpointJaxwsHandler");
    toHandler.reset();
    URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
    PersonService ss = new PersonService(wsdlURL, new QName("http://camel.apache.org/wsdl-first", "PersonService"));
    Person client = ss.getSoap();
    ((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + getPort2() + "/" + getClass().getSimpleName() + "/PersonService/");
    Holder<String> personId = new Holder<String>();
    personId.value = "hello";
    Holder<String> ssn = new Holder<String>();
    Holder<String> name = new Holder<String>();
    client.getPerson(personId, ssn, name);
    assertEquals("we should get the right answer from router", "Bonjour", name.value);
    personId.value = "";
    try {
        client.getPerson(personId, ssn, name);
        fail("We expect to get the UnknowPersonFault here");
    } catch (UnknownPersonFault fault) {
    // We expect to get fault here
    }
    personId.value = "Invoking getPerson with invalid length string, expecting exception...xxxxxxxxx";
    try {
        client.getPerson(personId, ssn, name);
        fail("We expect to get the WebSerivceException here");
    } catch (WebServiceException ex) {
        // Caught expected WebServiceException here
        assertTrue("Should get the xml vaildate error! " + ex.getMessage(), ex.getMessage().indexOf("MyStringType") > 0 || ex.getMessage().indexOf("Could not parse the XML stream") != -1);
    }
    verifyJaxwsHandlers(fromHandler, toHandler);
}
Also used : UnknownPersonFault(org.apache.camel.wsdl_first.UnknownPersonFault) WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) PersonService(org.apache.camel.wsdl_first.PersonService) Holder(javax.xml.ws.Holder) JaxwsTestHandler(org.apache.camel.wsdl_first.JaxwsTestHandler) Person(org.apache.camel.wsdl_first.Person) URL(java.net.URL) Test(org.junit.Test)

Example 2 with JaxwsTestHandler

use of org.apache.camel.wsdl_first.JaxwsTestHandler in project camel by apache.

the class CxfSoapMessageProviderTest method testSOAPMessageModeDocLit.

@Test
public void testSOAPMessageModeDocLit() throws Exception {
    JaxwsTestHandler fromHandler = getMandatoryBean(JaxwsTestHandler.class, "fromEndpointJaxwsHandler");
    fromHandler.reset();
    QName serviceName = new QName("http://apache.org/hello_world_soap_http", "SOAPProviderService");
    QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapProviderPort");
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    String response1 = new String("TestSOAPOutputPMessage");
    String response2 = new String("Bonjour");
    try {
        Greeter greeter = service.getPort(portName, Greeter.class);
        ((BindingProvider) greeter).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + port + "/CxfSoapMessageProviderTest/SoapContext/SoapProviderPort");
        for (int idx = 0; idx < 2; idx++) {
            String greeting = greeter.greetMe("Milestone-" + idx);
            assertNotNull("no response received from service", greeting);
            assertEquals(response1, greeting);
            String reply = greeter.sayHi();
            assertNotNull("no response received from service", reply);
            assertEquals(response2, reply);
        }
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
    assertEquals("Can't get the right message count", fromHandler.getMessageCount(), 8);
    assertEquals("Can't get the right fault count", fromHandler.getFaultCount(), 0);
//From CXF 2.2.7 the soap handler's getHeader() method will not be called if the SOAP message don't have headers
//assertEquals("Can't get the right headers count", fromHandler.getGetHeadersCount(), 4);
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) QName(javax.xml.namespace.QName) Greeter(org.apache.hello_world_soap_http.Greeter) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) JaxwsTestHandler(org.apache.camel.wsdl_first.JaxwsTestHandler) URL(java.net.URL) Test(org.junit.Test)

Aggregations

URL (java.net.URL)2 QName (javax.xml.namespace.QName)2 JaxwsTestHandler (org.apache.camel.wsdl_first.JaxwsTestHandler)2 Test (org.junit.Test)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 Holder (javax.xml.ws.Holder)1 WebServiceException (javax.xml.ws.WebServiceException)1 Person (org.apache.camel.wsdl_first.Person)1 PersonService (org.apache.camel.wsdl_first.PersonService)1 UnknownPersonFault (org.apache.camel.wsdl_first.UnknownPersonFault)1 Greeter (org.apache.hello_world_soap_http.Greeter)1 SOAPService (org.apache.hello_world_soap_http.SOAPService)1