This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Getting Headers 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 » Java in General
Bookmark "Getting Headers" Watch "Getting Headers" New topic
Author

Getting Headers

Sege Stephen
Ranch Hand

Joined: Oct 06, 2007
Posts: 51
Hi Guys, I am working on an application, which i am new to. This application is going to be integrated with other applications. The main portal where my application is going to be integrated with already provide things like the user in Context and the other details associated with the user.

What I need to do is to write the code in my application, which will get these headers from the portal.

�AccountID: �CurrentLocale: � UserId: � Email: � Login Name:
�User Name:


I understand I have to do it using

String header = request.getHeader (�CSP-User-Info�);

From this header one has to search for the above keys and fetch their corresponding values programmatically.

How do I go about doing this, and where do this code go in my application. All help and comments are appreciated. I need it to produce something like this

CSP-User-Info: AccountID=12345, CurrentLocale=en, UserId=200, Email=abc@step.com, Login Name=6007000, User Name=Xyz
Akshay Kiran
Ranch Hand

Joined: Aug 18, 2005
Posts: 220
Are you saying that all the key-value pairs are available as the value of the CSP-... header?
Assuming this is the case, all you need to do is, parse the String using the regex classes and print them out.
As for "Where do I do this", it depends on where this data is going to be available and where all do you need it printed.
if its only this page,
just put the code in the same place where you get the headers (I assume you're doing it in one of the doXxx or process methods)
[ October 06, 2007: Message edited by: Akshay Kiran ]

"It's not enough that we do our best; sometimes we have to do<br />what's required."<br /> <br />-- Sir Winston Churchill
Sege Stephen
Ranch Hand

Joined: Oct 06, 2007
Posts: 51
Hello Guys, I was able to get the string and then I had to break it down using String tokenizer. The value I want at this time is the one stored in String f4 which is the value of the user ID.

I need this f4 in another part of my code , how do I get it.



public class Tokens {



StringTokenizer token1;

String x = "AccountID=250387,Login%u0020Name=sampath,UserId=79";
token1 = new StringTokenizer(x,"=");
String f1 = token1.nextToken();
String f2 = token1.nextToken();
String f3 = token1.nextToken();
String f4 = token1.nextToken();



Now I have tried doing something like this in another class

public void setF4(String f4){
this.f4=f4;
}

public String getF4(){
return f4;
}

then I created a new instance of the class Tokens, but it doesn't work.

How do I retrieve and use this value stored in f4 in a another class.

Very easy, but I can't do it. Thanks for your help.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Since this is more about String parsing than servlets, I'm going to move it to our Java In General (Intermediate) forum.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I've done with with String.split()...


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting Headers
 
Similar Threads
Issue with passing expression to a hashmap key in a dataTable column
Action Class
Anyone know how to generate a HttpServletRequest with Headers?
Getting a Key and Value from a string
About Headers