title: How to emulate HttpServletRequest, HttpServletResponse and ServletContext?
body: <p>I've a method that uses <code>HttpServletRequest</code>, <code>HttpServletResponse</code> and <code>ServletContext</code>.
  Here's my code:</p>
  
  <pre><code>public String processarModelo(MyObject ou, Map&lt;String, Object&gt; attrs,
              Map&lt;String, Object&gt; params) throws Exception {
  
  
          ServletContext sc = com.opensymphony.webwork.ServletActionContext.getServletContext();
          HttpServletResponse r = com.opensymphony.webwork.ServletActionContext.getResponse();
          MyHttpRequest rw = new MyHttpRequest(com.opensymphony.webwork.ServletActionContext.getRequest());
          rw.clearAttributes();
  
          for (String s : attrs.keySet()) {
              rw.setAttribute(s, attrs.get(s));
          }
  
          Map&lt;String, String&gt; p = rw.getParameterMap();
          p.clear();
          for (String s : params.keySet()) {
              p.put(s, (String) params.get(s));
          }
  
          ByteArrayOutputStream bout = new ByteArrayOutputStream();
          Writer w = new OutputStreamWriter(bout);
          SwallowingHttpServletResponse r2 = new SwallowingHttpServletResponse(r, w, "iso-8859-1");
  
          javax.servlet.RequestDispatcher dispatcher = sc.getRequestDispatcher("/paginas/expediente/processa_modelo.jsp");
  
          dispatcher.include(rw, r2);
          w.flush();
          String s = bout.toString();
  
  
          return s;
      }
  </code></pre>
  
  <p>It's working when I call it from my browser.
  This week I've built a webservice that must call the same method. Inside the webservice method I have however no <code>ServletContext</code>, <code>HttpServletResponse</code> and <code>HttpServletRequest</code> at hands.</p>
  
  <p>How can I emulate them to render my JSP and get the generated HTML?</p>