Search in sources :

Example 1 with GetPersonResponse

use of org.apache.camel.non_wrapper.types.GetPersonResponse in project camel by apache.

the class PersonProcessor method process.

public void process(Exchange exchange) throws Exception {
    LOG.info("processing exchange in camel");
    BindingOperationInfo boi = (BindingOperationInfo) exchange.getProperty(BindingOperationInfo.class.getName());
    if (boi != null) {
        LOG.info("boi.isUnwrapped" + boi.isUnwrapped());
    }
    GetPerson person = exchange.getIn().getBody(GetPerson.class);
    String personId = person.getPersonId();
    GetPersonResponse response = new GetPersonResponse();
    if (personId == null || personId.length() == 0) {
        LOG.info("person id 123, so throwing exception");
        // Try to throw out the soap fault message
        org.apache.camel.non_wrapper.types.UnknownPersonFault personFault = new org.apache.camel.non_wrapper.types.UnknownPersonFault();
        personFault.setPersonId("");
        org.apache.camel.non_wrapper.UnknownPersonFault fault = new org.apache.camel.non_wrapper.UnknownPersonFault("Get the null value of person name", personFault);
        // Since camel has its own exception handler framework, we can't throw the exception to trigger it
        // We just set the fault message in the exchange for camel-cxf component handling and return
        exchange.getOut().setFault(true);
        exchange.getOut().setBody(fault);
        return;
    }
    response.setPersonId(personId);
    response.setName("Bonjour");
    response.setSsn("123");
    LOG.info("setting Bonjour as the response");
    // Set the response message, first element is the return value of the operation,
    // the others are the holders of method parameters
    exchange.getOut().setBody(new Object[] { response });
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) GetPersonResponse(org.apache.camel.non_wrapper.types.GetPersonResponse) GetPerson(org.apache.camel.non_wrapper.types.GetPerson)

Example 2 with GetPersonResponse

use of org.apache.camel.non_wrapper.types.GetPersonResponse in project camel by apache.

the class PayLoadConvertToPOJOTest method testClient.

@Test
public void testClient() throws Exception {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setAddress("http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/CamelContext/RouterPort");
    factory.setServiceClass(Person.class);
    Person person = factory.create(Person.class);
    GetPerson payload = new GetPerson();
    payload.setPersonId("1234");
    GetPersonResponse reply = person.getPerson(payload);
    assertEquals("Get the wrong person id.", "1234", reply.getPersonId());
}
Also used : GetPersonResponse(org.apache.camel.non_wrapper.types.GetPersonResponse) GetPerson(org.apache.camel.non_wrapper.types.GetPerson) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) GetPerson(org.apache.camel.non_wrapper.types.GetPerson) Person(org.apache.camel.non_wrapper.Person) Test(org.junit.Test)

Example 3 with GetPersonResponse

use of org.apache.camel.non_wrapper.types.GetPersonResponse in project camel by apache.

the class TestCamel1145Route method testCamel1145Route.

@Test
public void testCamel1145Route() throws Exception {
    URL wsdlURL = new URL("http://localhost:9000/PersonService/?wsdl");
    PersonService ss = new PersonService(wsdlURL, new QName("http://camel.apache.org/non-wrapper", "PersonService"));
    Person client = ss.getSoap();
    GetPerson request = new GetPerson();
    request.setPersonId("hello");
    GetPersonResponse response = client.getPerson(request);
    assertEquals("we should get the right answer from router", "Bill", response.getName());
    assertEquals("we should get the right answer from router", "Test", response.getSsn());
    assertEquals("we should get the right answer from router", "hello world!", response.getPersonId());
}
Also used : GetPersonResponse(org.apache.camel.non_wrapper.types.GetPersonResponse) QName(javax.xml.namespace.QName) PersonService(org.apache.camel.non_wrapper.PersonService) GetPerson(org.apache.camel.non_wrapper.types.GetPerson) GetPerson(org.apache.camel.non_wrapper.types.GetPerson) Person(org.apache.camel.non_wrapper.Person) URL(java.net.URL) Test(org.junit.Test)

Example 4 with GetPersonResponse

use of org.apache.camel.non_wrapper.types.GetPersonResponse in project camel by apache.

the class CxfNonWrapperTest method testInvokingServiceFromCXFClient.

@Test
public void testInvokingServiceFromCXFClient() throws Exception {
    URL wsdlURL = getClass().getClassLoader().getResource("person-non-wrapper.wsdl");
    PersonService ss = new PersonService(wsdlURL, new QName("http://camel.apache.org/non-wrapper", "PersonService"));
    Person client = ss.getSoap();
    ((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + port1 + "/CxfNonWrapperTest/PersonService/");
    GetPerson request = new GetPerson();
    request.setPersonId("hello");
    GetPersonResponse response = client.getPerson(request);
    assertEquals("we should get the right answer from router", "Bonjour", response.getName());
    request.setPersonId("");
    try {
        client.getPerson(request);
        fail("We expect to get the UnknowPersonFault here");
    } catch (UnknownPersonFault fault) {
    // We expect to get fault here
    }
}
Also used : GetPersonResponse(org.apache.camel.non_wrapper.types.GetPersonResponse) UnknownPersonFault(org.apache.camel.non_wrapper.UnknownPersonFault) QName(javax.xml.namespace.QName) PersonService(org.apache.camel.non_wrapper.PersonService) GetPerson(org.apache.camel.non_wrapper.types.GetPerson) GetPerson(org.apache.camel.non_wrapper.types.GetPerson) Person(org.apache.camel.non_wrapper.Person) URL(java.net.URL) Test(org.junit.Test)

Aggregations

GetPerson (org.apache.camel.non_wrapper.types.GetPerson)4 GetPersonResponse (org.apache.camel.non_wrapper.types.GetPersonResponse)4 Person (org.apache.camel.non_wrapper.Person)3 Test (org.junit.Test)3 URL (java.net.URL)2 QName (javax.xml.namespace.QName)2 PersonService (org.apache.camel.non_wrapper.PersonService)2 UnknownPersonFault (org.apache.camel.non_wrapper.UnknownPersonFault)1 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1