AXiS2 - Problem in returning the String value. < and > are getting converted to < and >
Asked Answered
S

2

1

I have written a simple web service which takes string as an argument and returns a String as output.

The service is something like this :

@WebService(name = "MyWebService", serviceName = "MyWebService", portName = "WS")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public class MyWebService {

    @WebMethod(action = "inputString")
    @WebResult(name = "resultString")
    public String serviceMethod(
            @WebParam(mode = WebParam.Mode.IN, name = "inputString") String inputString) {
        resultString ="<?xml version='1.0' encoding='UTF-8'?><Element><InnerElement>ElementValue</InnerElement></<Element>"
        System.out.println(resultString);
        return resultString;
    }

}

At the client Side I am getting:

&lt;?xml version='1.0' encoding='UTF-8'?&gt;&lt;Element&gt;&lt;InnerElement&gt;ElementValue&lt;/InnerElement&gt;&lt;/&lt;Element&gt;

This input is used in the third party parser which tries to find < or > and my application breaks.

Has any one come across this issue? What might be the issue and work around? Suggestions are highly welcome.

Subdual answered 10/8, 2011 at 18:21 Comment(0)
P
3

I'll admit I don't spend a lot of time researching it, but the last time I looked there was no good defined way to return an XML document as part of another XML document, which is basically what you are trying to do here. From what I remember reading, even in CDATA sections there could be problems. What you are seeing is the standard encoding for those characters in XML. If I'm remembering right its the XML header that messes up the CDATA sections, but again, its been a long time since I looked at it.

HTH

Petua answered 11/8, 2011 at 14:9 Comment(0)
S
0

Probably in WSDL you have xsd:string, so must converts special chars '<', '>' because this is only string. Change wsdl document to ex. xsd:any.

Snobbery answered 11/8, 2011 at 13:38 Comment(1)
but we need to pass string as required by the actual request. So changing to any not helpingNonproductive

© 2022 - 2024 — McMap. All rights reserved.