How to 'tunnel' requests/response with servlet?

Hallo!
I have the following problem.
Tomcat is used as ServletEngine. Here should work a servlet for authorization. The web application resides on another webserver.
After authorization all request go to Tomcat where a servlet should get (via HTTP) the HTML-pages from the other webserver and sends them to the client. The customer wants to act the Tomcat as Server to the client and as client to the other webserver. For me it seems to be some kind of proxy functionality.
How can I achieve this?
Kind regards
Jochen

Hi,
I am currently writing almost the same thing. And I have a partial success with something like ProxyServlet. What it does:
1. creates a URL object
2. creates HttpURLConnection through the URL
3. copies servlet's request parameters to the HttpURLConnection's request
4. copies the HttpURLConnection's response to the servlet's response
It works, but it is very - very slow.
I am currently struggling with the Keep-Alive feature in HTTP 1.1 that the remote server sends. If I copy that header onto the response, the client sends another request to the same channel, that is mean while broken - the servet is used only by one to one.
I am trying to find something like URL Connection pool, but still I am not successful. I am going to try not to trasfer the Keep-Alive headers to the client - perhaps this sort of downgrading Http 1.1 to 1.0 will limit the timeout delays ...
Did you succeed in your work ?
Ales

Similar Messages

  • How to redirect request to a servlet on another server/context

    Hi
    I want to redirect a request came to a servlet to another servlet on another server or atlest different context on same server.
    Thanks in advance,
    --Nagesh                                                                                                                                                                                                                                                                                                                               

    Thanks but, now after rediriceting the request I am
    not getting any ServletInputStream. Getting rintime
    error as NoClassDefinitionFoundError :
    ServletInputStream.That's indicative of a problem with your classpath settings.
    DO I have to do anything the JSP
    (which submitted the request to first servlet) after
    redirecting?Nops, you shouldnt do anything after sendredirect(). The response is committed after using this method.
    ram.

  • How to deploy an app with servlet and background processing

    i have a servlet with background processing. it has to run 24 hours a day.
    but i have problem with shutdown (after 1-2 hours without user action). [9iAS 9.0.3.0, windows 2000]
    i created for application seperate OC4J (in the EM) and i deployed it there. first time as war file, later as ear file (because there is possible to re-deploy only ear file).
    but it seems that the servlets are not designated to run as a uninterruptible task.
    the question is: how to deploy such (servlet + uninterruptible background processing) application in the 9iAS?
    a) everything in the OC4J (then how to disable shutdown?)
    b) servlet in the OC4J. where (and how) to install the rest of application?
    b1) servlet in the OC4J + rmi/soap/... + standalone server?
    what is the standard in the oracle world :) ?
    thanks

    Better to post your topic in the iPad in the Enterprise community.
    This is the, "Using Mac App Store" forum and for the most part for troubleshooting the App Store.

  • How to implement request/response domain in JMS

    hi friends,
    I need help regarding implementing request/response domain
    in jms.please help me.

    See the TopicRequestor and QueueRequestor helper classes in the JMS API.
    FWIW there's a POJO based request/response implementation using JMS here...
    http://lingo.codehaus.org
    you might find the source code useful as it does efficient request/response in a highly concurrent way using JMS under the covers.
    James
    http://logicblaze.com/

  • Simulate multiple request / response with a HTTP URL

    I need to communicate with a servlet. In the first request, the user gets authenticated and a connection is created. Now I need to use this connection to send further requests since all requests undergo an authentication check.
    However, when I try to implement the same, the second time I write to the output stream of the connection, I get the following exception:
    java.net.ProtocolException: Cannot write output after reading input.
    Please help! I need to create an application which communicates with this Servlet in the specified way

    Now I need to use this connection to send
    further requests since all requests undergo an
    authentication check.That's not how HTTP works. For each request, you have
    to make a new connection. And as for authentication,
    it's perfectly feasible for you to do the
    authentication for every single request, but (at
    least in the case of basic authentication) browsers
    tend to send an Authorization header once they have
    done the original authentication dialogue. You could
    do that too.Also, underneath it all, HTTP 1.1 tries to maintain a socket connection so you don't have that overhead to deal with each time. But as DrClap says, you need to use fresh HTTP instances each time and set the appropriate session/authentication headers.

  • How to use EAServer Jaguar with servlets?

    I have a web application that I have done using Tomcat and now need to run it with EAServers Jaguar. I am currently going through EAServer 5.2 documentation and the tutorial for creating a simple java application seems rather tedious ( have to use EAServers manager to create packages and components etc).
    Can anyone out there with experience tell me if going through the entire EAServer documentation will help me configure the server for servlets n jsp or is there an easier way to do things? Is it possible for me to just export my whole Web Application folder to some location in EAServer directories and run it like we do in Tomcat?
    I cant seem to find much help or tutorials on the net... Thanks for any help!!

    Ive found a few sources that uses PowerJ IDE to create WAR files to deploy in EAServers Manager. I tried creating a HelloWorld WAR without any IDE but cant seem to deploy it in EAServer Manager.
    Can anyone give some advice??

  • How can my applet communicate with servlet via HTTPS?

    hi all,
    I'm using jdk1.4.2_03. Tomcat 4.1.27/29.
    My applet used to communicate to serlvet/JSP via http protocol. However, I wish to apply SSL in my tomcat standalone. Is there any implication towards my existing applet to servlet codes?
    For example,
    URL servletURL = new URL("http://www.myhost.com/Shopping");
    // open connection between applet and servlet
    URLConnection servletConnection = servletURL.openConnection();
    servletConnection.setDoOutput(true); // allow connection do output
    servletConnection.setDoInput(true); // allow connection do input
    servletConnection.setUseCaches(false);
    servletConnection.setRequestProperty("Content-Type", "application/octet-stream");
    ObjectInputStream input = new ObjectInputStream(servletConnection.getInputStream());
    resultset = (Vector)input.readObject(); //get Object from Servlet
    input.close();

    http://java.sun.com/j2se/1.4.2/docs/api/javax/net/ssl/HttpsURLConnection.html
    I never used it though, you can check for some code here:
    http://javaalmanac.com/cgi-bin/search/find.pl?words=HttpsURLConnection

  • How to use Oracle Procedures with Servlet page

    Hi all
    I'm working on Servlet pages and I need to insert and select some records from Oracle database but it has to be done by calling some already written Procedures. I've never really used them before so I'm little lost. I know where the queries are used it'll be Procedures but what is the syntax for it.Can anyone put me in right direction please.
    Thanks

    Just google it. You will find lots of examples. Here are some :
    [http://java.sun.com/docs/books/tutorial/jdbc/basics/sql.html|http://java.sun.com/docs/books/tutorial/jdbc/basics/sql.html]
    [http://onjava.com/pub/a/onjava/2003/08/13/stored_procedures.html|http://onjava.com/pub/a/onjava/2003/08/13/stored_procedures.html]

  • How to use JNI with Servlets

    Hi
    i was trying to do some example with JNI. I can use JNI with standalone Java application but I just cannot figure out how I can use JNI with Servlet.
    Can some one show me a sample code using JNI with Servlets.
    thanks very much

    hi,
    I am also facing the same problem,
    when I am using JNI with stand alone application it works fine but when i tried to use it with a servlet It gives unsatisfied linker error
    stack: java.lang.UnsatisfiedLinkError: createSocket
         at RelayConnector.createSocket(Native Method)
         at RelayServlet.doGet(RelayServlet.java:70)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java:891)
         at com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:458)
    It seems i have to do some path settings in my iplenet web server.
    If some one have faced the problem i would be glad to know the solution for this, i am literally bugged up,....

  • Request Response Receive Port and Solicit Response Send Port

    Can anyone give me some idea how to bind Request Response Receive Port and Solicit Response Send Port with each other through TCP/IP adapter ??

    The binding of a Receive and Send Port has nothing to with the choice of Adapter.
    1) There is no out-of-the-box TCP/IP Adapter for BizTalk, but several 3rd. Party Adapters has been made, along with this one in CodePlex: http://tcpipbz2010.codeplex.com/
    2) Most people will use an Orchestration for binding a SR Send Port to a RR Receive Port. This may not be necessary though. All you need to do is have your Send Port subscribe to your Receive Port (by setting the Filter on the Send Port to "BTS.ReceivePortName
    == [The name of your Receive Port]". In this case, internal correlation will make sure that the response is routed back to the Receive Port.
    Morten la Cour

  • Swings with servlets

    Hi,
    how we can use swings with servlets or jsps.
    or
    how we can display the browser in the swings.
    please give me a valid answer with examples.

    Hi,
    Your question is not clear... are you trying to display HTML using swing components or are you trying to use swing in a server-side application?
    Some Swing components (e.g. JLabel) natively support simple html, so:
    JLabel lbl = new JLabel("<html>hello <b>world</b></html>");would result in a JLabel that looks with the word "world" in bold. If you need also frames, css and javascript support - you'll need to reach for a 3^rd^ party library, I'm afraid.
    As for using swing in servers, look at this article:
    http://today.java.net/pub/a/today/2006/04/20/bringing-swing-to-the-web.html
    If you meant neither, please explain more.
    Hope this helps, though.
    Michael Bar-Sinai

  • Using forward(request, response) in Java Servlet

    Hi
    I need help on how to use the forward() method in a java servlet passing a List object and riderecting to another jsp.
    when I use the following code;
    request.getRequestDispatcher(path).forward(request, response);
    I'm getting this message:
    Content modified /content...
    Status
    200
    Message
    OK
    Location
    /content...
    Parent Location
    /content
    Path
    /content...
    Referer
    Thanks,

    Looking at your traces seems like you are forwarding during POST. Seems like issue with your component implementation missing with POST & proxy scripts. Please eloborate more on the exact steps you are following. Alternatively See if this helps.
    org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper req =
    new org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper(slingRequest) {
    public String getMethod() {
    return "GET";
    String path = "/content/.../test.html";
    javax.servlet.RequestDispatcher dispatcher = slingRequest.getRequestDispatcher(path);
    dispatcher.include(req, slingResponse);

  • How do i track clicks with jsp/servlets?

    I would like to know how to imitate the click of link in JSP or serlvet, in order to track clicks.
    I have pages with links containing tel protocol URIs like this:
    Click here to listen!
    I want to replace the above with something like this:
    Click here to listen!
    And have call_tracking.jsp do its tracking stuff and then spawn a phone call, just like the first example does. I do not want to bother the user with another page, hence the need to accomplish the click action programmatically. I presume this feat is achievable via Response header magic, I just don't know the right incantation ;-)
    Thanks

    You should create a servlet to track the links, let´s say LinkTracker. Here I have an example for you. Each link calls a servlet and pass the url as a parameter.
    <html>
      <head>
        <title>Some Links Tracked by the LinkTracker Servlet</title>
      </head>
      <body>
      Some good links for you. Each link is directed
      through the LinkTracker Servlet. Click on a few and visit
      the <a href="LinkTracker">LinkTracker Servlet</a>.
      <ul>
        <li><a href="LinkTracker?link=http://www.google.com">
          Google Site</a></li>
        <li><a href="LinkTracker?link=http://www.yahoo.com">
          Yahoo site</a></li>
        <li><a href="LinkTracker?link=http://java.sun.com">
          Sun Microsystems</a></li>
      </ul>
      </body>
    </html>And here the code to LinkTracker servlet
    public class LinkTracker extends HttpServlet {
      static private Hashtable links = new Hashtable();
      String tstamp;
      public LinkTracker() {
        tstamp = new Date().toString();
      public void doGet(HttpServletRequest request,
                        HttpServletResponse response)
        throws IOException, ServletException {
        String link = request.getParameter("link");
        if (link != null && !link.equals("")) {
          synchronized (links){
            Integer count = (Integer) links.get(link);
            if (count == null) {
              links.put(link, new Integer(1));
            else {
              links.put(link, new Integer(1+count.intValue()));
          //here the servlet redirect the client to the link he clicked
          response.sendRedirect(link);
        else {
          response.setContentType("text/html");
          PrintWriter out = response.getWriter();
          request.getSession();
          out.println("<html>");
          out.println("<head>");
          out.println("<title>Links Tracker Servlet</title>");
          out.println("</head>");
          out.println("<body>");
          out.println("<p>Links Tracked Since");
          out.println(tstamp+":</p>");
          if (links.size() != 0) {
            Enumeration enum = links.keys();
            while (enum.hasMoreElements()) {
              String key = (String)enum.nextElement();
              int count = ((Integer)links.get(key)).intValue();
              out.println(key+" : "+count+" visits<br>");
          else {
            out.println("No links have been tracked!<br>");
          out.println("</body>");
          out.println("</html>");
      public void doPost(HttpServletRequest request,
                        HttpServletResponse response)
        throws IOException, ServletException {
        doGet(request, response);
    }

  • How to Modify Data in a Servlet Response

    Hi..
    I have a servlet that upon receving an http request from client sends some data to the client browser, but i want to modify the data that is being sent to the client and resend it somehow (like its a kind of bypassing...without sending the original data..i want to modify the data and send the response ON THE FLY.
    Any ideas of suggestions how to do it, if some one of you has already done it then pls do send some code snippet.
    Thanx in advance
    mark.

    Aha... now the truth comes out. You asked how to do it, but your secret question was that you were already doing it and you were having some problems. It's generally just better to come out and ask the question, even though it may be embarrassing that what you did isn't working.
    To me, what you did sounds like a perfectly good method, except that writing the data to a temp file is going to run you into problems as soon as you get two requests at about the same time. I would do that in memory instead (write to a ByteArrayOutputStream, get the resulting array of bytes, modify it, and write the end result out to the servet response's output stream).
    The problem you describe, though, is probably caused because the browsers are caching requests to your servlet. Do you have something like this code in your servlet that tells the browsers not to cache it?response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");

  • How can I know whether the Servlet is sending a response!!!

    Hello,
    My question is this :
    How do I know whether that server outputstream is sending me a response or not?
    I have opened the Client InputStream to recieve a response from a servlet,but how
    can i be sure that i will receive a response from the servlet?
    I cud be waiting for an 15 expecting a response but havent received one..
    Is there any way to check whether the servlet is sending me a response?
    The reason I am asking is this.
    I have written a Java Client that connects to a servlet.It has to wait for a
    response from the servlet.It will wait for 5 seconds and if this doesnt recieve
    a response,it will return back else it will display the response.
    I have set a timer on my client for 5 seconds and a timer on the servlet for 15 seconds.
    Essentially,when the client connects,the servlet response is held for 15 seconds
    and the client tries for 5 seconds.
    But the client is unable to exit without a response.The response comes back in 15 seconds.
    The client shud have the message 'Connection Timed Out' after 5 seconds.
    This means there is an error somewhere.
    As the response takes 15 seconds,the client shudnt recieve one.
    So,is there a way I can block the servlet response?
    I am using threads and Inner classes for the timer purposes..
    Please can any one help me?
    ajay
    Client code:
    public class HttpHandler {
    private static String sURL="localhost";
    static String sMessage="Hello Server..Client sending Data";
    static DataInputStream dis = null;
    static HttpURLConnection hpCon=null;
    public static void main(String[] args)
    sendData(sMessage);
    public void TimerTest() {
    NewThread nt = new NewThread();
    public static void sendData(String sMess)
    String response=null;
    try{
    // Invoke Timer
    new HttpHandler.TimerTest();
    URL url=null;
    String uri = "http://" + sURL + ":8080/servlet/threads.Recieve_Http_Data1";
    url = new URL(uri);
    hpCon=null;
    hpCon = (HttpURLConnection)url.openConnection();
    hpCon.setDoOutput(true);
    hpCon.setDoInput(true);
    // Transfer Data over http
    DataOutputStream dos = new DataOutputStream(hpCon.getOutputStream());
    dos.writeUTF(sMess);
    }catch(IOException e)
    {System.out.println("Error in Client " + e); e.printStackTrace();}
    } // End of Method sendData
    // Inner Class
    class NewThread extends Thread
    String response;
    int i=0;
    NewThread()
    start();
    public void run()
    try {
    while(i < 5)
    System.out.println(i);
    Thread.sleep(1000);
    try {
    dis = new DataInputStream(hpCon.getInputStream());
    response = dis.readUTF();
    // If response recieved, break off else Loop back.
    if(dis !=null)
    System.out.println("SERVER RESPONSE : " + response);
    dis.close();
    break;
    }catch(IOException e){System.out.println("Here : " + e);}
    i++;
    } // End of While.
    }catch(InterruptedException e){}
    The Servlet
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import java.io.*;
    import java.sql.*;
    import java.math.*;
    public class Recieve_Http_Data1 extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html";
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException
    doPost(request,response);
    public void doPost(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException
    System.out.println("Server Ready to receive Message from application :");
    System.out.println();
    BufferedReader br=null;
    // Data Read by the Servlet
    String sMess="";
    DataInputStream dis = new DataInputStream(request.getInputStream());
    sMess = dis.readUTF();
    System.out.println("Received from Client: " + sMess);
    // Send response back after 15 seconds Only.
    try {
    for(int i=0;i<15;i++)
    System.out.println(i);
    DataOutputStream dos = new DataOutputStream(response.getOutputStream());
    String sResponse = "Hello Client...This is server sending response";
    dos.writeUTF(sResponse);
    Thread.sleep(1000);
    }catch(InterruptedException e){}

    I don't know whether you solve your problem or not! Anyway, I have the same problem. The program hangs when getInputStream is called.
    DataInputStream dis = new DataInputStream(request.getInputStream());
    If you have the answer, please let me know. Thanks!!

Maybe you are looking for

  • Can't use Google. At all. Please help!

    A couple of days ago, I started having trouble using any Google applications or even loading the pages for them. I can't check my gmail, get on the iGoogle homepage, use the search bar in the browser, or even load www.google.com. At first I thought m

  • Field KONP-KONWA. does not exist in the screen SAPMV13A 0201

    Hi, We have one BDC program to change Material Inforecord through transaction ME12. We have executed the BDC and Batch input session got created. When i execute the session, it is giving error "Field KONP-KONWA. does not exist in the screen SAPMV13A

  • The PO was printed straight away without going through Release Strategy.

    Hello, Purchase order was raised in March for over Rs 1,000,000/- and went through the Release Strategy for printing. The value of this order was changed today - about Rs 7,000/- was added in the purchase order. The Purchase Order was printed straigh

  • Creating user account and setting password in Solaris9 through shell script

    I need to create and set password of user through shell scripts. User can be added successfully through "useradd" command but password cant be set through "passwd" command in script. Is there any other alternative for the same.

  • PSE 9: can't "get photos" from my scanner

    I'm running PSE 9 on a Mac using OS-10 Lion.  In Organizer, I try to get photos from my Epson Perfection V500 Photo scanner, but that option is not available in the drop down window.  I have installed all the Epson programs; Twain, Epson Scan, Event