• Post Reply Bookmark Topic Watch Topic
  • New Topic

< is replaced by &lt; in axis2 web service

 
yash wardhan
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
thomas paul Paul
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yash wardhan can you please explain how you resolved the issue with some code help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!