Created
July 28, 2011 04:32
-
-
Save ratnikov/1110968 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parameter map: {field=[Ljava.lang.String;@6c29d838} | |
Printing body... | |
Done printing body | |
env: {"jruby.rack.dynamic.requests.only"=>true, "rack.version"=>[1, 1], "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "rack.input"=>#<JRuby::RackNonRewindableInput:0x6bcf8de2>, "rack.errors"=>#<JRuby::Rack::ServletLog:0x76c27ba @context=#<Java::OrgJrubyRackServlet::ServletRackContext:0x3956f14c>>, "rack.url_scheme"=>"http", "java.servlet_request"=>#<#<Class:0x138b72ce1>:0x2e807f85>, "java.servlet_context"=>#<Java::OrgJrubyRackServlet::ServletRackContext:0x3956f14c>, "jruby.rack.version"=>"1.1.0.dev", "jruby.rack.jruby.version"=>"1.6.2", "jruby.rack.rack.release"=>"1.2", "CONTENT_TYPE"=>"application/x-www-form-urlencoded", "CONTENT_LENGTH"=>"20", "REQUEST_METHOD"=>"POST", "SCRIPT_NAME"=>"", "REQUEST_URI"=>"/post", "PATH_INFO"=>"/post", "QUERY_STRING"=>"", "SERVER_NAME"=>"localhost", "SERVER_SOFTWARE"=>"Google App Engine Development/1.5.1", "REMOTE_HOST"=>"127.0.0.1", "REMOTE_ADDR"=>"127.0.0.1", "REMOTE_USER"=>"", "SERVER_PORT"=>"8080", "HTTP_HOST"=>"localhost:8080", "HTTP_CONNECTION"=>"keep-alive", "HTTP_REFERER"=>"http://localhost:8080/", "HTTP_CACHE_CONTROL"=>"max-age=0", "HTTP_ORIGIN"=>"http://localhost:8080", "HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30", "HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "HTTP_ACCEPT_ENCODING"=>"gzip,deflate,sdch", "HTTP_ACCEPT_LANGUAGE"=>"en-US,en;q=0.8", "HTTP_ACCEPT_CHARSET"=>"ISO-8859-1,utf-8;q=0.7,*;q=0.3"} | |
request post: {} | |
request: #<Rack::Request:0x1be0799a @env={"jruby.rack.dynamic.requests.only"=>true, "rack.version"=>[1, 1], "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "rack.input"=>#<JRuby::RackNonRewindableInput:0x6bcf8de2>, "rack.errors"=>#<JRuby::Rack::ServletLog:0x76c27ba @context=#<Java::OrgJrubyRackServlet::ServletRackContext:0x3956f14c>>, "rack.url_scheme"=>"http", "java.servlet_request"=>#<#<Class:0x138b72ce1>:0x2e807f85>, "java.servlet_context"=>#<Java::OrgJrubyRackServlet::ServletRackContext:0x3956f14c>, "jruby.rack.version"=>"1.1.0.dev", "jruby.rack.jruby.version"=>"1.6.2", "jruby.rack.rack.release"=>"1.2", "CONTENT_TYPE"=>"application/x-www-form-urlencoded", "CONTENT_LENGTH"=>"20", "REQUEST_METHOD"=>"POST", "SCRIPT_NAME"=>"", "REQUEST_URI"=>"/post", "PATH_INFO"=>"/post", "QUERY_STRING"=>"", "SERVER_NAME"=>"localhost", "SERVER_SOFTWARE"=>"Google App Engine Development/1.5.1", "REMOTE_HOST"=>"127.0.0.1", "REMOTE_ADDR"=>"127.0.0.1", "REMOTE_USER"=>"", "SERVER_PORT"=>"8080", "HTTP_HOST"=>"localhost:8080", "HTTP_CONNECTION"=>"keep-alive", "HTTP_REFERER"=>"http://localhost:8080/", "HTTP_CACHE_CONTROL"=>"max-age=0", "HTTP_ORIGIN"=>"http://localhost:8080", "HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30", "HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "HTTP_ACCEPT_ENCODING"=>"gzip,deflate,sdch", "HTTP_ACCEPT_LANGUAGE"=>"en-US,en;q=0.8", "HTTP_ACCEPT_CHARSET"=>"ISO-8859-1,utf-8;q=0.7,*;q=0.3", "rack.request.form_input"=>#<JRuby::RackNonRewindableInput:0x6bcf8de2>, "rack.request.form_hash"=>{}, "rack.request.form_vars"=>""}> | |
request params: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.jruby.rack; | |
// ... | |
public class RubyFirstRackFilter implements Filter { | |
// ... | |
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | |
throws IOException, ServletException { | |
RequestCapture reqCapture = new RequestCapture((HttpServletRequest) request); | |
ResponseCapture respCapture = new ResponseCapture((HttpServletResponse) response); | |
RackEnvironment env = new ServletRackEnvironment(reqCapture, context); | |
RackResponseEnvironment responseEnv = new ServletRackResponseEnvironment(respCapture); | |
System.out.println("parameter map: " + request.getParameterMap()); | |
printStream(request.getInputStream()); | |
request.setAttribute(RackEnvironment.DYNAMIC_REQS_ONLY, Boolean.TRUE); | |
dispatcher.process(env, responseEnv); | |
if (respCapture.isError()) { | |
reqCapture.reset(); | |
response.reset(); | |
chain.doFilter(reqCapture, response); | |
} | |
} | |
private void printStream(InputStream stream) { | |
System.out.println("Printing body..."); | |
try { | |
BufferedReader br = new BufferedReader(new InputStreamReader(stream)); | |
String line; | |
while ((line = br.readLine()) != null) { | |
System.out.println("line: " + line); | |
} | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
System.out.println("Done printing body"); | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment