> From: "Michael Mehrle" <[EMAIL PROTECTED]> > Sent: Wednesday, May 18, 2005 8:58 AM
> - Servlet issues https request to an outside server (via > getServletContext().getRequestDispatcher(https://www.someoutsideserver/) ) > - Outside server processes request and responds with POST response (also via > https). > - Servlet [somehow] is able to be the recipient of the response. > - Servlet parses the response and stores data to the database. Your problem is with the whole model. There is no reason why a Servlet can't send an HTTP(S) request to another server. But the server that you are making the request shouldn't be making an independent POST back to you, rather it should just send you the data you want back as the reply body. You then parse the reply and move on. IF you insist that the "reply" be in the manner of a POST from the other server (really really silly IMHO), then, simply, you need to make the request to the other server be the last thing your Servlet does. Then when the POST comes back, you pick up where you left off, tracking your state through a request parameter. So, your Servlet may start with a request like: http://otherserver.com/processData?mysession=123&stage=1 Then the otherserver replies with a POST to: http://yourserver.com/yourServlet?mysession=123&stage=2 You use the mysession information to maintain your state between requests. But the key is that your servlet ends each time, and Tomcat then restarts it when the POST comes back. It's still a silly idea. You don't need Webservices, SOAP, XML-RPC, etc to talk to another server via HTTP. You can easily stream serialized Java objects to each other if you want, use the simple Java Properties file format for your responses, etc. I think if you have control over both servers, "WEB RPC" can be very simple for a limited domain. If you don't have control over the other server, then you do what you have to do. I mean, seriously: public class AddNumberServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); String arg1 = request.getParameter("arg1"); String arg2 = request.getParameter("arg2"); int i1 = Integer.parseInt(arg1); int i2 = Integer.parseInt(arg2); int result = i1 + i2; out.println("answer=" + result); } } public class RequesterServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); URL reqURL = new URL("http://otherserver/AddNumberServlet?arg1=2&arg2=4); Properties result = new Properties(); result.load(reqURL.openStream()); String answer = result.get("answer"); out.println("<HTML><BODY>When you add up 2 and 4 you get " + answer + "</BODY></HTML>"); } } There. Instant "web service". Error checking and robustness are left as an exercise for the reader, but you can see that you don't need a 500 page book to get some data from another web server. Not to discount the XML-RPC and SOAPs, they have their place most certainly. No doubt XML-RPC started just like this and grew from there (and then into SOAP), but its just a simple example of how easy this can be when you have control over the whole shebang. Regards, Will Hartung ([EMAIL PROTECTED]) --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
