Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Headers

 
Sege Stephen
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sege Stephen
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this is more about String parsing than servlets, I'm going to move it to our Java In General (Intermediate) forum.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done with with String.split()...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic