5 Replies Latest reply on May 22, 2012 7:37 AM by jim.ma

    Encoding of response

    nickarls

      Hi,

       

         I have a WebService deployed on a JBAS 7.1.1. Testing with SoapUI, I see an UTF-8 encoded request coming in, an UTF-8 encoded response  going out, "åäöÅÄÖ" is encoded correctly etc. The WS is however also used by an Eclipse BIRT reporting engine and it insists on encoding the request as ISO-8859-1 and. The In/Out logger interceptors show the response also being ISO-8859-1 encoded but the "åäöÅÄÖ" has now become "??????". I discussed this with Richard Opalka and the mentioned that the response is always encoded in UTF-8. If I can't force the client to use UTF-8, what options are there left? Are there any CXF-interceptors that would allow me to change the encoding (on the way in)?

       

      The WS definition is a very simple

       

       

      @Stateless
      @WebService
      @ExcludeDefaultInterceptors
      @InInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingInInterceptor")
      @OutInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingOutInterceptor")
      public class ReportWebService 
      {
                @Inject
                private Reportgenerator reportgenerator;
      
      // methods calling reportgenerator, spitting out a POJO-structure
      
      
        • 1. Re: Encoding of response
          jim.ma

          Hi Nicklas, what is the payload printed by logginInInterceptor  ? If it is "??????", it could be the client side issue and it doesn't encode the "åäöÅÄÖ" correctly.  I had a quick try in CXF , send this request  with ISO-8859-1 encoded and cxf can handle  the response correctly.

          • 2. Re: Encoding of response
            nickarls
            12:50:59,837 INFO  [org.apache.cxf.interceptor.LoggingInInterceptor] (http--0.0.0.0-80-5) Inbound Message
            ----------------------------
            ID: 4
            Address: http://fikarlsnic01/OSTi/WebMarelaReportWebService
            Encoding: ISO-8859-1
            Http-Method: POST
            Content-Type: text/xml
            Headers: {Accept=[text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2], cache-control=[no-cache], connection=[Close], Content-Length=[554], content-type=[text/xml], host=[fikarlsnic01], pragma=[no-cache], SOAPAction=[], user-agent=[Java/1.7.0]}
            Payload: <?xml version="1.0"?>
            <SOAP-ENV:Envelope
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
                      <SOAP-ENV:Body>
                                <m:haeKulutusraportti xmlns:m="http://report.webmarela.osti.affecto.fi/">
                                          <arg0>V2</arg0>
                                          <arg1>WebMarela</arg1>
                                          <arg2>0018</arg2>
                                          <arg3>012011</arg3>
                                          <arg4>012012</arg4>
                                          <arg5>cafebabe1</arg5>
                                </m:haeKulutusraportti>
                      </SOAP-ENV:Body>
            </SOAP-ENV:Envelope>
            
            

             

             

            12:50:59,500 INFO  [org.apache.cxf.interceptor.LoggingOutInterceptor] (http--0.0.0.0-80-5) Outbound Message
            ---------------------------
            ID: 3
            Encoding: ISO-8859-1
            Content-Type: text/xml
            Headers: {}
            Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:haeKulutusraporttiResponse xmlns:ns2="http://report.webmarela.osti.affecto.fi/"><return><otsikko><arvo10>0.0</arvo10><arvo11>0.0</arvo11><arvo12>0.0</arvo12><arvo13>0.0</arvo13><arvo14>0.0</arvo14><arvo15>0.0</arvo15><arvo2>Ajalta :01.11.0120 - 31.12.0120</arvo2><arvo3>.</arvo3><arvo4>.</arvo4><arvo5>.</arvo5><arvo6>0.0</arvo6><arvo7>0.0</arvo7><arvo8>0.0</arvo8><arvo9>0.0</arvo9><id><arvo1>??????</arvo1><naytto>MYY917</naytto><numero>1428</numero><tunnus>0000000000</tunnus></id><raportti>.</raportti></otsikko></return></ns2:haeKulutusraporttiResponse></soap:Body></soap:Envelope>
            --------------------------------------
            
            

             

            The question marks come in the <arvo1> where the åäöÅÄÖ was sent

            • 3. Re: Encoding of response
              nickarls

              Some further testing:

               

              case 1, soapUI, åäö OK

               

              request

               

              ID: 1
              Address: http://fikarlsnic01/OSTi/WebMarelaReportWebService
              Encoding: UTF-8
              Http-Method: POST
              Content-Type: text/xml;charset=UTF-8
              Headers: {accept-encoding=[gzip,deflate], Content-Length=[444], content-type=[text/xml;charset=UTF-8], host=[fikarlsnic01], SOAPAction=[""], user-agent=[Jakarta Commons-HttpClient/3.1]}
              Payload: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rep="http://report.webmarela.osti.affecto.fi/">
              ...
              

               

              response

               

              ID: 1
              Encoding: UTF-8
              Content-Type: text/xml
              Headers: {}
              Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
              ...
              

               

              case 2, httpClient (saved request from soapUI), åäö become "???"


              request

               

              ID: 2
              Address: http://fikarlsnic01/OSTi/WebMarelaReportWebService
              Encoding: ISO-8859-1
              Http-Method: POST
              Content-Type: text/xml; charset=ISO-8859-1
              Headers: {connection=[Keep-Alive], Content-Length=[443], content-type=[text/xml; charset=ISO-8859-1], host=[fikarlsnic01:80], user-agent=[Apache-HttpClient/4.1.3 (java 1.5)]}
              Payload: soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rep="http://report.webmarela.osti.affecto.fi/">
              ...
              

               

              response

               

              ID: 2
              Encoding: ISO-8859-1
              Content-Type: text/xml
              Headers: {}
              Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
              ...
              

               

              case 3, BIRT report viewer call, åäö become "???"

               

              request

               

              ID: 3
              Address: http://fikarlsnic01/OSTi/WebMarelaReportWebService
              Encoding: ISO-8859-1
              Http-Method: POST
              Content-Type: text/xml
              Headers: {Accept=[text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2], cache-control=[no-cache], connection=[Close], Content-Length=[554], content-type=[text/xml], host=[fikarlsnic01], pragma=[no-cache], SOAPAction=[], user-agent=[Java/1.7.0]}
              Payload: <?xml version="1.0"?>
              <SOAP-ENV:Envelope
              xmlns:xsd="http://www.w3.org/2001/XMLSchema"
              xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
              ...
              

               

              response

               

              ID: 6
              Encoding: ISO-8859-1
              Content-Type: text/xml
              Headers: {}
              Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
              ...
              

               

              So in my environment UTF-encoded request/reponse works fine but ISO-8859-1 fails for both httpClient and the BIRT viewer.

              • 4. Re: Encoding of response
                nickarls

                A strange thing is also that httpClient doesn't work for UTF-8 encoding. But SoapUI works even if it apparently uses httpClient internally. Sigh.

                • 5. Re: Encoding of response
                  jim.ma

                  Is there any special operation in the  ReportWebService to generate '"åäöÅÄÖ" ? CXF sets the response with same encoding style as request.   I think add an intercetor after org.apache.cxf.interceptor.StaxInInterceptor  could change the response encoding to what you want:

                   

                  public class ChangeEncodingInterceptor extends AbstractPhaseInterceptor<Message> {

                       ....

                   

                      public void handleMessage(Message message) {

                          message.put(Message.ENCODING, "UTF-8");

                      }

                  }