wood burning stoves 2.0*
The moose likes Servlets and the fly likes Adding a customized header to an HTTP request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Adding a customized header to an HTTP request" Watch "Adding a customized header to an HTTP request" New topic
Author

Adding a customized header to an HTTP request

David Michell
Greenhorn

Joined: Sep 15, 2008
Posts: 4
Hi all,

Does anyone know of a way to add a custom header to an HTTP request?

My situation is that I'm trying to get Single Sign-on working between an SAP portal and the Adobe Connect product. Adobe Connect can be configured to have the user's id (which has been authenticated by my separate program) passed to it in a developer-specified header field.

I have (I think) sufficient documentation to do the authentication part of the process however I can't figure out how to add the user ID (once I've determined it) to a custom header field in a request to the Adobe Connect login URL.

Anyone know how I'd go about doing this?

Thanks in advance,
David

PS I realize using something other than a header would be easier but I'm constrained by the requirements of the Adobe Connect package that I'm working with.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41046
    
  43
Welcome to JavaRanch.

What kind of software is it that sends the HTTP request? A browser? Java code of yours? Some 3rd party software?


Ping & DNS - my free Android networking tools app
David Michell
Greenhorn

Joined: Sep 15, 2008
Posts: 4
It'll be the user's browser coming via my Java code.

The scenario that I'm envisioning is that the user has logged into our SAP portal and gone through the standard authentication process there. They then hit a link within the portal to go to Adobe Connect. That particular link actually sends them to my servlet which checks that they're authenticated (using a Java package made available by SAP), extracts their user ID, adds it to the necessary custom header field and then forwards the request on to the Adobe Connect login page.

Alternatively I may need to create a new request within my servlet with the custom header added. I then parse the response from Adobe Connect verifying the login is successful and getting the appropriate session cookie. I think return that session information back to the user and redirect them to the Adobe Connect home page.

(as you can tell I'm still in the process of investigating how this is going to work, unfortunately I've fallen at the first hurdle because of the difficulty of adding information into a custom header in a request)

PS Thanks for the welcome.
[ September 15, 2008: Message edited by: David Michell ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41046
    
  43
You can't add headers when forwarding or redirecting a browser request. It's possible to set custom headers if you create your own (Http)URLConnection, though, like you mention for the alternative approach.
David Michell
Greenhorn

Joined: Sep 15, 2008
Posts: 4
Originally posted by Ulf Dittmer:
... It's possible to set custom headers if you create your own (Http)URLConnection, though, like you mention for the alternative approach.


That sounds promising. I've had a look at the javadocs for the HttpUrlConnection class though and I can't find any methods for adding headers (only for getting them). Could you point me in the direction of some documentation and/or code that I could follow to do this?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41046
    
  43
Have a look at e140 here; it shows the opposite (retrieving headers).

Setting them is done using the addRequestProperty and setRequestProperty methods.
Ravindra Verma
Greenhorn

Joined: Sep 16, 2008
Posts: 8
Adding custom headers are possible in case you send an AJAX request. Other it's browser's work to create HttpRequest object using http protocol and we can't interfere in this process. Instead of doing all this you better use cookies to send that userId, or use url rewriting.
David Michell
Greenhorn

Joined: Sep 15, 2008
Posts: 4
Originally posted by Ulf Dittmer:
Setting them is done using the addRequestProperty and setRequestProperty methods.


Does that therefore mean that Headers and RequestProperties are the same thing?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41046
    
  43
Yes.
Dlse Sertz
Greenhorn

Joined: Sep 17, 2008
Posts: 2
Did you get the solution?

I've spent half a day trying to solve SSO HTTP Header type access to an Adobe LC Workspace (web app). I can confirm-test it to work using Modify Headers Firefox plugin.

My plan was to create a servlet, where I would navigate with my browser... the servlet would modify httpservletrequest (adding http header parameter user=someuser) and navigate to Workspace site using modified httpservletrequest.

Can you please elaborate?


Thank you
Anu Jacob
Greenhorn

Joined: Jul 16, 2013
Posts: 1
Hi Dlse,
I have the same scenario like yours, ie to add http header to a request sent to adobe live cycle. Could you please tell me how you could solve this.

Would really appreciate your reply in this matter.

Thanks and regards,

Anu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding a customized header to an HTTP request
 
Similar Threads
How to set custom HTTP REQUEST HEADER
Anyone know how to generate a HttpServletRequest with Headers?
adding listeners
Doubt about header
Set Request Header in a web application