* @return Request information includes the http header and other information parsed by
* servlet container from a servlet request
*/
@SuppressWarnings("unchecked")
public HttpRequest getRequestInfo(HttpServletRequest request) {
HttpRequest requestInfo = new org.jboss.soa.esb.http.HttpRequest();
requestInfo.setAuthType(request.getAuthType());
requestInfo.setCharacterEncoding(request.getCharacterEncoding());
requestInfo.setContentType(request.getContentType());
requestInfo.setContextPath(request.getContextPath());
requestInfo.setLocalAddr(request.getLocalAddr());
requestInfo.setLocalName(getLocalName(request));
requestInfo.setMethod(request.getMethod());
requestInfo.setProtocol(request.getProtocol());
requestInfo.setQueryString(request.getQueryString());
requestInfo.setRemoteAddr(request.getRemoteAddr());
requestInfo.setRemoteHost(request.getRemoteHost());
requestInfo.setRemoteUser(request.getRemoteUser());
requestInfo.setContentLength(request.getContentLength());
requestInfo.setRequestSessionId(request.getRequestedSessionId());
requestInfo.setRequestURI(request.getRequestURI());
requestInfo.setScheme(request.getScheme());
requestInfo.setServerName(request.getServerName());
requestInfo.setRequestPath(request.getServletPath());
String pathInfo = request.getPathInfo();
requestInfo.setPathInfo(pathInfo);
if(pathInfo != null) {
List<String> pathInfoTokens = requestInfo.getPathInfoTokens();
pathInfoTokens.addAll(Arrays.asList(request.getPathInfo().split("/")));
// remove empty tokens...
Iterator<String> tokensIterator = pathInfoTokens.iterator();
while(tokensIterator.hasNext()) {
if(tokensIterator.next().trim().length() == 0) {
tokensIterator.remove();
}
}
}
// Http Query params...
Map paramMap = request.getParameterMap();
if(paramMap != null) {
requestInfo.getQueryParams().putAll(paramMap);
}
// Http headers...
Enumeration enumeration = request.getHeaderNames();
while (enumeration.hasMoreElements()) {
String name = (String) enumeration.nextElement();
String value = request.getHeader(name);
requestInfo.getHeaders().add(new HttpHeader(name, value));
}
return requestInfo;
}