Follow the following steps
1) Create Filter classes
package com.filter;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
public class ParameterFilter implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
ServletRequestParameters.set(request.getParameterMap());
// forward the wrapped request to the next filter in the chain
if (chain != null){
chain.doFilter(request, response);
}
ServletRequestParameters.set(null);
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}
package com.filter;
import java.util.HashMap;
import java.util.Map;
public class ServletRequestParameters {
private static ThreadLocal tl = new ThreadLocal() {
protected Object initialValue() {
return new HashMap();
}
};
public static Map getAll() {
return (Map)tl.get();
}
static void set(Map params) {
tl.set(params);
}
public static String getParameter(String key) {
String[] values = (String[])getAll().get(key);
if (values != null && values.length > 0) {
return values[0];
}
return null;
}
public static String[] getParameters(String key) {
return (String[])getAll().get(key);
}
public static String getParameter(String key, String defaultValue) {
String value = getParameter(key);
if (value == null) {
value = defaultValue;
}
return value;
}
}
2) Create the jar file of above classes and put it in portal shared dir e.g ../shared/app
3) Register these filter in WPS web.xml. The location web.xml varies by portal version. make sure you find out correct location.
4) Access the parameter in Portlet
package com.portal.
import java.io.IOException;
import javax.portlet.*;
import com.alltel.filter.ServletRequestParameters;
public class TestPortlet extends com.ibm.faces.portlet.FacesPortlet {
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
String phoneId =ServletRequestParameters.getParameter("phoneId");
System.out.println("name phoneId :"+phoneId);
request.setAttribute("phoneId", phoneId);
super.doView(request, response);
}
}
No comments:
Post a Comment