Hi Tim

I need to open an HTTP connection to register1.asp. HTTP FormA on the client
used to talk directly to Register1.asp. For various reasons, Register1.asp
cannot be changed. There is now a need to "intercept" the form data, check
it against our ERP system and depending upon the response of the ERP system
I need to change some of the data originally submitted and then forward it
to Register1.asp, which still needs to see the incoming data as if it were
submitted via a Form. So now FormA calls my servlet when the form is
submitted, the servlet does the neccassary and now I need to pass the
amended form data to Register1.asp.

Because I can't ( or haven't found a way to ) change the form data and
bundle it in the original request data, I can't use a RequestDispatcher,
hence the need to open a URL connection and write to Register1.asp. I also
need to recieve Register1.asp's response and forward that back to the
original requesting client.

I've actually got this working by specifying the absolute path to
Register1.asp when creating a URL object but this means I need two versions
of the servlet, one for our test system and one for our production system
which run on different hosts. What I'm trying to do is to have one servlet
that uses a relative path to Register1.asp and create an HTTP URL
connection.

The original code looks like;

            URL url = new
URL("http://TestServer/Application/cgibin/Register1.asp";);
            urlConnection = (HttpURLConnection)url.openConnection();
            urlConnection.setDoInput(true);
            urlConnection.setDoOutput(true);
            urlConnection.setRequestMethod("POST");

urlConnection.setRequestProperty("Content-Type","application/x-www-form-urle
ncoded");

            BufferedWriter bw = new BufferedWriter(new
OutputStreamWriter(urlConnection.getOutputStream()));

The URL path relates to the wwwroot of our IIS web server. I can move
Register1.asp if needed, but I need to end up with a relative path that
either points back into the wwwroot hierarchy of our web server or points to
a path relative to the WEB-INF structure under which the servlet sits and
gives me an HTTP connection.

I hope this makes it clear what I'm trying to do.

Regards
Roger

> -----Original Message-----
> From: Chen, Gin [mailto:[EMAIL PROTECTED]]
> Sent: 20 March 2002 16:00
> To: [EMAIL PROTECTED]
> Subject: Re: Your Message Sent on Tue, 19 Mar 2002 15:35:33 -0000
>
>
> Hey Roger,
>         Sorry, unfortunately it doesnt work that way.
> When you get a resource for a page, it gives you the source
> of that page,
> not the actual results of it.
> From servlet 2.3 specs:
>
>         "These methods are not used to obtain dynamic
> content. For example,
> in a
>         container supporting the JavaServer PagesTM
> specification1, a method
> call of the
>         form getResource("/index.jsp") would return the JSP
> source code and
> not the
>         processed output. See Chapter SRV.8, "Dispatching
> Requests" for more
>         information about accessing dynamic content."
>
> I have used in my code:
>         URL url = getServletContext().getResource("/flow.xml");
>       URLConnection conn = (URLConnection) url.openConnection();
>       InputStream in = conn.getInputStream();
> This, however, reads the actual source of the resource.
>
> To actually get the dynmaic content of it, you might consider
> not using
> getResource and simply using the net package.
> You might look at sample code for Applet/Servlet
> communication to find out
> more.
> http://java.sun.com/docs/books/tutorial/networking/urls/index.html
>
> Also, depending on what you need to do, it might be
> sufficient to use the
> include method of the requestDispatcher.
> -Tim
>
> -----Original Message-----
> From: Varley, Roger [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, March 20, 2002 10:40 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Your Message Sent on Tue, 19 Mar 2002 15:35:33 -0000
>
>
> >
> >
> > You can only go back to the root of your project when using
> > getResource
> >
> > For the servlet 2.3 specs:
> >
> >         "The getResource and getResourceAsStream methods take
> > a String with
> > a
> >         leading "/" as argument which gives the path of the resource
> > relative to the root of
> >         the context. This hierarchy of documents may exist in
> > the server's
> > file system, in a
> >         web application archive file, on a remote server, or
> > at some other
> > location."
> >
> > As you can see beginning with the / is a requirement.
> >
> > for mine, i use getServletContext().getResource("/flow.xml");
> > This refers to the /flow.xml in my root directory.
> > If your Register1.asp is not in the root directory or its
> > subfolders then
> > you need to move it.
>
> Hi,
>
> Thanks for your response. I've tried that and moved the
> register1.asp file.
> The code now looks like;
>
>                 ServletContext sc = config.getServletContext();
>             url = sc.getResource("/register1.asp");
>             System.out.println(url.toString());
>
> I must be missing something obvious though because now the
> problem is that
> getResource() is returning a file:// url not an Http url so
> when I try to
> open the connection, the servlet crunches again.  The system
> prints the
> content of the URL as
file:e:\tomcat\webapps\Application\register1.asp. I
need an HTTP connection.

Regards
Roger

************************************************************************
Information in this message is confidential and may be privileged.  It is
for the exclusive use of the intended recipient(s).  If you are not the
intended recipient(s) please notify the sender and delete the message
immediately.  Unauthorised disclosure, distribution and copying of this
email is strictly prohibited.  The opinions expressed within this message
are those of the individual author.  Whilst Brake Bros takes reasonable
steps to scan this email it does not accept liability for any virus that may
be contained in it.
Bros Foodservice Limited, Enterprise House, Eureka Business Park, Ashford,
Kent TN25 4AG.
Registered in England and Wales number 706764.
Telephone 01233 206000 Fax 01233 206006.

___________________________________________________________________________
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

___________________________________________________________________________
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

************************************************************************
Information in this message is confidential and may be privileged.  It is
for the exclusive use of the intended recipient(s).  If you are not the
intended recipient(s) please notify the sender and delete the message
immediately.  Unauthorised disclosure, distribution and copying of this
email is strictly prohibited.  The opinions expressed within this message
are those of the individual author.  Whilst Brake Bros takes reasonable
steps to scan this email it does not accept liability for any virus that may
be contained in it.
Bros Foodservice Limited, Enterprise House, Eureka Business Park, Ashford,
Kent TN25 4AG.
Registered in England and Wales number 706764.
Telephone 01233 206000 Fax 01233 206006.

___________________________________________________________________________
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

Reply via email to