Hi ,
If you just want handler the low level message such as the SOAP message
with the JAXWS Provider API, you have to follow the CXF Provider example
. In this way , CXF will set a sepecial interceptor chain (which skips
the data binding handling) for the in/out message.
In you first case, CXF will try to marshal the response message as a
float object which you set with a SOAP message. So you can't get the
right response SOAP message on your client side.
Willem.
Ian de Beer wrote:
Hi
Thanks for the replies.
When I expose the following class as a Web Service, using CXF, I can
correctly retrieve the rating using the getRating method call from a soap
client:
@WebService(serviceName = "TraderHistory", portName = "TraderHistoryPort")
@WebServiceProvider()
@ServiceMode(Service.Mode.MESSAGE)
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use =
SOAPBinding.Use.LITERAL)
public class TraderHistoryHandler implements ITraderHistory {
private EntityManagerFactory entityManagerFactory;
@WebMethod(exclude = true)
public void setEntityManagerFactory(EntityManagerFactory
entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}
@WebMethod(operationName = "getRating", action = "urn:GetRating")
@WebResult(name = "rating")
public float getTraderRating(String traderName, Integer scoreType) {
...
}
However, when I try to route the cxf service to a spring bean to do the
required processing (instead of in the implemented method itself):
from("cxf:bean:soapEndpoint")
.to("bean:messageProcessor?methodName=processMessage");
Camel do intercept the call and the processMessage method is invoked:
public SOAPMessage processMessage(Exchange exchange) {
System.out.println("PROCESSING MESSAGE...");
try {
String param1 = (String) exchange.getIn().getBody(List.class).get(0);
Integer param2 = (Integer)
exchange.getIn().getBody(List.class).get(1);
System.out.println("param1 = " + param1);
System.out.println("param2 = " + param2);
try {
return
createSoapMessage(traderHistoryHandler.getTraderRating(param1, param2));
}
catch (Exception e) {
System.out.println("ERROR2");
e.printStackTrace();
SOAPMessage msg = createSoapMessage((float) -1);
exchange.getOut().setBody(msg, SOAPMessage.class);
return msg;
}
}
catch (Exception e) {
System.out.println("ERROR1");
e.printStackTrace();
}
return null;
}
public static SOAPMessage createSoapMessage(Float value) {
try {
SOAPMessage soapMessage =
MessageFactory.newInstance().createMessage();
SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
envelope.addNamespaceDeclaration("ns1", "http://poc.tatis.com/");
envelope.addNamespaceDeclaration("wsdl",
"http://schemas.xmlsoap.org/wsdl/");
envelope.addNamespaceDeclaration("xsd",
"http://www.w3.org/2001/XMLSchema");
envelope.addNamespaceDeclaration("xsi",
"http://www.w3.org/2001/XMLSchema-instance");
envelope.addNamespaceDeclaration("soap",
"http://schemas.xmlsoap.org/soap/envelope/");
envelope.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");
SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
QName payloadName = new QName("http://poc.tatis.com/", "rating",
"ns1");
SOAPBodyElement payload = body.addBodyElement(payloadName);
payload.addTextNode(String.valueOf(value)).setAttribute("xsi:type",
"xsd:float");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
But, the soap message (as shown in the previous mail) is not routed through
to the client. No exceptions are thrown in the process.
If I strictly follows the example and implement a Provider<SOAPMessage> :
public SOAPMessage invoke(SOAPMessage soapMessage) {
throw new UnsupportedOperationException("Placeholder method");
}
then the client receives the correct message and all is well.
Regards
Ian
willem.jiang wrote:
Hi ,
Do you use the SAAJ to build up the SOAP message ?
Maybe you need to show us the codes or a small test case to let us
reproduce the error.
Willem
Ian de Beer wrote:
Hi
I have created a camel route similar to the cxf provider example. The
exchange is correctly routed to a bean that creates a SOAP message .
Before
I return the message I display it and I can verify that it contains the
correct response. However when the response message arrives back at the
SOAP
client the content of the SOAP message body has mysteriously disappeared.
I
also notice that the namespaces has changed from what I have set them to.
What I send:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://poc.tatis.com/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Header/><SOAP-ENV:Body><ns1:getRatingResponse><rating
xsi:type="xsd:float">123.11</rating></ns1:getRatingResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
What I receive:
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:getRatingResponse
xmlns:ns1="http://poc.tatis.com/"/></soap:Body></soap:Envelope>
Can someone perhaps shed some light on this behaviour.
Regards
Ian