I am trying to get a Java Servlet logged into an extranet system, pull down search results, and logout. However, I keep getting weird results. First I get a MUE when I first login, what I found out is the server takes the login form and send the results to another URL as parameters. Now, the forwarding URL string gets flagged as an MU exception. However, just to get past it, I did a real no-no and put code in the exception to then forward to the real URL with the parameters. OK, it looks as if I get in, then I set up the search parameters, headers and the cookies and when I execute the sendGetRequest, 8 out of 10 times nothing happens, but 2 times out of 10, I get a socket error. I have tried to catch anything I can think of but nothing works. Any ideas?
Here's the code: try { resServlet.tools.writeLog("Entering site"); URL url1 = new URL("http", "www.extranetsite.com", "/client_login.asp"); //login HttpMessage lmsg = new HttpMessage(url1); Properties lprops = new Properties(); resServlet.tools.writeLog("Starting Login"); Cookie[] lcookies = request.getCookies(); if (lcookies!= null) { for (int i=0; i < lcookies.length; i++) { cname = lcookies<i>.getName(); cvalue = lcookies<i>.getValue(); resServlet.tools.writeLog("Cookies: " + cname +" ," + cvalue); if (cname.equals("JSESSIONID")) {jsession=cvalue; resServlet.tools.writeLog("JSESSIONID" + jsession);} } } lprops.put("username","[EMAIL PROTECTED]"); lprops.put("password","secret"); lprops.put("action", "submit"); lprops.put("Log+in.x", "43"); lprops.put("Log+in.y", "6"); lmsg.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; YComp 5.0.0.0; .NET CLR 1.0.3705)"); lmsg.setHeader("Host", "www.extranetsite.com^J"); lmsg.setHeader("Content-Type", "application/x-www-form-urlencoded"); lmsg.setHeader("Referer", "http://www.extranetsite.co m/client_login.asp"); lmsg.setHeader("Accept" , "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"); lmsg.setHeader("Accept-Language", "en-us"); lmsg.setHeader("Connection", "Keep-Alive"); lmsg.setHeader("Content-Length", "84"); lmsg.setHeader("Pragma", "no-cache"); lmsg.setCookie("USERID", "Bob+Smith"); lmsg.setCookie("CJGUID", "1c87826bd8884acb861a0c906107d073"); lmsg.setCookie("JSESSIONID", cvalue); resServlet.tools.writeLog("Set Parms: "); try { InputStream out = lmsg.sendPostMessage(lprops); } catch (SocketException e) { // Can't connect to host, report it and abandon the broadcast resServlet.tools.writeLog("Can't connect to host: " + e.getMessage()); } catch (FileNotFoundException e) { // Servlet doesn't exist, report it and abandon the broadcast resServlet.tools.writeLog("Resource not found: " + e.getMessage()); } catch (MalformedURLException e) { resServlet.tools.writeLog("MUE: " + e.getMessage()); URL url12 = new URL("http", "www.extranetsite.com", "/client2.asp?userID=1138346&username=bob%40whatever%2Ecom" ); //login HttpMessage lmsg2 = new HttpMessage(url1); lmsg2.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; YComp 5.0.0.0; .NET CLR 1.0.3705)"); lmsg2.setHeader("Host", "www.extranetsite.com^J"); lmsg2.setHeader("Content-Type", "application/x-www-form-urlencoded"); lmsg2.setHeader("Referer", "http://www.extranetsite.co m/client_login.asp"); lmsg2.setHeader("Accept" , "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"); lmsg2.setHeader("Accept-Language", "en-us"); lmsg2.setHeader("Connection", "Keep-Alive"); lmsg2.setHeader("Content-Length", "84"); lmsg2.setHeader("Pragma", "no-cache"); lmsg2.setCookie("RECRUITER", "Bob+Smith"); lmsg2.setCookie("CJGUID", "1c87826bd8884acb861a0c906107d073"); lmsg2.setCookie("JSESSIONID", jsession); resServlet.tools.writeLog("Set Parms2: "); InputStream out = lmsg2.sendPostMessage(); } catch (IOException e) { resServlet.tools.writeLog("Http Post Failed!: " + e.getMessage()); } catch (Exception e) { // Some other problem, report it and abandon the broadcast resServlet.tools.writeLog("General exception: " + e.getClass().getName() + ": " + e.getMessage()); } resServlet.tools.writeLog("Sent Login"); //Get cookies Cookie[] cookies = request.getCookies(); if (cookies!= null) { for (int i=0; i < cookies.length; i++) { cname = cookies<i>.getName(); cvalue = cookies<i>.getValue(); resServlet.tools.writeLog("Cookies: " + cname +" ," + cvalue); if (cname.equals("CJSESSION")) { cjsession = cvalue; } if (cname.equals("RECRUITER")) { recruiter = cvalue; } if (cname.equals("ASP.NET_SessionId")) { aspnet = cvalue; } if (cname.equals("CLIENT")) { client = cvalue; } if (cname.equals("CJGUID")) { cjguid=cvalue; } if (cname.equals("JSESSIONID")) {jsession=cvalue;} } } else { resServlet.tools.writeLog("No Cookies!"); } } catch(Exception e) { resServlet.tools.writeLog("Extranet Login Failed: "+e); } String extranetsurl = "http://www.extran etsite.com/client/SearchStandard.asp"; URL url = null; try { url = new URL(extranetsurl); } catch (MalformedURLException e) { resServlet.tools.writeLog("BAD URL: " + extranetsurl); } HttpMessage msg = null; try { msg = new HttpMessage(url); } catch (Exception e) { resServlet.tools.writeLog("Extranet HTTP Failed: "+e); } // Parameters may optionally be set using java.util.Properties Properties props = new Properties(); props.put("errdirect", "searchstandard.asp"); props.put("legendtype", "1"); props.put("searchtype", "NEW"); props.put("log_event", "1"); props.put("keywords", keywords); props.put("match_section", "whole"); props.put("days", "90"); props.put("zipcode", ""); props.put("city", city); props.put("city_state", state); props.put("perpage", "100"); // Headers, cookies setting msg.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; YComp 5.0.0.0; .NET CLR 1.0.3705)"); msg.setHeader("Host", "www.employers.computerjobs.com^J"); msg.setHeader("Content-Type", "application/x-www-form-urlencoded"); msg.setHeader("Referer", "http://www .extranetsite.com/client/SearchStandardResults.cfm"); msg.setHeader("Accept" , "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"); msg.setHeader("Accept-Language", "en-us"); msg.setHeader("Connection", "Keep-Alive"); msg.setHeader("Content-Length", "222"); msg.setHeader("Pragma", "no-cache"); msg.setCookie("JSESSION", jsession); msg.setCookie("CLIENT", "sid=9889187&uid=1138346&cid=461732"); // msg.setCookie("ASP.NET_SessionId", aspnet); // msg.setCookie("USERID", recruiter); // msg.setCookie("CLIENT", client); // msg.setCookie("CJGUID", cjguid); // msg.setCookie("CJSESSION", cjsession); resServlet.tools.writeLog("Props Set for Search"); try { // InputStream out = msg.sendPostMessage(props); InputStream in = msg.sendGetMessage(props); resServlet.tools.writeLog("Search Post"); ObjectInputStream result = new ObjectInputStream(in); obj = result.readObject(); } catch (ClassNotFoundException e) { resServlet.tools.writeLog("Result Class Not Found!"); } catch (SocketException e) { // Can't connect to host, report it and abandon the broadcast resServlet.tools.writeLog("Can't connect to host: " + e.getMessage()); } catch (FileNotFoundException e) { // Servlet doesn't exist, report it and abandon the broadcast resServlet.tools.writeLog("Resource not found: " + e.getMessage()); } catch (MalformedURLException e) { resServlet.tools.writeLog("Search MUE: " + e.getMessage()); } catch (IOException e) { resServlet.tools.writeLog("Http Message Failed!: " + e); } catch (Exception e) { resServlet.tools.writeLog("Extranet Search Failed!: "+ e.getMessage()); } } resServlet.tools.writeLog("response from search:" + obj.toString()); return; Any ideas? Any thing for me to try? Ross ___________________________________________________________________________ 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