jQuery in Action, 2nd edition*
The moose likes Web Services and the fly likes How to pass a string as http header info Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to pass a string as http header info" Watch "How to pass a string as http header info" New topic
Author

How to pass a string as http header info

Rahul Mark
Greenhorn

Joined: Apr 08, 2012
Posts: 2
Hi all,
I use REST service along with spring framework.
- I need to pass some info (say a string like username) as header to next class instead of putting the username in url like this :
order/module/{userName}
- The username cannot be in URL due to security issue.
- I tried using HttpServletRequest . But it has only getHeader() and no setHeader().
Can anyone help?
Thanks
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
- I need to pass some info (say a string like username) as header to next class


Are you talking about a whole new request or continuing with the same request?

If the client for this service is a browser, the usual method for passing information to subsequent requests in headers is one or more cookies.

Bill
Rahul Mark
Greenhorn

Joined: Apr 08, 2012
Posts: 2
Thanks for your reply.
-But the client is not a browser. The client is a java class which will change later to some external client.
-I even tried httpentity() but I could not figure it out properly.
-Because in httpentity, the header is attached to response object instead of request. So the header info is not going to THE controller from the
client, instead it is going back to the class that called the client.
Is there anyway I could attach the header to request object??
Thanks.
Ajoo Bar
Ranch Hand

Joined: Mar 28, 2011
Posts: 30
Hi Rahul,

DId you find a solution for this? I have a smilar requirement but it is for SOAP. My requirement is to have a basic authentication. When I opened a wsdl in SOAP UI this is what I have in header. Please let me know if you find any solution

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:polh="http://ws.pol.com/PolContractService/2012-01-03/Polservice_V1_0" xmlns:sec="http://ws.pol.com/IBC/2010-11-19/securitybasetype_V1" xmlns:mes="http://ws.pol.com/IBC/2010-11-19/messagecontextbasetype_V1" xmlns:man="http://ws.pol.com/PolService/2012-01-03/managecontractrequest_V1" xmlns:con="http://ws.pol.com/Common/2012-01-05/contractbasetype_V1">
<soapenv:Header>
<polh:headerContextParameters>
<securityContextParameters>
<sec:usernameToken>
<sec:userName>?</sec:userName>
<sec:password>?</sec:password>
</sec:usernameToken>
</securityContextParameters>
</polh:headerContextParameters>
</soapenv:Header>

Thanks"
Ajoo
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
If the client is a Java class under your control then you can put anything you want in the request HTTP headers.

See the documentation for java.net.URLConnection setRequestProperty()

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to pass a string as http header info
 
Similar Threads
SOAP authorization problem
is there a way to control header or tail info when printing by java script?
Referer Header information passed from the Login Jsp page
like keyword in sql
Getting a Key and Value from a string