Search code examples
javaweb-servicessoapapache-camelcxf

Construct SOAP Request using SoapJaxbDataFormat marshal


Trying to construct a soap request using SoapJaxbDataFormat marshal method. Route:

private SoapJaxbDataFormat soap = new SoapJaxbDataFormat("<manage order generated package path>");

public void configure() throws Exception {
    soap.setVersion("1.2");
    from("direct:" + "invokeSoapServiceRoute")
        .process(new constructManageOrderRequestObject())
        .setHeader(Exchange.SOAP_ACTION, simple(MANAGE_ORDER_SOAP_ACTION))
        .setHeader(Exchange.HTTP_METHOD, simple(HTTP_METHOD_POST))
        .setHeader(Exchange.CONTENT_TYPE, constant("application/soap+xml;charset=UTF-8"))
        .marshal(soap) //request
        .log(LoggingLevel.DEBUG, LOG, "request ===========>${body}")
    .end();
}

constructManageOrderRequestObject processor creates the ManageOrderRequest object (class is generated from WSDL using maven during build time) and sets its all different properties (other references) and set the object to exchange body. When I'm marshalling the body using above code, it is logging the below output -

<?xml version="1.0" encoding="UTF-8"?>
<ns0:Envelope xmlns:ns0="http://www.w3.org/2003/05/soap-envelope">
   <ns0:Body>
      <ns1:manageOrderRequest xmlns:ns1="http://cap.xe.com/xsd/ManageOrder/2010/06/01">com.xe.cap.ManageOrderRequest@40c3dcba</ns1:manageOrderRequest>
   </ns0:Body>
</ns0:Envelope>

It is not converting the ManageOrderRequest object xml, rather using its object reference inside soap-body.

Can someone help me to fix this issue.


Solution

  • I found the solution:

    need to set the context path using soap.setContextPath("Package name")