You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by jean pierre pelerin <jp...@yahoo.fr> on 2009/02/11 10:37:19 UTC

problem using marshallerProperties for CData output

Hi,

    I'm trying to use a com.sun.xml.bind.characterEscapeHandler for JAXB customize escaping,
    in order to output CData text.
    
    This is my cxf configuration :


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:jaxws="http://cxf.apache.org/jaxws"
   xmlns:cxf="http://cxf.apache.org/core"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">

   <import resource="classpath:META-INF/cxf/cxf.xml" />
   <import resource="classpath:META-INF/cxf/cxf-extension-xml.xml" />
   <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

   
   <jaxws:endpoint id="wsuodb"
      implementor="my.test.odbu.odbActionImpl"
      wsdlLocation="WEB-INF/wsdl/odb.wsdl" address="/odb" >
      <jaxws:serviceFactory>
          <bean class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean">
             <property name="dataBinding">
                <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
                  <property name="marshallerProperties">
                     <map>
                        <entry>
                           <key><value>com.sun.xml.bind.characterEscapeHandler</value></key>
                           <bean class="my.test.escape.CDataCEH"/>
                        </entry>
                     </map>
                  </property>
               </bean>                
             </property>
          </bean>
       </jaxws:serviceFactory>   
   </jaxws:endpoint>

</beans>

Here is a part of the wsdl :

   <wsdl:binding name="ODB_XMLBinding" type="myODB:ODBActions">
    <xformat:binding />
    <wsdl:operation name="ODBAction">
      <wsdl:input name="TrRequest" />
      <wsdl:output name="TrResponse" />
    </wsdl:operation>
  </wsdl:binding>
  
  <wsdl:service name="ODBU">
    <wsdl:port binding="myODB:ODB_XMLBinding" name="actionsu">
      <http-conf:server CacheControl="no-cache" />
      <http:address location="http://localhost/odb/odb" />
    </wsdl:port>    
  </wsdl:service>


   There is no error when it start, and durring a request.
   But there is somme trace in the escape Methode of my.test.escape.CDataCEH and It is nerver call.

   When I replace  <bean class="my.test.escape.CDataCEH"/> by <value>something</value>
   there is an error during output, syaing that "something" is not an instance of "characterEscapeHandler". So that's ok, this configuration is use.
   Why the escape methode is never call ?

Many thanks.
JP


      __________________________________________________________________________________________________
Ne pleurez pas si votre Webmail ferme ! Récupérez votre historique sur Yahoo! Mail ! http://fr.docs.yahoo.com/mail/transfert_mails.html

Re : problem using marshallerProperties for CData output

Posted by jean pierre pelerin <jp...@yahoo.fr>.
Hi,

    I found that example : https://jaxb.dev.java.net/faq/JaxbCDATASample.java
    I think it's a better solution, but i didn't know how to configure this in CXF.
    With an interceptors ?

Thanks,




________________________________
From : Daniel Kulp 


This looks like a restriction/bug in JAXB, not really CXF.    If you use a 
marshaller to marshal an object to an OutputStream with encoding UTF-8, then 
the CharacterEscapeHandler never comes into play.  You can verify that by 
writing a simple program that marshals something to and outputstream.

