Search in sources :

Example 1 with UnknownPersonFault

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

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

the class CxfConsumerFaultWithRouteTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() {
    final String serviceURI = "cxf://" + serviceAddress + "?" + PORT_NAME_PROP + "&" + SERVICE_NAME_PROP + "&" + WSDL_URL_PROP + "&serviceClass=org.apache.camel.wsdl_first.Person";
    return new RouteBuilder() {

        public void configure() {
            from(serviceURI).process(new Processor() {

                public void process(final Exchange exchange) throws Exception {
                    // set the fault message here
                    org.apache.camel.wsdl_first.types.UnknownPersonFault faultDetail = new org.apache.camel.wsdl_first.types.UnknownPersonFault();
                    faultDetail.setPersonId("");
                    UnknownPersonFault fault = new UnknownPersonFault("Get the null value of person name", faultDetail);
                    throw fault;
                }
            }).to("log:myfaultlog");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) UnknownPersonFault(org.apache.camel.wsdl_first.UnknownPersonFault)

Example 3 with UnknownPersonFault

use of org.apache.camel.wsdl_first.UnknownPersonFault 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 4 with UnknownPersonFault

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

the class AbstractCxfWsdlFirstTest method testInvokingServiceWithCamelProducer.

@Test
@SuppressWarnings("unchecked")
public void testInvokingServiceWithCamelProducer() throws Exception {
    Exchange exchange = sendJaxWsMessageWithHolders("hello");
    assertEquals("The request should be handled sucessfully ", exchange.isFailed(), false);
    org.apache.camel.Message out = exchange.getOut();
    List<Object> result = out.getBody(List.class);
    assertEquals("The result list should not be empty", result.size(), 4);
    Holder<String> name = (Holder<String>) result.get(3);
    assertEquals("we should get the right answer from router", "Bonjour", name.value);
    exchange = sendJaxWsMessageWithHolders("");
    assertEquals("We should get a fault here", exchange.isFailed(), true);
    Throwable ex = exchange.getException();
    assertTrue("We should get the UnknowPersonFault here", ex instanceof UnknownPersonFault);
}
Also used : Exchange(org.apache.camel.Exchange) UnknownPersonFault(org.apache.camel.wsdl_first.UnknownPersonFault) Holder(javax.xml.ws.Holder) Test(org.junit.Test)

Example 5 with UnknownPersonFault

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

UnknownPersonFault (org.apache.camel.wsdl_first.UnknownPersonFault)7 Test (org.junit.Test)6 Holder (javax.xml.ws.Holder)5 Person (org.apache.camel.wsdl_first.Person)5 URL (java.net.URL)4 PersonService (org.apache.camel.wsdl_first.PersonService)4 QName (javax.xml.namespace.QName)2 WebServiceException (javax.xml.ws.WebServiceException)2 Exchange (org.apache.camel.Exchange)2 Client (org.apache.cxf.endpoint.Client)2 LoggingInInterceptor (org.apache.cxf.interceptor.LoggingInInterceptor)2 LoggingOutInterceptor (org.apache.cxf.interceptor.LoggingOutInterceptor)2 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)1 Processor (org.apache.camel.Processor)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 JaxwsTestHandler (org.apache.camel.wsdl_first.JaxwsTestHandler)1