| Author |
< is replaced by < in axis2 web service
|
yash wardhan
Ranch Hand
Joined: Jan 22, 2008
Posts: 46
|
|
Hi,
I am using axis2 to develop a RESTFul webservice.
The method takes and returns the xml as a string.
I am preparing the response xml using Document object and converting it into string using Transformer class.
When I return the converted string from the service the < sigh is replaced by '& lt;'.
(I inserted the space between & and lt; for this post only otherwise the editor was parsing it as <. Please look in the subject how it is in the response )
The > sign is not escaped.
When I print the the string just before return statement it is a proper string nothing is escaped.
Can anyone please tell me how to overcome this problem, I am stuck on this problem and need to resolve at the server side only.
Thanks in advance
|
 |
yash wardhan
Ranch Hand
Joined: Jan 22, 2008
Posts: 46
|
|
Still waiting for reply.
Anyone got the problem like this and resolved it?
Thanks
|
 |
Dan Drillich
Ranch Hand
Joined: Jul 09, 2001
Posts: 1121
|
|
Yash,
Are you saying that all the < characters are being concerted to this sequence?
In order for the document to be well-formed the < characters need to be escaped when these characters are not used for the XML markup.
Regards,
Dan
|
William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
|
 |
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
|
|
yash wardhan wrote:and returns the xml as a string.
And as Dan pointed out that is where your problem is.
Under JAX-WS this is fixed by using an org.w3c.dom.Document instead of a String as this communicates your intention of passing an actual XML document. Maybe Axis2 has a similar mechanism.
|
 |
yash wardhan
Ranch Hand
Joined: Jan 22, 2008
Posts: 46
|
|
Thanks for the reply Dan and Peer,
Actually I am creating the org.w3c.dom.Document object and then converting it into a string.Because I am not sure if Axis2 supports that.
I checked the converted string and it is fine but when the response string received on the client the < character is replaced by the escape sequence.
Can you please tell me what should I do or point me to any url having allowed data types that axis2 supports?
It would be very nice if I can send the Document as a return type.
I googled but didn't find anything.
Thanks,
Yash
|
 |
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
|
|
yash wardhan wrote:Actually I am creating the org.w3c.dom.Document object and then converting it into a string. ... It would be very nice if I can send the Document as a return type.
Having a quick look at the RESTful Web Services Support page (they should get with it and re-title that page to more appropriately state "XML/HTTP Binding Support") it becomes clear that Axis2's XML world doesn't revolve around org.w3c.dom.Element but org.apache.axiom.om.OMElement instead.
So rather than converting the org.w3c.dom.Document to a java.lang.String convert it to an org.apache.axiom.om.OMElement with org.apache.axis2.util.XMLUtils.toOM(org.w3c.dom.Element) : org.apache.axiom.om.OMElement and return the resulting org.apache.axiom.om.OMElement - maybe that will work.
If you have a look at axis2/samples/userguide/src/userguide/example1/MyService.java - guess what userguide.example1.MyService.echo(OMElement element) returns? An org.apache.axiom.om.OMElement. Also notice the calls to element.build() and element.detach() before the org.apache.axiom.om.OMElement is returned.
|
 |
yash wardhan
Ranch Hand
Joined: Jan 22, 2008
Posts: 46
|
|
Thanks for the reply Peer,
I took a look at the OMElement and I am using org.apache.axis2.util.XMLUtils class's toOM(Element) method to conver the org.w3c.dom.Element into OMElement. As I said previously I was creating Document object any way so just 2-3 lines of code change is required.
So now the problem of < is resolved.
Also we don't need to give OMElement as an argument to the exposed method, and this is what my requirement was. I was getting a xml string as an input to my method and depending on this I needed to create the response xml. So I am able to do the both.
I am giving this so that no one stuck to the same problem.
Regards,
Yash
|
 |
 |
|
|
subject: < is replaced by < in axis2 web service
|
|
|