-
1. Re: WF 10.1, how to not escape JAX-WS content
jaikiran Sep 20, 2017 2:23 AM (in response to nickarls)Is there some code you could post to show how this call is currently being done? It's been many years since I read/dealt with JAX-WS so I don't remember what's involved in this flow.
-
2. Re: WF 10.1, how to not escape JAX-WS content
nickarls Sep 20, 2017 6:19 AM (in response to jaikiran)Yep, I mostly do JAX-RS nowadays but every now and then stuff like this drops onto my desk. So I have something like
@Stateless @WebService public class Service { public String magic() { return "<data><![CDATA[<foo>bar</foo>]]></data>"; } }
but I end up (using SoapUI) with
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ns2:saveMessageResponse xmlns:ns2="http://magic/"> <return><data><![CDATA[<foo>bar</foo>]]></data></return> </ns2:saveMessageResponse> </soap:Body> </soap:Envelope>
where I would just like to have the raw String.
Well, technically the result is valid, too, but it confuses the consumer and the calling end is out of our hands so I thought it might be easier to fix in the service end...
I guess it could be possible to use a logical message handler in a chain but that sounds a bit like overkill. I tried it and even if I did a search/replace, they still were encoded on the way out somehow (lost the CDATA-section also somehow)
thanks in advance,
Nik
-
3. Re: WF 10.1, how to not escape JAX-WS content
jewellgm Sep 20, 2017 8:44 AM (in response to nickarls)In the past, if I've wanted to manipulate the contents of a SOAP message, I've implemented a SOAPHandler. In order to do that, you would need to annotate the class with @HandlerChain, which points to a configuration file. That file lists all of the handlers in the chain that operate on the SOAP message.
I don't know whether the operations that you want to do would cause errors in the transmission of the message, but it may be worth looking into.
Here's some documentation on Oracle's website on how to do this in WebLogic, but I did similar things with JBoss AS 7 to Wildfly 9.
-
4. Re: WF 10.1, how to not escape JAX-WS content
nickarls Sep 20, 2017 8:56 AM (in response to jewellgm)Yep, tried it, did a "unencode" but they still re-appeared "on the way out". The CDATA-section got dropped for some reason also.
Perhaps I should have stayed on XML level, my first attempt converted it to a string for the modification...
-
5. Re: WF 10.1, how to not escape JAX-WS content
asoldano Sep 20, 2017 9:52 AM (in response to nickarls)Hi,
I need to do some tries and check when exactly the encoding happens.
Nicklas Karlsson wrote:
I've seen examples in Java SE where you created a JAXBContext, got the marshaller from there and added an implementation of a CharacterEscapeHandler into a certain property on the marshaller but what would be the integration point from a WS-annotated stateless EJB?
Can you past a link to where you've see the examples mentioned above?
Thanks
Alessio
-
6. Re: WF 10.1, how to not escape JAX-WS content
nickarls Sep 20, 2017 5:40 PM (in response to asoldano)I think I saw it mentioned in java - Can I force JAXB not to convert " into ", for example, when marshalling to XML? - Stack Overflow
The strange thing is that in my logical message handler I saw the message "escaped" so I thought I was in the right place but after my modification there was apparently *still* some encoding being done....
-
7. Re: WF 10.1, how to not escape JAX-WS content
nickarls Sep 22, 2017 1:46 AM (in response to nickarls)I even tried to add a Servlet Filter with a HttpServletResponseWrapper implementation that "de-encoded" the stuff but the result was the same as with the logical message handler: CDATA wrapping is dropped and < goes back to < which would indicate that the JAX-WS implementation is applying some encoding even on top of the outermost filter layer of the web application(?)
-
8. Re: WF 10.1, how to not escape JAX-WS content
nickarls Sep 27, 2017 5:55 AM (in response to nickarls)Any theories? I'd hate to write some non-WS-enabled wrapper just to escape the container-level-escaping...
-
9. Re: WF 10.1, how to not escape JAX-WS content
asoldano Sep 27, 2017 12:47 PM (in response to nickarls)Hi,
sorry, I haven't had time yet to try something for this.
Anyway, the jaxb marshalling is controlled by Apache CXF, so I tried a quick search and found this thread: cxf-user - CXF jaxb send string as CData | Threaded View That seems to be suggesting to add a CXF interceptor to install a custom xml stream writer that deals with the escape process. You can try something on that line, or I'll do that as soon as I have time.
-
10. Re: WF 10.1, how to not escape JAX-WS content
nickarls Sep 28, 2017 2:02 AM (in response to asoldano)Thanks I'll give it a try. Awfully lot of code for having something *not* done ;-)
-
11. Re: WF 10.1, how to not escape JAX-WS content
nickarls Oct 2, 2017 2:05 AM (in response to nickarls)I tried the interceptor approach, I see it hit (even rewrote it so that super.writeCData is never called) but still I get escaped characters. Have to see if there is some ordering involved...
-
12. Re: WF 10.1, how to not escape JAX-WS content
mattalica Nov 8, 2017 4:10 PM (in response to nickarls)I had this same issue, and this did it for me:
java - Add CDATA on request's string parameter using only JAX-WS - Stack Overflow
In your SOAPHandler, you can use a method called message.getSOAPPart().createCDATASection( "CDATA content");
That apparently handles all the encoding.
-
13. Re: WF 10.1, how to not escape JAX-WS content
nickarls Nov 13, 2017 1:47 AM (in response to mattalica)Thanks for the pointer, I'll have a look. The problem is that it looks to be a client-side solution and I don't have control over the client :-/
If nothing else works I'll have to use some servlet etc that does the forwarding to the endpoint and modifies the response at a level where the JAX-WS implementation no longer can get its dirty hands on it...
-
14. Re: WF 10.1, how to not escape JAX-WS content
mattalica Nov 13, 2017 6:29 AM (in response to nickarls)Ok, sorry, I misunderstood that you were coming from the server side. Good luck! You might be able to use the SOAPHandlers for outgoing server data, too. I’m not sure.