I'm not sure which code paths in JAXB use the escape handlers and which ones 
don't.  Thus, I cannot really offer a workaround or anything at this point.  
You may be able to ask on the jaxb list for ideas.  At least they may be able 
to tell which of the marshal methods would actually us it, if any, and which 
conditions.   For example, may flipping from UTF-8 to something else would 
cause it to start being called.  (jaxb has a highly optimized UTF-8 encoder 
that maybe doesn't call the EscapeHandlers.  Possibly the other encoders do)

Dan


On Wed February 11 2009 4:37:19 am jean pierre pelerin wrote:
> Hi,
>
>     I'm trying to use a com.sun.xml.bind.characterEscapeHandler for JAXB
> customize escaping, in order to output CData text.
>
>     This is my cxf configuration :
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xmlns:jaxws="http://cxf.apache.org/jaxws"
>    xmlns:cxf="http://cxf.apache.org/core"
>    xsi:schemaLocation="http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
> http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
> http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
>
>    <import resource="classpath:META-INF/cxf/cxf.xml" />
>    <import resource="classpath:META-INF/cxf/cxf-extension-xml.xml" />
>    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
>
>
>    <jaxws:endpoint id="wsuodb"
>       implementor="my.test.odbu.odbActionImpl"
>       wsdlLocation="WEB-INF/wsdl/odb.wsdl" address="/odb" >
>       <jaxws:serviceFactory>
>           <bean
> class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"> <property
> name="dataBinding">
>                 <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
>                   <property name="marshallerProperties">
>                      <map>
>                         <entry>
>                          
> <key><value>com.sun.xml.bind.characterEscapeHandler</value></key> <bean
> class="my.test.escape.CDataCEH"/> </entry>
>                      </map>
>                   </property>
>                </bean>
>              </property>
>           </bean>
>        </jaxws:serviceFactory>
>    </jaxws:endpoint>
>
> </beans>
>
> Here is a part of the wsdl :
>
>    <wsdl:binding name="ODB_XMLBinding" type="myODB:ODBActions">
>     <xformat:binding />
>     <wsdl:operation name="ODBAction">
>       <wsdl:input name="TrRequest" />
>       <wsdl:output name="TrResponse" />
>     </wsdl:operation>
>   </wsdl:binding>
>
>   <wsdl:service name="ODBU">
>     <wsdl:port binding="myODB:ODB_XMLBinding" name="actionsu">
>       <http-conf:server CacheControl="no-cache" />
>       <http:address location="http://localhost/odb/odb" />
>     </wsdl:port>
>   </wsdl:service>
>
>
>    There is no error when it start, and durring a request.
>    But there is somme trace in the escape Methode of
> my.test.escape.CDataCEH and It is nerver call.
>
>    When I replace  <bean class="my.test.escape.CDataCEH"/> by
> <value>something</value> there is an error during output, syaing that
> "something" is not an instance of "characterEscapeHandler". So that's ok,
> this configuration is use. Why the escape methode is never call ?
>
> Many thanks.
> JP
>
>
>      
> ___________________________________________________________________________
>_______________________ Ne pleurez pas si votre Webmail ferme ! Récupérez
> votre historique sur Yahoo! Mail !
> http://fr.docs.yahoo.com/mail/transfert_mails.html

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog



      __________________________________________________________________________________________________
Ne pleurez pas si votre Webmail ferme ! Récupérez votre historique sur Yahoo! Mail ! http://fr.docs.yahoo.com/mail/transfert_mails.html

Re : problem using marshallerProperties for CData output

Posted by jean pierre pelerin <jp...@yahoo.fr>.
Hi, thanks for your answer.

   I try a simple program, and you're right. With ISO-8859-1 encoding, the escaper is called.
   But i try to add this entry for marshallerProperties in my cxf config :
   <entry>
         <key><value>jaxb.encoding</value></key>
         <value>ISO-8859-1</value>
   </entry>                                
    
    and it stay in UTF8 encoding, so the escaper is not called.
    I'm in PureXML/http in tomcat, is it the good properties to set ?

Many thanks.
JP



________________________________
From : Daniel Kulp :


This looks like a restriction/bug in JAXB, not really CXF.    If you use a 
marshaller to marshal an object to an OutputStream with encoding UTF-8, then 
the CharacterEscapeHandler never comes into play.  You can verify that by 
writing a simple program that marshals something to and outputstream.

I'm not sure which code paths in JAXB use the escape handlers and which ones 
don't.  Thus, I cannot really offer a workaround or anything at this point.  
You may be able to ask on the jaxb list for ideas.  At least they may be able 
to tell which of the marshal methods would actually us it, if any, and which 
conditions.   For example, may flipping from UTF-8 to something else would 
cause it to start being called.  (jaxb has a highly optimized UTF-8 encoder 
that maybe doesn't call the EscapeHandlers.  Possibly the other encoders do)

Dan


On Wed February 11 2009 4:37:19 am jean pierre pelerin wrote:
> Hi,
>
>     I'm trying to use a com.sun.xml.bind.characterEscapeHandler for JAXB
> customize escaping, in order to output CData text.
>
>     This is my cxf configuration :
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xmlns:jaxws="http://cxf.apache.org/jaxws"
>    xmlns:cxf="http://cxf.apache.org/core"
>    xsi:schemaLocation="http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
> http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
> http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
>
>    <import resource="classpath:META-INF/cxf/cxf.xml" />
>    <import resource="classpath:META-INF/cxf/cxf-extension-xml.xml" />
>    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
>
>
>    <jaxws:endpoint id="wsuodb"
>       implementor="my.test.odbu.odbActionImpl"
>       wsdlLocation="WEB-INF/wsdl/odb.wsdl" address="/odb" >
>       <jaxws:serviceFactory>
>           <bean
> class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"> <property
> name="dataBinding">
>                 <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
>                   <property name="marshallerProperties">
>                      <map>
>                         <entry>
>                          
> <key><value>com.sun.xml.bind.characterEscapeHandler</value></key> <bean
> class="my.test.escape.CDataCEH"/> </entry>
>                      </map>
>                   </property>
>                </bean>
>              </property>
>           </bean>
>        </jaxws:serviceFactory>
>    </jaxws:endpoint>
>
> </beans>
>
> Here is a part of the wsdl :
>
>    <wsdl:binding name="ODB_XMLBinding" type="myODB:ODBActions">
>     <xformat:binding />
>     <wsdl:operation name="ODBAction">
>       <wsdl:input name="TrRequest" />
>       <wsdl:output name="TrResponse" />
>     </wsdl:operation>
>   </wsdl:binding>
>
>   <wsdl:service name="ODBU">
>     <wsdl:port binding="myODB:ODB_XMLBinding" name="actionsu">
>       <http-conf:server CacheControl="no-cache" />
>       <http:address location="http://localhost/odb/odb" />
>     </wsdl:port>
>   </wsdl:service>
>
>
>    There is no error when it start, and durring a request.
>    But there is somme trace in the escape Methode of
> my.test.escape.CDataCEH and It is nerver call.
>
>    When I replace  <bean class="my.test.escape.CDataCEH"/> by
> <value>something</value> there is an error during output, syaing that
> "something" is not an instance of "characterEscapeHandler". So that's ok,
> this configuration is use. Why the escape methode is never call ?
>
> Many thanks.
> JP
>
>
>      
> ___________________________________________________________________________
>_______________________ Ne pleurez pas si votre Webmail ferme ! Récupérez
> votre historique sur Yahoo! Mail !
> http://fr.docs.yahoo.com/mail/transfert_mails.html

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog



      __________________________________________________________________________________________________
Ne pleurez pas si votre Webmail ferme ! Récupérez votre historique sur Yahoo! Mail ! http://fr.docs.yahoo.com/mail/transfert_mails.html

Re: problem using marshallerProperties for CData output

Posted by Daniel Kulp <dk...@apache.org>.
This looks like a restriction/bug in JAXB, not really CXF.    If you use a 
marshaller to marshal an object to an OutputStream with encoding UTF-8, then 
the CharacterEscapeHandler never comes into play.  You can verify that by 
writing a simple program that marshals something to and outputstream.

I'm not sure which code paths in JAXB use the escape handlers and which ones 
don't.  Thus, I cannot really offer a workaround or anything at this point.   
You may be able to ask on the jaxb list for ideas.  At least they may be able 
to tell which of the marshal methods would actually us it, if any, and which 
conditions.   For example, may flipping from UTF-8 to something else would 
cause it to start being called.  (jaxb has a highly optimized UTF-8 encoder 
that maybe doesn't call the EscapeHandlers.  Possibly the other encoders do)

Dan


On Wed February 11 2009 4:37:19 am jean pierre pelerin wrote:
> Hi,
>
>     I'm trying to use a com.sun.xml.bind.characterEscapeHandler for JAXB
> customize escaping, in order to output CData text.
>
>     This is my cxf configuration :
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xmlns:jaxws="http://cxf.apache.org/jaxws"
>    xmlns:cxf="http://cxf.apache.org/core"
>    xsi:schemaLocation="http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
> http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
> http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
>
>    <import resource="classpath:META-INF/cxf/cxf.xml" />
>    <import resource="classpath:META-INF/cxf/cxf-extension-xml.xml" />
>    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
>
>
>    <jaxws:endpoint id="wsuodb"
>       implementor="my.test.odbu.odbActionImpl"
>       wsdlLocation="WEB-INF/wsdl/odb.wsdl" address="/odb" >
>       <jaxws:serviceFactory>
>           <bean
> class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"> <property
> name="dataBinding">
>                 <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
>                   <property name="marshallerProperties">
>                      <map>
>                         <entry>
>                           
> <key><value>com.sun.xml.bind.characterEscapeHandler</value></key> <bean
> class="my.test.escape.CDataCEH"/> </entry>
>                      </map>
>                   </property>
>                </bean>
>              </property>
>           </bean>
>        </jaxws:serviceFactory>
>    </jaxws:endpoint>
>
> </beans>
>
> Here is a part of the wsdl :
>
>    <wsdl:binding name="ODB_XMLBinding" type="myODB:ODBActions">
>     <xformat:binding />
>     <wsdl:operation name="ODBAction">
>       <wsdl:input name="TrRequest" />
>       <wsdl:output name="TrResponse" />
>     </wsdl:operation>
>   </wsdl:binding>
>
>   <wsdl:service name="ODBU">
>     <wsdl:port binding="myODB:ODB_XMLBinding" name="actionsu">
>       <http-conf:server CacheControl="no-cache" />
>       <http:address location="http://localhost/odb/odb" />
>     </wsdl:port>
>   </wsdl:service>
>
>
>    There is no error when it start, and durring a request.
>    But there is somme trace in the escape Methode of
> my.test.escape.CDataCEH and It is nerver call.
>
>    When I replace  <bean class="my.test.escape.CDataCEH"/> by
> <value>something</value> there is an error during output, syaing that
> "something" is not an instance of "characterEscapeHandler". So that's ok,
> this configuration is use. Why the escape methode is never call ?
>
> Many thanks.
> JP
>
>
>      
> ___________________________________________________________________________
>_______________________ Ne pleurez pas si votre Webmail ferme ! Récupérez
> votre historique sur Yahoo! Mail !
> http://fr.docs.yahoo.com/mail/transfert_mails.html

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog