Discussions

EJB design: Servlet to Servlet communication which are in diff web servers

  1. Hi!
    I am santosh. I need example code and theory for the following issue. One of my servlet is residing in the tomcat server. One of my page is calling this servlet and I need to pass this request and response to the other servlet which is running in another Webserver. Can any body help in this issuue.please clarify me how they work in different servers context.I am so much thank ful if anybody gives me a solution with example..
    regards
    santosh
  2. Servlet Spec says Servlet Context will work between the apps within the server only.
  3. for example:

    String url="http://172.16.0.1:7001/TranPro/Tran3800";
    URL url = new URL(Url);
    HttpURLConnection connection =(HttpURLConnection) url.openConnection();
    connection.setRequestMethod("GET");
    connection.setDoOutput(true);
    OutputStreamWriter ostream = new OutputStreamWriter(connection.getOutputStream());
              if(buffer!=""){
    BufferedWriter out = new BufferedWriter(ostream);
    //out.write(buffer);
    out.flush();
    out.close();
    }

    InputStream stream = connection.getInputStream();
    BufferedInputStream in = new BufferedInputStream(stream);
    time=System.currentTimeMillis();
    int i = 0;
    while ((i = in.read()) != -1) {
    System.out.write(i);
    }
                            in.close();
                            connection.disconnect();
  4. Thank you very much,
    I will try with this code accords to my application. That means i have to create a url connection object and set the url parameters.thank you very much.I hope that you will help me in the following problem
    I have one more problem
    We have one security server and application server. In security server the servlet handles the request from the client. It is authenticated and if success occurs it redirects the request to application server. Whenere I need to write a program which should serve the security server request. It has to receive the request and process and send it back to the security server and the security server will return the response to the client depending on his role. The communication between security server and application server should have to use rmi protocol. what programs do i need to develop..if i write socket programming in appserver...or is there any other solution to solve this problem..please reply to me asap. as i need to solve this issue on an emergency base.
    if possible please give me one example or resource addresses.
    i will be so much thank ful
  5. As Viswa said, directly passing the request and response to a servlet in a different server won't work.

    The most straightforward form of servlet-engine-to-servlet-engine communication is to have your first servlet invoke the remote servlet as an normal HTTP client, for example using the java.net.URL and java.net.URLConnection classes.
  6. Thank you very much for the solution. Can you give me some of the site names or resouce names so i can quickly go through the code.I hope that you will help me inthe following problem...
    We have one security server and application server. In security server the servlet handles the request from the client. It is authenticated and if success occurs it redirects the request to application server. Whenere I need to write a program which should serve the security server request. It has to receive the request and process and send it back to the security server and the security server will return the response to the client depending on his role. The communication between security server and application server should have to use rmi protocol. what programs do i need to develop..if i write socket programming in appserver...or is there any other solution to solve this problem..please reply to me asap. as i need to solve this issue on an emergency base.
    if possible please give me one example or resource addresses.
    i will be so much thank ful
    regards
    santosh
  7. // In your servlet:
    URL url = new URL("http://>/RemoteServlet?request-data");
    URLConnection con = url.openConnection();
    con.connect();

    // To process the response:
    InputStream is = (InputStream) con.getContent();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line = br.readLine();
    while (line != null) {
      System.out.println(line);
      line = br.readLine();
    }
    br.close();
  8. test comment[ Go to top ]

    Soory I am putting a junk mesg >pls ignore this