Return-Path: Delivered-To: apmail-ws-axis-user-archive@www.apache.org Received: (qmail 14520 invoked from network); 1 Dec 2006 00:41:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Dec 2006 00:41:12 -0000 Received: (qmail 49603 invoked by uid 500); 1 Dec 2006 00:41:11 -0000 Delivered-To: apmail-ws-axis-user-archive@ws.apache.org Received: (qmail 49584 invoked by uid 500); 1 Dec 2006 00:41:11 -0000 Mailing-List: contact axis-user-help@ws.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-user@ws.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-user@ws.apache.org Received: (qmail 49573 invoked by uid 99); 1 Dec 2006 00:41:11 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Nov 2006 16:41:11 -0800 X-ASF-Spam-Status: No, hits=2.9 required=10.0 tests=HTML_10_20,HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of sridhar.jforum@gmail.com designates 64.233.162.232 as permitted sender) Received: from [64.233.162.232] (HELO nz-out-0102.google.com) (64.233.162.232) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Nov 2006 16:41:00 -0800 Received: by nz-out-0102.google.com with SMTP id m7so1397403nzf for ; Thu, 30 Nov 2006 16:40:40 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=FojO+hOYcT8xXuyW0zKYcawWhMF7hbQG/CytYFIsducfh7H+JeaDgZK8u7KU4LNAVRKuJUteVTWH/s9VtJ7LaYzoTt3bGVRXltrT/ufRzinDsG7QCXepiQ6xs1xAfqJ+fnZOtRuA3TbTeQPGpCnaFkLiIFJ8yj7lLmQkKDdLiBE= Received: by 10.64.208.20 with SMTP id f20mr6602505qbg.1164933639777; Thu, 30 Nov 2006 16:40:39 -0800 (PST) Received: by 10.65.75.11 with HTTP; Thu, 30 Nov 2006 16:40:39 -0800 (PST) Message-ID: <624a79970611301640t2e53315bi9688d89da337cf39@mail.gmail.com> Date: Thu, 30 Nov 2006 19:40:39 -0500 From: "sridhar vudutha" To: axis-user@ws.apache.org Subject: Intercepting SOAP Request Using ServletFilter MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_36584_757212.1164933639745" X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_36584_757212.1164933639745 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello All, I understand that this is not the right forum to post this message but want to see if there any better solution. I'm trying to intercept a SOAP request, modify the XML and pass it on to the AxisServlet. Gone through forums and got to a point where I could read the request content into a StringBuffer. Can someone please help me to set the read bytes back to the HttpServletRequest object. // Servlet Filter import java.io.*; import java.util.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; public final class SOAPServletFilter implements Filter { private FilterConfig config = null; PrintWriter out; public void init(FilterConfig filterConfig) throws ServletException { config = filterConfig; } public void destroy() { config = null; // destroy method called } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (config == null) { return; } CustomRequestWrapper cr = new CustomRequestWrapper((HttpServletRequest)request); chain.doFilter(cr, response); } } // HttpServletRequestWrapper import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; public class CustomRequestWrapper extends HttpServletRequestWrapper{ private CustomServerInputStream in; private HttpServletRequest request; public CustomRequestWrapper(HttpServletRequest request) throws IOException{ super(request); this.request = request; in = new CustomServerInputStream(request.getInputStream()); } public ServletInputStream getInputStream() { return in; } public BufferedReader getReader() { BufferedReader br = new BufferedReader(new InputStreamReader(in)); return br; } } class CustomServerInputStream extends ServletInputStream { final private ServletInputStream in; private StringBuffer strbuf = new StringBuffer(); public CustomServerInputStream(ServletInputStream inputStream) { super(); in = inputStream; } public int read(byte[] b, int off, int len) throws IOException{ final int chr = in.read(b,0,b.length); System.out.println(" total : " + chr); return chr; } public int read(byte[] b) throws IOException { int chr = in.read(b); strbuf.append(new String(b)); System.out.println(" content " + new String(b)); System.out.println(" noOfBytes " + chr); return chr; } public int read() throws IOException { final int chr = in.read(); System.out.println(" char " + chr); return chr; } public StringBuffer getBody() { return strbuf; } } I have overrided the 3 read() methods. Not sure why the read(byte [] b) is only invoked. Also, it is invoked more than once depending on the no of bytes in the request object. The example I'm trying has 5278 bytes, it read the first 4000 bytes and rest in the 2nd invocation. I'm putting all the read bytes into a StringBuffer. The problem is, after all the bytes are read, how to set it back to the Request object. Any help in this regard is greatly appreciated. Thanks in advance, Sridhar. ------=_Part_36584_757212.1164933639745 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
Hello All,
   I understand that this is not the right forum to post this message but want to see if there any better solution.
 
I'm trying to intercept a SOAP request, modify the XML and pass it on to the AxisServlet. Gone through forums and got to a point where I could read the request content into a StringBuffer. Can someone please help me to set the read bytes back to the HttpServletRequest object.

// Servlet Filter

import java.io.*;
import java.util.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;


public final class SOAPServletFilter implements Filter {
private FilterConfig config = null;
PrintWriter out;
public void init(FilterConfig filterConfig) throws ServletException {
config = filterConfig;
}

public void destroy() {
config = null; // destroy method called
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {

if (config == null) {
return;
}

CustomRequestWrapper cr = new
CustomRequestWrapper((HttpServletRequest)request);
chain.doFilter(cr, response);
}
}


// HttpServletRequestWrapper

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletRequestWrapper;

public class CustomRequestWrapper extends HttpServletRequestWrapper{
private CustomServerInputStream in;

private HttpServletRequest request;
public CustomRequestWrapper(HttpServletRequest request) throws IOException{
super(request);
this.request = request;
in = new CustomServerInputStream(request.getInputStream());
}
public ServletInputStream getInputStream() {
return in;
}
public BufferedReader getReader() {
BufferedReader br = new BufferedReader(new InputStreamReader(in));
return br;
}
}

class CustomServerInputStream extends ServletInputStream {

final private ServletInputStream in;
private StringBuffer strbuf = new StringBuffer();

public CustomServerInputStream(ServletInputStream inputStream) {
super();
in = inputStream;
}

public int read(byte[] b, int off, int len) throws IOException{
final int chr = in.read(b,0,b.length );
System.out.println(" total : " + chr);
return chr;
}

public int read(byte[] b) throws IOException {
int chr = in.read(b);
strbuf.append(new String(b));
System.out.println(" content " + new String(b));
System.out.println(" noOfBytes " + chr);

return chr;
}

public int read() throws IOException {
final int chr = in.read();
System.out.println(" char " + chr);
return chr;
}

public StringBuffer getBody() {
return strbuf;
}
}


I have overrided the 3 read() methods. Not sure why the read(byte [] b) is only invoked. Also, it is invoked more than once depending on the no of bytes in the request object. The example I'm trying has 5278 bytes, it read the first 4000 bytes and rest in the 2nd invocation. I'm putting all the read bytes into a StringBuffer.

The problem is, after all the bytes are read, how to set it back to the Request object.

Any help in this regard is greatly appreciated.

Thanks in advance,
Sridhar.
------=_Part_36584_757212.1164933639745--