aspose file tools*
The moose likes Web Services and the fly likes How to get document object From SOAP Message? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to get document object From SOAP Message?" Watch "How to get document object From SOAP Message?" New topic
Author

How to get document object From SOAP Message?

chaitu sravs
Greenhorn

Joined: Oct 21, 2009
Posts: 11
I want to extract the Document object containing the SOAP XML from the below raw SOAP Message that contains an attachment. Ideally, I want to be able to load the below content into a SOAPMessage and then extract the DOM for the XML alone.



What are the options experts can hint at?
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Have you considered implementing a service endpoint implementation class that implements Provider<SOAPMessage>?
The Provider interface is located in the javax.xml.ws package - see the JDK 1.6 API documentation for more information!
In its invoke-method, you would then receive a SOAPMessage object, which you can manipulate and extract information from using SAAJ.
If you want to extract the raw XML before the request reaches the web service, I suggest using a handler.
Best wishes!
chinni nani
Greenhorn

Joined: Jun 26, 2009
Posts: 3
Good to know. But the problem is the suggested options can work only during communication.

I want to be able to process it offline in a standalone program. No client/endpoint involved, just a file with the content posted previously.

Very nice problem here:

1. I tried loading the content into an inputstream and was able to create a SOAPMessage.

2. I tried several ways to get a DocumentTraversal object from the SOAPMessage (its SOAPPart etc).

3. It looks like there is no way I can get a DocumentTraversal enabled Document object from a SOAPMessage's SOAPPart.

Is there any?

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Ah, you said nothing about reading a message from a file in your original post.
First you read the entire file and separate the MIME parts from the SOAP message. For each of the MIME headers, you create an object of the class javax.xml.soap.MimeHeader. Each MimeHeader instance is added to an instance of javax.xml.soap.MimeHeaders. Then you can use the SAAJ API to read the SOAP message, like in the following example:

Best wishes!
chaitu sravs
Greenhorn

Joined: Oct 21, 2009
Posts: 11
Sure. We are doing the same and are able to get the SOAPMessage.

The XML inside is huge and we are trying to 'flat' iterate all the nodes using DocumentTraversal interface, but looks like SOAPPart cannot be casted to DocumentTraversal as it does not implement the interface.

Trying to see if the SOAP MessageFactory can use xerces2 Dom Implementation while exposing the SOAPPart.

Any ideas?
chaitu sravs
Greenhorn

Joined: Oct 21, 2009
Posts: 11
Also, just curious...

# or to allow for both versions of SOAP messages. The latter allow
# * for processing of incoming SOAP 1.1 and 1.2 messages


How would one go about that? I did not find any appropriate SOAPConstant entry for 'both' versions. Just do an AND (&) operation on the two constants (1.1 & 1.2)?
chaitu sravs
Greenhorn

Joined: Oct 21, 2009
Posts: 11
Never mind the original problem.

We were able to use the code at http://www.troubleshooters.com/tpromag/200103/codexercises.htm#_domwalkerjava to flat-walk a DOM tree from SOAPPart.

We are now left with only the problem of how to make the MessageFactory work for 'both versions'.

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get document object From SOAP Message?