Soap Request as String convert it into java object

cxf, java, jaxb, soap, string

Solution

I'm getting a SOAP request as string, from which I want to extract a Java object. Is it possible?

Yes.

If yes, then how?

You need to convert the `String` into something that JAXB can unmarshal. Examples include a `StringReader` or `XMLStreamReader`.

What API can be used for this?

Since a SOAP message contains more information than what corresponds to the domain model I would recommend using JAXB with a StAX `XMLStreamReader`. You use `StAX` to parser the `String`. Then you advance the `XMLStreamReader` to the element that contains the content you wish to unmarshal. Then you unmarshal the `XMLStreamReader` at that point.

- http://blog.bdoughan.com/2012/08/handle-middle-of-xml-document-with-jaxb.html

Problem

I'm getting a SOAP request as string, from which I want to extract a Java object. Is it possible? If yes, then how? What API can be used for this?

Original source