• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass a string as http header info

 
Rahul Mark
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- 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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic