Search in sources :

Example 1 with Person

use of org.apache.camel.wsdl_first.Person 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 Person

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

the class CXFWsdlOnlyPayloadModeNoSpringTest method testRoutes.

@Test
public void testRoutes() throws Exception {
    URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
    PersonService ss = new PersonService(wsdlURL, QName.valueOf(getServiceName()));
    Person client = ss.getSoap();
    Client c = ClientProxy.getClient(client);
    ((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + port1 + "/" + getClass().getSimpleName() + "/PersonService");
    c.getInInterceptors().add(new LoggingInInterceptor());
    c.getOutInterceptors().add(new LoggingOutInterceptor());
    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("Bonjour", name.value);
}
Also used : LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) PersonService(org.apache.camel.wsdl_first.PersonService) Holder(javax.xml.ws.Holder) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Person(org.apache.camel.wsdl_first.Person) URL(java.net.URL) Test(org.junit.Test)

Example 3 with Person

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

the class CxfConsumerPayloadFaultCauseEnabledTest method testInvokingFromCxfClient.

@Test
public void testInvokingFromCxfClient() throws Exception {
    this.getCamelContextService();
    URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
    PersonService ss = new PersonService(wsdlURL, SERVICE_QNAME);
    Person client = ss.getSoap();
    Client c = ClientProxy.getClient(client);
    c.getInInterceptors().add(new LoggingInInterceptor());
    c.getOutInterceptors().add(new LoggingOutInterceptor());
    ((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceAddress);
    Holder<String> personId = new Holder<String>();
    personId.value = "";
    Holder<String> ssn = new Holder<String>();
    Holder<String> name = new Holder<String>();
    try {
        client.getPerson(personId, ssn, name);
        fail("SOAPFault expected!");
    } catch (Exception e) {
        assertTrue(e instanceof SOAPFaultException);
        SOAPFault fault = ((SOAPFaultException) e).getFault();
        assertEquals("Someone messed up the service. Caused by: Homer", fault.getFaultString());
    }
}
Also used : LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) PersonService(org.apache.camel.wsdl_first.PersonService) Holder(javax.xml.ws.Holder) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPFault(javax.xml.soap.SOAPFault) Client(org.apache.cxf.endpoint.Client) Person(org.apache.camel.wsdl_first.Person) URL(java.net.URL) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Example 4 with Person

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

the class CxfConsumerPayloadFaultTest method testInvokingFromCxfClient.

@Test
public void testInvokingFromCxfClient() throws Exception {
    URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
    PersonService ss = new PersonService(wsdlURL, QName.valueOf(SERVICE_NAME));
    Person client = ss.getSoap();
    Client c = ClientProxy.getClient(client);
    c.getInInterceptors().add(new LoggingInInterceptor());
    c.getOutInterceptors().add(new LoggingOutInterceptor());
    ((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceAddress);
    Holder<String> personId = new Holder<String>();
    personId.value = "";
    Holder<String> ssn = new Holder<String>();
    Holder<String> name = new Holder<String>();
    Throwable t = null;
    try {
        client.getPerson(personId, ssn, name);
        fail("expect UnknownPersonFault");
    } catch (UnknownPersonFault e) {
        t = e;
        assertEquals("Get the wrong fault detail", "", e.getFaultInfo().getPersonId());
    }
    assertNotNull(t);
    assertTrue(t instanceof UnknownPersonFault);
}
Also used : UnknownPersonFault(org.apache.camel.wsdl_first.UnknownPersonFault) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) PersonService(org.apache.camel.wsdl_first.PersonService) Holder(javax.xml.ws.Holder) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Person(org.apache.camel.wsdl_first.Person) URL(java.net.URL) Test(org.junit.Test)

Example 5 with Person

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

the class CXFWsdlOnlyPayloadModeNoSpringTest method testApplicationFault.

@Test
public void testApplicationFault() {
    URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
    PersonService ss = new PersonService(wsdlURL, QName.valueOf(getServiceName()));
    Person client = ss.getSoap();
    ((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + port1 + "/" + getClass().getSimpleName() + "/PersonService");
    Client c = ClientProxy.getClient(client);
    c.getInInterceptors().add(new LoggingInInterceptor());
    c.getOutInterceptors().add(new LoggingOutInterceptor());
    Holder<String> personId = new Holder<String>();
    personId.value = "";
    Holder<String> ssn = new Holder<String>();
    Holder<String> name = new Holder<String>();
    Throwable t = null;
    try {
        client.getPerson(personId, ssn, name);
        fail("expect UnknownPersonFault");
    } catch (UnknownPersonFault e) {
        t = e;
    }
    assertNotNull(t);
    assertTrue(t instanceof UnknownPersonFault);
}
Also used : UnknownPersonFault(org.apache.camel.wsdl_first.UnknownPersonFault) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) PersonService(org.apache.camel.wsdl_first.PersonService) Holder(javax.xml.ws.Holder) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Person(org.apache.camel.wsdl_first.Person) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Person (org.apache.camel.wsdl_first.Person)8 Test (org.junit.Test)8 URL (java.net.URL)7 Holder (javax.xml.ws.Holder)7 PersonService (org.apache.camel.wsdl_first.PersonService)7 UnknownPersonFault (org.apache.camel.wsdl_first.UnknownPersonFault)5 Client (org.apache.cxf.endpoint.Client)4 LoggingInInterceptor (org.apache.cxf.interceptor.LoggingInInterceptor)4 LoggingOutInterceptor (org.apache.cxf.interceptor.LoggingOutInterceptor)4 QName (javax.xml.namespace.QName)3 WebServiceException (javax.xml.ws.WebServiceException)2 SOAPFault (javax.xml.soap.SOAPFault)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)1 JaxwsTestHandler (org.apache.camel.wsdl_first.JaxwsTestHandler)1