• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to pass a string as http header info

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic