OK,

You can read the request from the HTTP request stream but once you do the 
request is no longer in the stream and trying to pass it on to its destination 
for handling will fail as the request is no longer available having been read 
earlier. I think the headers you are getting are infact HTTP headers as SOAP 
headers are burried in the SOAPEnvelope which you dont have.

What you then need to do is wrap the request within a new stream where you can 
make the previously read stream contents available i.e. as a byte stream 
further down the handling chain.

I have a filter that does just this. It audits all SOAP requests including 
HTTP headers and the body, then passes the request on down the handling chain. 
This can be an expensive process so use with caution.

I have attached the relevant files to this mail for you.

Regards

Steve


Quoting Vogt Burkhard EXT <[EMAIL PROTECTED]>:

> Hi,
> 
> I'm sitting in the middle between a SOAP Client and (one or more) services,
> operating as a web-service proxy. 
> As a tomcat (5.x, java 1.4.2) application I receive the SOAP headers as
> expected but additionaly I need to 
> receive the SOAP object from the request in order to delegate the processing
> to the appropriate web service.
> 
> Does anybody know how to do this?
> 
> Thanks in advance for your time and any hints.
> 
> Regards,
> Burkhard
> 



package somepackage;

import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletContext;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.*;

import org.apache.commons.id.*;

public abstract class BaseFilter implements Filter {
        Logger logger = Logger.getLogger(BaseFilter.class);
        
        protected SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd-HHmmss");
        
        protected FilterConfig config = null;

        protected IdentifierGeneratorFactory factory = 
IdentifierGeneratorFactory.newInstance();
        protected StringIdentifierGenerator generator = 
factory.alphanumericGenerator();        
        protected synchronized String getNextID(){
                StringBuffer buff = new StringBuffer( sdf.format(new Date()) );        
 
                buff.append("-");
                buff.append(generator.nextStringIdentifier());          
                return buff.toString();
        }
        
    /**
     * Place this filter into service.
     *
     * @param filterConfig The filter configuration object
     */
        public void init(FilterConfig filterConfig) throws ServletException {
                this.config = filterConfig;
        }
        
        /**
         * Take this filter out of service.
         */
        public void destroy() {
            this.config = null;     
        }
        
        protected synchronized void log(String msg){
                //log to ctx
                ServletContext ctx = this.config.getServletContext();
                ctx.log(msg);
                
                //log to own logger maybe context logger is n ot set 
                logger.info(msg);
        }
        
        protected void createAuditMsg(String requestString, String responseString){
                log("create audit Msg ....");
                StringBuffer auditMsg = new StringBuffer("<-----------------------[ \n 
");                                                      
                auditMsg.append(getNextID());
                auditMsg.append("\n REQ = \n");
                auditMsg.append(requestString);
                auditMsg.append("\n RESP = \n");
                auditMsg.append(responseString);
                auditMsg.append(" \n ]----------------------->");

                log(auditMsg.toString());
        }
}
package somepackage;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.o2.germany.ecrm.common.filters.wrapper.*;

public class AuditFilter extends BaseFilter {
        
        public void doFilter(ServletRequest request, ServletResponse response, 
FilterChain chain) throws IOException, ServletException {                
                if(this.config != null){
                        log("Audit Filter start ...");
                        java.io.OutputStream                     out                   
  = response.getOutputStream(); 
                        
                        ByteArrayRequestWrapper    requestWrapper   = new 
ByteArrayRequestWrapper((HttpServletRequest)request);
                        ByteArrayResponseWrapper   responseWrapper  = new 
ByteArrayResponseWrapper((HttpServletResponse) response); 
                        
                        String requestString = requestWrapper.toString();
                        
                        log("---- do chain ...");
                        chain.doFilter(requestWrapper, responseWrapper);
                                        
                        log("---- set response data ...");
                        out.write(responseWrapper.getData());
                        out.close();    
                        
                        createAuditMsg(requestString, new 
String(responseWrapper.getData()) );
                        log("Audit Filter filter done .");
                }else{
                        
System.err.println("***********************************************************************");
                System.err.println("AuditFilter ---> CONFIG IS NULL FILTER 
FUNCTIONALITIE IS NOT USED !!!!!");
                
System.err.println("***********************************************************************");
                }
                return;
        }
}

Reply via email to