4 Replies Latest reply on Aug 3, 2009 3:20 AM by ropalka

    String being escaped

      Hi,

      I've got a sample webservice that I'm deploying to JBoss 4.2.2.GA with JBoss-WS 3.0.2

      <?xml version="1.0" encoding="UTF-8"?>
      <definitions
       targetNamespace="http://roundtrip.developerWorks.ibm.com"
       xmlns="http://schemas.xmlsoap.org/wsdl/"
       xmlns:impl="http://roundtrip.developerWorks.ibm.com"
       xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">
       <types>
       <schema
       targetNamespace="http://roundtrip.developerWorks.ibm.com"
       xmlns="http://www.w3.org/2001/XMLSchema"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <complexType name="life">
       <sequence>
       <element name="deathday" nillable="true" type="xsd:dateTime"/>
       <element name="birthday" nillable="true" type="xsd:dateTime"/>
       <element name="str" nillable="false" type="xsd:string" form="qualified"/>
       </sequence>
       </complexType>
       </schema>
       </types>
       <message name="GetALifeRequest"/>
       <message name="GetALifeResponse">
       <part name="GetALifeReturn" type="impl:life"/>
       </message>
       <portType name="population">
       <operation name="GetALife">
       <input message="impl:GetALifeRequest" name="GetALifeRequest"/>
       <output message="impl:GetALifeResponse" name="GetALifeResponse"/>
       </operation>
       </portType>
       <binding name="populationSoapBinding" type="impl:population">
       <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
       <operation name="GetALife">
       <wsdlsoap:operation soapAction=""/>
       <input name="GetALifeRequest">
       <wsdlsoap:body namespace="http://roundtrip.developerWorks.ibm.com" use="literal"/>
       </input>
       <output name="GetALifeResponse">
      
       <wsdlsoap:body namespace="http://roundtrip.developerWorks.ibm.com" use="literal"/>
      
      
       </output>
       </operation>
       </binding>
       <service name="populationService">
       <port binding="impl:populationSoapBinding" name="population">
       <wsdlsoap:address location="http://localhost:9080/Roundtrip2/services/population"/>
       </port>
       </service>
      </definitions>
      




      <?xml version="1.0" encoding="UTF-8"?>
      <webservices version="1.1" xmlns="http://java.sun.com/xml/ns/j2ee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd">
       <webservice-description>
       <webservice-description-name>populationService</webservice-description-name>
       <wsdl-file>WEB-INF/wsdl/Roundtrip2.wsdl</wsdl-file>
       <jaxrpc-mapping-file>WEB-INF/wsdl/Roundtrip2_mapping.xml</jaxrpc-mapping-file>
       <port-component>
       <port-component-name>population</port-component-name>
       <wsdl-port xmlns:pfx="http://roundtrip.developerWorks.ibm.com">pfx:population</wsdl-port>
       <service-endpoint-interface>com.ibm.developerWorks.roundtrip.population</service-endpoint-interface>
      
       <service-impl-bean>
       <servlet-link>population</servlet-link>
       </service-impl-bean>
      
       </port-component>
       </webservice-description>
      </webservices>
      
      





      
      <?xml version="1.0" encoding="UTF-8"?>
      
      <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="WebApp_ID" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
      
       <servlet>
       <servlet-name>population</servlet-name>
       <servlet-class>org.jboss.wsf.stack.jbws.EndpointServlet</servlet-class>
       <init-param>
       <param-name>jboss.ws.endpoint</param-name>
       <param-value>com.ibm.developerWorks.roundtrip.populationImpl</param-value>
       </init-param>
       </servlet>
       <servlet-mapping>
       <servlet-name>population</servlet-name>
       <url-pattern>/ws/*</url-pattern>
       </servlet-mapping>
      </web-app>
      
      



      The populationImpl.java


      
      package com.ibm.developerWorks.roundtrip;
      
      import java.util.Calendar;
      import java.util.Date;
      
      public class populationImpl implements population {
       public life GetALife() {
       life aLife = new life();
       Calendar cal = Calendar.getInstance();
       cal.set(1910, 4, 15);
       aLife.birthday = cal.getTime();
       cal.set(2002, 11, 25);
       aLife.deathday = cal.getTime();
       String str=new String("<![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?>]]>");
       aLife.str=str;
       aLife._value=str;
       System.out.println("The value is " + str);
       return aLife;
       }
      }
      
      



      The response I'm getting is as follows,

      <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
       <env:Header/>
       <env:Body>
       <roun:GetALifeResponse xmlns:roun="http://roundtrip.developerWorks.ibm.com">
       <GetALifeReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <deathday>2002-12-24T14:14:47.646Z</deathday>
       <birthday>1910-05-14T15:14:47.646Z</birthday>
       <ns_str:str xmlns:ns_str="http://roundtrip.developerWorks.ibm.com"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>]]></ns_str:str>
       </GetALifeReturn>
       </roun:GetALifeResponse>
       </env:Body>
      </env:Envelope>
      



      For some reason the CDATA inside the element is being escaped. Can I specify anywhere in JBoss not to escape the string being returned ?

      Thanks

        • 1. Re: String being escaped

          This is my finding so far after debugging through the jboss-xb-binding source code

          The class MarshallerImpl() is the core class that does the serialization of the result from the objects to XML. The main method to do the serialization is called marshal(...) [ which have got several method implementation ]. The marshal (..) method calls an internal method (which is a private method) called marshallInternal(..). Basically what the marshallInternal(..) method does is it serialize the created "elements" and "value" to a String representation and it uses a class called ContentWriter (which is an implementation of org.xml.sax.ContentHandler interface), inside ContentWriter the characters(..) method implementation "normalize" all string character, this is where the problem lies as it converts all different character such as <,>,&,\," to it's respective decoded style &lt;,&gt;,&amp;,&apos;,&quot;



          The question that I'm wondering is this a bug , a feature or it's intentionally put in as a JBoss implementation ?

          I tried the same sample in WebSphere and the output inside the element is not being escaped.

          Can anybody point me to the right direction ?

          • 2. Re: String being escaped
            ropalka

            AFAIK this is feature.
            You should receive the same string on client side when you send XML fragment as string from server.
            Similarly you should receive the same XML fragment string on server side when it was sent from client. IOW serialization shouldn't affect you at all when you use just JAXWS API.

            • 3. Re: String being escaped

              Hi Richard,

              Thanks for your reply. Let me correct something in my previous posting the result I'm getting is that the string is being escaped as follows

              env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
               <env:Header/>
               <env:Body>
               <roun:GetALifeResponse xmlns:roun="http://roundtrip.developerWorks.ibm.com">
               <GetALifeReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <deathday>2002-12-24T14:14:47.646Z</deathday>
               <birthday>1910-05-14T15:14:47.646Z</birthday>
               <ns_str:str xmlns:ns_str="http://roundtrip.developerWorks.ibm.com">&lt;![CDATA[&lt;?xml version="1.0" encoding="UTF-8"?>]]&gt;</ns_str:str>
               </GetALifeReturn>
               </roun:GetALifeResponse>
               </env:Body>
              </env:Envelope>
              



              The reality is that when I run this the character is getting escaped now I'm not sure whether my configuration is correct or not ? the only thing that really baffle me is that it works in WebSphere without any problem but it got escaped in JBoss and as I explained in my previous post going through the source code it does gets escaped the question is why ?



              • 4. Re: String being escaped
                ropalka

                If there's CDATA section, then there's no need to escape characters.
                If you don't like current begavior, provide simple test case, patch and we'll incorporate it to our product ;)