We have a legacy webservice that encodes its entire message with
Base64. I've written an interceptor that decodes the message to its
original form and that works. the interceptor is configured at the
phase RECEIVE.

Now there is an interceptor, configured at Phase.USER_PROTOCOL, that
checks for a SOAPheader in the message, which worked, but if I enable
the 'decodinginterceptor' the SAAJ model is not created and the
soapheader and body are null.

I searched the internet and found this
(http://bytearray.brixtonjunkies.com/2009/11/03/cxf-raw-soap-envelope-via-interceptor/)
blog, which explanes exactly my problem. So I implemented his
solution, but with no success.

InputStream inputStream = message.getContent(InputStream.class);

    if (inputStream != null){
        String processedSoapEnv = "";
        // Cache InputStream so it can be read independently
        CachedOutputStream cachedInputStream = new CachedOutputStream();
        try {
            IOUtils.copy(inputStream,cachedInputStream);
            inputStream.close();
            cachedInputStream.close();

            InputStream tmpInputStream = cachedInputStream.getInputStream();
            try{
                String inputBuffer = "";
                int data;
                while((data = tmpInputStream.read()) != -1){
                    byte x = (byte)data;
                    inputBuffer += (char)x;
                }
                processedSoapEnv = new String(new
Base64().decode(inputBuffer));


            }
            catch(IOException e){
                e.printStackTrace();
            }
        }
        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        message.setContent(InputStream.class, new
ByteArrayInputStream(processedSoapEnv.getBytes()));

If I print the var inputBuffer, I see a Base64 string, if I print the
processedSoapEnv the xml soap message is printed.

The interceptor is configured before the logging interceptor, and the
message is logged as plain text, like we want.

What am i doing wrong?

ps. spring configuration snippet:
        <jaxws:endpoint 
          id="sentinelServer" 
          implementor="#sentinelServerService" 
          address="/SentinelServer" >
                <jaxws:inInterceptors>
                        <ref bean="messageDecoder"/>
                        <bean 
class="org.apache.cxf.binding.soap.saaj.SAAJInInterceptor" />
                        <ref bean="securityTokenValidator"/>
                        <ref bean="requestInterceptor"/>
                </jaxws:inInterceptors>
                <jaxws:outInterceptors>
                        <bean 
class="org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor" />
                        <ref bean="messageEncoder"/>
                        <ref bean="responseInterceptor"/>
                </jaxws:outInterceptors>
                <jaxws:features>
                        <bean class="org.apache.cxf.feature.LoggingFeature" />
                </jaxws:features>
          </jaxws:endpoint>

--
View this message in context: 
http://cxf.547215.n5.nabble.com/CXF-Saaj-model-SOAPMessage-is-null-after-inpustream-modification-tp5492249p5492249.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to