I'd like to figure out the MessageContext solution at some point but
I haven't yet. Until then, this handler solution is working for me.
It took some time to figure it out as the xfire user doc assumes more
contextual knowledge than it should, I think, for newbies.
Regardless, I use the following handler in my xfire client to get the
incoming soap response message, strip off the soap envelope and body
elements, and then write the remaining xml to a file for later use.
public class InboundXMLFileWriterHandler extends
org.codehaus.xfire.handler.AbstractHandler {
private static final Log logger = LogFactory.getLog
(InboundXMLFileWriterHandler.class);
public void invoke(MessageContext context) throws Exception {
Document doc = (Document) context.getInMessage().getProperty
(DOMInHandler.DOM_MESSAGE);
if (doc == null) {
logger.error("DOM Document not found.");
return;
}
Element firstRoot = doc.getDocumentElement();
NodeList mylist = firstRoot.getElementsByTagName
("ns1:myQueryResponse");
Element responseElement = (Element)mylist.item(0);
FileOutputStream fos = new FileOutputStream(new File
("myresponsedoc.xml"));
DOMUtils.writeXml(responseElement, fos);
fos.flush();
fos.close();
}
To enable this handler, I added something like this to my client:
MyWSClient client = new MyWSClient();
//create a default service endpoint
MyWSPortType service = client.getMyWSHttpPort();
Client xfireClientInstance = Client.getInstance(service);
xfireClientInstance.addInHandler(new
org.codehaus.xfire.util.dom.DOMInHandler());
xfireClientInstance.addInHandler(InboundXMLFileWriterHandler());
I hope that helps,
kwade
On Jul 17, 2007, at 3:10 AM, Giulio Rizzo wrote:
Hi,
I'm new to Xfire and I can't understand how to get the
original Soap message from a request.
My problem is that I have a some classed automatically
generated from a WSDL, but the method I have only
return the object and I can't figure out how to get
the soap message.
I need it because I have to cut out the Soap envelope
and keep the original message inside. I can't rebuild
the XML from the object because the inside XML is
likely to change very quickly.
I've watched to message Context but i can't figure out
how to get it, i always get a null context.
I've tryed to use the invoke method of a Client but i
can pass the parameter only as object and the server
refuse to accept the Long object for the lonf
primitive type.
I try to use the handler with the same problem.
Can anyone help me please?
Thanks.
Giulio
___________________________________
L'email della prossima generazione? Puoi averla con la nuova Yahoo!
Mail:
http://it.docs.yahoo.com/nowyoucan.html