5 Replies Latest reply: Jun 22, 2009 12:05 AM by EJP RSS

    Use Apache HTTPClient and log on, then transfer flow to browser

    807588
      In a website, I need to log on and then navigate to a page where an applet loads. I then to upload a file to that applet, which then zips it up and sends to the server.

      I am building a swing desktop application that prepares the content to load to the server. To make it easy for the user, I would like the user to just prepare the content and with a click of a button, transfer the content to the clipboard. After which, I'll log on to the website and open the page that has the applet on it. He then needs to do a Ctrl+V on that applet and the content will go to the database.

      Using Apache HTTP Client I have logged on to the website. After this, I understand, that I cannot go any further, because of the applet. So I need to transfer the logged on session to the browser - Internet Explorer or Firefox, which ever is the system default. How do I do that? Any ideas?

      I know this is not the correct design. I dont have access to direct calls to the server via APIs or the web services it might be using. I understand that if the website changed due to any reason, this wont work... Blah Blah Blah..

      But still, is there a way to do this?
        • 1. Re: Use Apache HTTPClient and log on, then transfer flow to browser
          807588
          What limitations does the applet provide?

          If possible, may I see the code for the 'logging in' to the web site?

          http://hc.apache.org/httpclient-3.x/tutorial.html
          • 2. Re: Use Apache HTTPClient and log on, then transfer flow to browser
            807588
            The code is a bit big and I keep getting scolded for posting long code. The code is present in the examples directory when you download httpclient. Its called ClientFormLogon. Its pretty simple actually, you first go to the address you want to log on using a get method request. Then you analyse the form on the webpage and make sure you simulate it exactly, by populating all the name value pairs.. Then call the post method with those name value pairs and voila you are logged in.
            You might want to read this, it gives a thorough understanding of what httpclient is.

            http://wiki.apache.org/jakarta-httpclient/ForAbsoluteBeginners#head-93d0

            What did you mean by
            su_penguin wrote:
            What limitations does the applet provide?
            Actually another thought occured to me, instead of going to the applet page, why dont I simulate what the applet is doing and call the servlet that the applet calls. But I dont know the URL to that servlet! Any thought?

            Edited by: Sethu.R on Jun 21, 2009 6:30 PM
            • 3. Re: Use Apache HTTPClient and log on, then transfer flow to browser
              793415
              >
              ..
              Actually another thought occured to me, instead of going to the applet page, why dont I simulate what the applet is doing and call the servlet that the applet calls. But I dont know the URL to that servlet! Any thought?>
              Wireshark or a high trace level in the Java Console might tell you that information.
              • 4. Re: Use Apache HTTPClient and log on, then transfer flow to browser
                807588
                I tried doing the tracing thing.. Hell I downloaded the jars for that applet from the website, but it looks a bit like reinventing the wheel to me. The website already offers a lot, I would just like to supplement it rather than replace it. Isn't there a way I could invoke the browser after logging in?
                The server is using cookies to track the session. Cant I somehow feed that to the browser?
                • 5. Re: Use Apache HTTPClient and log on, then transfer flow to browser
                  EJP
                  You don't need the browser. Just construct the URL required, set the method to POST if necessary, write the arguments, get the response, all in the applet. That's all the browser does.