title: How to call servlet from java
body: <p>I've a third-party servlet inside a JAR that I cannot change. I've extended that servlet and been using it normally as a servlet should be used, the client side makes an HTTP request that invokes my servlet.</p>
  
  <p>But now the client wants an automatic service, that is, I will need to do some requests to that third party servlet from the same webapp where the servlet is.</p>
  
  <p>I looked at the the third party servlet code but I didn't found a place to bypass the servlet because the HttpServletRequest and HttpServletResponse objects are passed from method to method... Basically it seems that I would need to re-implement all the third party code.</p>
  
  <blockquote>
    <p>Solutions I found but do not satisfy me:</p>
    
    <p><strong>Call servlet from URL with HttpURLConnection:</strong> My common sense says that calling the third party servlet from a url is not the best way to
    go, besides the overhead added, I don't want to expose the third party
    servlet. Calling my servlet from a url also brings problems with
    sessions and other things.  </p>
    
    <p><strong>Call the doGet directly:</strong> This seems to be out of the question because there is no implementation for the HttpServletRequest and
    HttpServletResponse.</p>
    
    <p><strong>Use jMock or something like that:</strong> Didn't explore this solution yet, but it seams wrong to use a test-driven library in the real
    environment.</p>
  </blockquote>
  
  <p>Anyone has an idea how to interact with that third party servlet?</p>
  
  <p>EDIT:</p>
  
  <p>Since my English is not very good and I'm finding difficult to explain myself here goes a schematic to try to explain better</p>
  
  <p><img src="https://i.stack.imgur.com/GlaXr.png" alt="Schematic"></p>
  
  <p>EDIT2: After a meeting the third party maker they offer to isolate the methods I need to avoid calling the servlet. If you don't have the same luck I did check out both <em>gigadot</em> and <em>BalusC</em> answers.</p>