on 11-14-2007 6:51 AM
The HttpGetterCallback can be used to fetched a specific header from a request, for example:
HttpGetterCallback cb = new HttpGetterCallback();
cb.setType(HttpCallback.HEADER);
cb.setName("Content-Type");
... pass to callback handler ...
String value = (String) cb.getValue();
But what if I wanted to get all the headers in a request? Or all the request parameters? Is there a way to do this?
Hi,
Check this
http://help.sap.com/saphelp_47x200/helpdata/en/6c/5da94fdd594791bc0f6bfdfad4d36e/content.htm
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the link.
I have already read that page and it only shows how to get the value of a specific header (in this example, "address").
I would like to get all the header fields in a request, rather than a particular header.
For example:
// Create a callback that gets all headers.
HttpGetterCallback cb = new HttpgetterCallback();
cb.setType(HttpCallback.HEADER);
... the callback is handled ...
// Log all headers found in the request.
String[] headers = (String[]) cb.getValue();
for (int i = 0; i < headers.length; i++) {
log("Request contains header: " + header);
}
I tried not setting a name in a HEADER callback as per the above example but got a NullPointerException within the callback handler.
So is it possible to fetch all headers or request parameters, without knowing their names?
Geoff
You are correct.It is possible and in fact advisable to retreive header information
without specifically asking for each of them.
this can be done in any standard jsp or servlet code.
Heres the code snippet and it should do the job for you:
<H1>Reading Header Information</H1>
Here are the request headers and their data:
<BR>
<% java.util.Enumeration names = request.getHeaderNames();
while(names.hasMoreElements()){
String name = (String) names.nextElement();
out.println(name + ":<BR>" + request.getHeader(name) + "<BR><BR>");
}
%>
-
For reading all the request parameters in one shot here's the code snippet:
String title = "Reading All Request Parameters";
out.println(ServletUtilities.headWithTitle(title) +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=CENTER>" + title + "</H1>\n" +
"<TABLE BORDER=1 ALIGN=CENTER>\n" +
"<TR BGCOLOR=\"#FFAD00\">\n" +
"<TH>Parameter Name<TH>Parameter Value(s)");
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
out.println("<TR><TD>" + paramName + "\n<TD>");
String[] paramValues = request.getParameterValues(paramName);
if (paramValues.length == 1) {
String paramValue = paramValues[0];
if (paramValue.length() == 0)
out.print("<I>No Value</I>");
else
out.print(paramValue);
} else {
out.println("<UL>");
for(int i=0; i<paramValues.length; i++) {
out.println("<LI>" + paramValues<i>);
}
out.println("</UL>");
}
}
out.println("</TABLE>\n</BODY></HTML>");
-
In fact this is the approach more or less all the frameworks and struts etc use to
populate the Action Classes and similar code.
Hope this solves your problem.
P.S. Please award points for useful answers.
Thanks for the information regarding using HttpServletRequest in jsp or servlet code.
However, I am writing a custom login module that (to my knowledge) has no access to HttpServletRequest instances.
The only way to get HTTP header information seems to be via the HttpGetterCallback class. This class allows fetching specific headers, but not (to my knowledge) fetching all headers. Similarly for request parameters.
Essentially, what I am trying to do is create a HttpServletRequest object within the login module (the authentication library that I am using requires this). I was hoping I could implemet the HttpServletRequest interface using the HttpGetterCallback class, but implementing request.getHeaderNames() seems impossible.
Unless there is some way of obtaining the HttpServletRequest directly within the login module?
> Unless there is some way of obtaining the HttpServletRequest directly within the login module?
HttpServletRequest can be obtained using the Webcallback callback, but this is only available when the login module is invoked via the portal.
For a login module invoked via normal Netweaver AS Java, it does not appear possible to get a list of HTTP headers.
User | Count |
---|---|
76 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.