<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Debugging SOAP by logging the incoming HttpRequest</title>
	<atom:link href="http://blog.redstream.nl/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.redstream.nl/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/</link>
	<description>Pragmatic Integrators</description>
	<lastBuildDate>Fri, 23 Jul 2010 20:48:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=1058</generator>
	<item>
		<title>By: netminkey</title>
		<link>http://blog.redstream.nl/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/comment-page-1/#comment-227</link>
		<dc:creator>netminkey</dc:creator>
		<pubDate>Thu, 20 Dec 2007 21:36:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.pascalalma.net/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/#comment-227</guid>
		<description>or more simply:

public void init(FilterConfig filterConfig) throws ServletException
    {
        com.sun.xml.ws.transport.http.HttpAdapter.dump=true;
    }</description>
		<content:encoded><![CDATA[<p>or more simply:</p>
<p>public void init(FilterConfig filterConfig) throws ServletException<br />
    {<br />
        com.sun.xml.ws.transport.http.HttpAdapter.dump=true;<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: netminkey</title>
		<link>http://blog.redstream.nl/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/comment-page-1/#comment-226</link>
		<dc:creator>netminkey</dc:creator>
		<pubDate>Thu, 20 Dec 2007 18:44:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.pascalalma.net/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/#comment-226</guid>
		<description>You could also wrap the request in an HttpServletRequestWrapper:

class MyWrapper extends javax.servlet.HttpServletRequestWrapper {
        private ServletInputStream wrappedInputStream;
        public MyWrapper(HttpServletRequest servletRequest)
        {  super(servletRequest);  }

        public void printInputStream() throws IOException {
            InputStream s = getRequest().getInputStream();
            byte[] data = null;
            try { data = readDataIntoByteArray(s); }
            finally { s.close(); }
            System.out.println(&quot;Data is: &quot; + new String(data));

            final ByteArrayInputStream bis = new ByteArrayInputStream(data);
            wrappedInputStream = new ServletInputStream() {
                @Override
                public int read() throws IOException
                {  return bis.read();    }};
        }
        @Override
        public ServletInputStream getInputStream() throws IOException {
            if (wrappedInputStream == null)
                return getRequest().getInputStream();
            else
                return wrappedInputStream;
        }
}

and use it like this:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,  ServletException   {
       MyWrapper httpRequest = new MyWrapper((HttpServletRequest)request);
       httpRequest.printInputStream();
       chain.doFilter(httpRequest, response);
}

Even better, you can add an init param to your filter to choose whether to turn debugging on (for dev mode) or off (for production mode)</description>
		<content:encoded><![CDATA[<p>You could also wrap the request in an HttpServletRequestWrapper:</p>
<p>class MyWrapper extends javax.servlet.HttpServletRequestWrapper {<br />
        private ServletInputStream wrappedInputStream;<br />
        public MyWrapper(HttpServletRequest servletRequest)<br />
        {  super(servletRequest);  }</p>
<p>        public void printInputStream() throws IOException {<br />
            InputStream s = getRequest().getInputStream();<br />
            byte[] data = null;<br />
            try { data = readDataIntoByteArray(s); }<br />
            finally { s.close(); }<br />
            System.out.println(&#8220;Data is: &#8221; + new String(data));</p>
<p>            final ByteArrayInputStream bis = new ByteArrayInputStream(data);<br />
            wrappedInputStream = new ServletInputStream() {<br />
                @Override<br />
                public int read() throws IOException<br />
                {  return bis.read();    }};<br />
        }<br />
        @Override<br />
        public ServletInputStream getInputStream() throws IOException {<br />
            if (wrappedInputStream == null)<br />
                return getRequest().getInputStream();<br />
            else<br />
                return wrappedInputStream;<br />
        }<br />
}</p>
<p>and use it like this:<br />
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,  ServletException   {<br />
       MyWrapper httpRequest = new MyWrapper((HttpServletRequest)request);<br />
       httpRequest.printInputStream();<br />
       chain.doFilter(httpRequest, response);<br />
}</p>
<p>Even better, you can add an init param to your filter to choose whether to turn debugging on (for dev mode) or off (for production mode)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zouq</title>
		<link>http://blog.redstream.nl/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/comment-page-1/#comment-229</link>
		<dc:creator>Zouq</dc:creator>
		<pubDate>Sat, 01 Dec 2007 09:01:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.pascalalma.net/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/#comment-229</guid>
		<description>Any idea how to log outgoing Response??? Any help would be appreciated.</description>
		<content:encoded><![CDATA[<p>Any idea how to log outgoing Response??? Any help would be appreciated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Hunt</title>
		<link>http://blog.redstream.nl/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/comment-page-1/#comment-224</link>
		<dc:creator>Tom Hunt</dc:creator>
		<pubDate>Sun, 25 Nov 2007 19:21:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.pascalalma.net/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/#comment-224</guid>
		<description>Pascal,
     Thank you!  I have been trying to implement the same solution for logging multipart-form data posts.  I tried wrapping the request, but I hadn&#039;t taken it to the point of overriding the inputstream and its read functions.  This works like a charm.</description>
		<content:encoded><![CDATA[<p>Pascal,<br />
     Thank you!  I have been trying to implement the same solution for logging multipart-form data posts.  I tried wrapping the request, but I hadn&#8217;t taken it to the point of overriding the inputstream and its read functions.  This works like a charm.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mat</title>
		<link>http://blog.redstream.nl/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/comment-page-1/#comment-225</link>
		<dc:creator>mat</dc:creator>
		<pubDate>Thu, 22 Nov 2007 08:41:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.pascalalma.net/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/#comment-225</guid>
		<description>The sample kind of works but for some reason the logged SOAP request gets truncated towards the end. I could not detect the reason. Pretty odd. Any idea why that would be ?
Thank you anyway.</description>
		<content:encoded><![CDATA[<p>The sample kind of works but for some reason the logged SOAP request gets truncated towards the end. I could not detect the reason. Pretty odd. Any idea why that would be ?<br />
Thank you anyway.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jim</title>
		<link>http://blog.redstream.nl/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/comment-page-1/#comment-228</link>
		<dc:creator>jim</dc:creator>
		<pubDate>Wed, 31 Oct 2007 17:45:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.pascalalma.net/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/#comment-228</guid>
		<description>Thank you Pascal. This is exactly what I was looking for as I was at dead end wondering why the SOAP servcie was blowing up just because I logged the inputstream. Your idea is great and I appreciate you posting your solution. I was in the exact same situation. It tried as the other comment suggests about using .reset() and it didn&#039;t work for me either, but your solution did work great. Thanks again!</description>
		<content:encoded><![CDATA[<p>Thank you Pascal. This is exactly what I was looking for as I was at dead end wondering why the SOAP servcie was blowing up just because I logged the inputstream. Your idea is great and I appreciate you posting your solution. I was in the exact same situation. It tried as the other comment suggests about using .reset() and it didn&#8217;t work for me either, but your solution did work great. Thanks again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pascal Alma</title>
		<link>http://blog.redstream.nl/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/comment-page-1/#comment-221</link>
		<dc:creator>Pascal Alma</dc:creator>
		<pubDate>Tue, 18 Sep 2007 04:48:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.pascalalma.net/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/#comment-221</guid>
		<description>Just got some time to test the filter with the reset() statement. Unfortunatly it doesn&#039;t work. I&#039;m getting the following stacktrace:
java.io.IOException: mark/reset not supported
	java.io.InputStream.reset(InputStream.java:331)
        net.pascalalma.filter.LogRequestFilter.doFilter(LogRequestFilter.java:51)
	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

So maybe my solution wasn&#039;t that bad??</description>
		<content:encoded><![CDATA[<p>Just got some time to test the filter with the reset() statement. Unfortunatly it doesn&#8217;t work. I&#8217;m getting the following stacktrace:<br />
java.io.IOException: mark/reset not supported<br />
	java.io.InputStream.reset(InputStream.java:331)<br />
        net.pascalalma.filter.LogRequestFilter.doFilter(LogRequestFilter.java:51)<br />
	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)</p>
<p>So maybe my solution wasn&#8217;t that bad??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pascal Alma</title>
		<link>http://blog.redstream.nl/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/comment-page-1/#comment-223</link>
		<dc:creator>Pascal Alma</dc:creator>
		<pubDate>Thu, 30 Aug 2007 03:57:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.pascalalma.net/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/#comment-223</guid>
		<description>LOL!
I don&#039;t have time right now to check this but if it is true then that would be a much easier solution!
So if this blog isn&#039;t helpful to you, at least I am learning of it :-)</description>
		<content:encoded><![CDATA[<p>LOL!<br />
I don&#8217;t have time right now to check this but if it is true then that would be a much easier solution!<br />
So if this blog isn&#8217;t helpful to you, at least I am learning of it :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mykola Dzyuba</title>
		<link>http://blog.redstream.nl/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/comment-page-1/#comment-222</link>
		<dc:creator>Mykola Dzyuba</dc:creator>
		<pubDate>Wed, 29 Aug 2007 21:46:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.pascalalma.net/2007/08/24/debugging-soap-by-logging-the-incoming-httprequest/#comment-222</guid>
		<description>In response to this comment: &quot;When you try this implementation of the filter you will definitely receive errors in your web service! This is caused by the fact that the inputstream is already processed in the filter so you can not process it again in your web service/servlet&quot;

I think it would be easier to simply call in.reset() as it is done in my function below.


 private void writeInputStream(HttpServletRequest request, BufferedWriter out) throws IOException {
    out.write(&quot;** START INPUTSTREAM **\n&quot;);
    ServletInputStream in = request.getInputStream();
    if (in.markSupported()) {
      in.mark(MAX_BYTES);
    }
    int i = 0;
    while ((i = in.read()) != -1) {
      out.write(i);
    }
    out.write(&quot;\n** END OF INPUTSTREAM **\n&quot;);
    in.reset();
  }</description>
		<content:encoded><![CDATA[<p>In response to this comment: &#8220;When you try this implementation of the filter you will definitely receive errors in your web service! This is caused by the fact that the inputstream is already processed in the filter so you can not process it again in your web service/servlet&#8221;</p>
<p>I think it would be easier to simply call in.reset() as it is done in my function below.</p>
<p> private void writeInputStream(HttpServletRequest request, BufferedWriter out) throws IOException {<br />
    out.write(&#8220;** START INPUTSTREAM **\n&#8221;);<br />
    ServletInputStream in = request.getInputStream();<br />
    if (in.markSupported()) {<br />
      in.mark(MAX_BYTES);<br />
    }<br />
    int i = 0;<br />
    while ((i = in.read()) != -1) {<br />
      out.write(i);<br />
    }<br />
    out.write(&#8220;\n** END OF INPUTSTREAM **\n&#8221;);<br />
    in.reset();<br />
  }</p>
]]></content:encoded>
	</item>
</channel>
</rss>
