Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Sockets and Internet Protocols and the fly likes Pass on HTTP request to external server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Pass on HTTP request to external server" Watch "Pass on HTTP request to external server" New topic

Pass on HTTP request to external server

Laurence Prescott

Joined: Mar 25, 2011
Posts: 2
We are trying to work out how to pass on a request to an external server and catch the response in code.
The situation is this:
Most users need authenticating against AD, but some we'll handle differently.
Our server doesn't have access into our corporate domain so can't authenticate users against Active Directory.
We have been supplied with an aspx page on another server that will do this authentication then redirect the client back to our server with their username in the query string.
Currently we check any new requests, and if we have not yet authenticated the user we use a response.sendRedirect() call to pass them on to the authenticating server.

The problem is this: if the authenticating server's authentication fails, it sends a message back to the client that makes no sense to the user and they can't access our web site. In this case we'd like to handle this (failed) user differently, but have no way of knowing of the authentication failure.
So basically we would like to pass on the original request to the authenticating server and catch the response.
If the response is an authentication challenge we need to pass this back to the client (to facilitate the authorization mechanism).
If the response is a redirection back to our server we know the user is okay and can serve them what they need.
If the response is the failure message we want to do something else.

Is this possible or is it not allowed due to security risks.

We are running Tomcat5 on Windows 2000 Server.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

You can use the classes in (notably URL and URLConnection) or a library such as HttpClient.

[Asking smart questions] [About Bear] [Books by Bear]
Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

And welcome to the Ranch!

How To Ask Questions How To Answer Questions
Laurence Prescott

Joined: Mar 25, 2011
Posts: 2
Bear and Rob,
Greetings and thanks for the welcome.
Sorry about the slow response (how rude!).
I've was pulled of this task for the moment but will let you know any results I achieve.

Nice to be part of the ranch.
I agree. Here's the link:
subject: Pass on HTTP request to external server
It's not a secret anymore!