Hello everybody! I have the following problem....
I have two servlets called "Servlet_A" and " Servlet_B". "Servlet_B" is running on an external Web Site and requests authentication to access to it, while "Servlet A" is mine and is running on my Web Site. When a user connects to Servlet_B from the Web Browser (using Servlet_B's URL, for example: http://www.domain.com/Servlet_B ) he must insert his login and password in a form "F" for identification. What I would like to do is to make to communicate Servlet_A and Servlet_B each other, implementing some "automatic identification procedure": that is to say when a user connects to my Web Site (and so to Servlet_A too) I use the login and the password he typed before to identify himself to connect to Servlet_B. Let's suppose that the login and the password to access to Servlet_A and Servlet_B are the same. I implemented the "automatic identification procedure" sending from Servlet_A to Servlet_B the same parameters present in form "F" (using POST method). At this point I have the following problem: Servlet_B requires not only the identification parameters present in the form but also that the user has the "Cookie support" enabled in his Web Browser and that he accepts a cookie after identification. In fact for every user Servlet_B create a session object where to store useful information about him. So if I connects to Servlet_B not from a Web Browser but from my Servlet_A I don't know how to simulate in Servlet_A the "cookie support" of the browser storing or reading the cookie that it is sent from ServletB to Servlet A. So Servlet_B believes that Servlet_A hasn't "cookie support" enabled and the identification procedure fails....in fact in this case Servlet_B can't create a session for Servlet_A!!! I want to point out that to connect to Servlet_B from Servlet_A I used the following piece of code (in ServletA): protected void doPost(HttpServletRequest request, HttpServletResponse response) { .. String UrlServlet_B=...; URL url = new URL(UrlServlet_B); HttpURLConnection Con = (HttpURLConnection)url.openConnection(); Con.setRequestMethod("POST"); //I encode the form parameters for identification: Login and Password. "LoginValue" and "PasswordValue" are the values of the Login and Password that the user already used to access to Servlet_A. String PostData="Login="+URLEncoder.encode(LoginValue)+"&Password="+URLEncoder.enco de(PasswordValue); Con.setDoInput(true); Con.setDoOutput(true); Con.setUseCaches(false); Con.setRequestProperty("Content-Length",""+PostData.length()); Con.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); //Now I sent the parameters in POST to Servlet_B DataOutputStream DataStream=new DataOutputStream(Con.getOutputStream()); DataStream.writeBytes(PostData); DataStream.flush(); DataStream.close(); //Now I read the HTML page returned by Servlet_B that contains the result of identification InputStream ins = Con.getInputStream(); BufferedReader In = new BufferedReader(new InputStreamReader(ins)); boolean Exit=false; String Page=""; while(!Exit ) { String line =null; try { line = In.readLine(); if (line==null) Esci=true; } catch (Exception Ex){ Exit=true;} if (line!=null) Pagina+=line; } } //Now I show the HTML page "Page" in the Web Browser of the user. PrintWriter Out=new PrintWriter(response.getOutputStream()); res.setContentType("text/html"); Out.println(risultato); Out.close(); Can someone help me? How can I implement the identification procedure passing from my Servlet_A and not directly from the Web Browser of the user? Is it possible to set and read cookies using an "HttpURLConnection" object and not "HTTPServletRequest" and HTTPServletResponse" objects (in fact when I open a direct connection these types of objects aren't available)? Thanks a lot in advance! Luca ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
