Another solution that fully implements ServletContextProvider and does not extend StrutsPortlet was contributed to the Portals-Bridges Jira instance by Edgar P. Dollin (see http://issues.apache.org/jira/browse/PB-30?page=all). This one and the following solution has been tested with Pluto version 1.0.1.

This was contributed by Sunil Patil to the pluto-users mail list

Hi, I am able to deploy Struts portlet developed using Apache's Portal Bridges Struts Framework on Pluto. I tried some basic test cases and it works. If someone thinks that being able to develop Struts Portlet for Pluto is useful and is willing to add this code in pluto repository please let me know i will cleanup these classes and create how to document In order to get it working you should create a simple PlutoStrutsPortlet.java class and use it in your portlet.xml file like this. You will also need PlutoServletContextProvider.class file in your classpath. Please take a look at this code listing

1) PlutoStrutsPortlet.java

import javax.portlet.GenericPortlet;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletResponse;
import org.apache.pluto.core.impl.PortletConfigImpl;
import org.apache.portals.bridges.struts.StrutsPortlet;
public class PlutoStrutsPortlet extends StrutsPortlet{
 protected HttpServletRequest getHttpServletRequest(GenericPortlet portlet, PortletRequest request, PortletResponse response) {
     HttpServletRequest httpServletRequest =(HttpServletRequest) request.getAttribute(" javax.portlet.request");
     return httpServletRequest;
 }
 protected HttpServletResponse getHttpServletResponse(GenericPortlet portlet, PortletRequest request, PortletResponse response) {
     HttpServletResponse httpServletResponse =(HttpServletResponse)request.getAttribute(" javax.portlet.response");
     return httpServletResponse;
 }
 protected ServletContext getServletContext(GenericPortlet portlet, PortletRequest request, PortletResponse response) {
     PortletConfigImpl portletConfigImpl =(PortletConfigImpl)request.getAttribute("javax.portlet.config ");
     ServletContext servletContext = portletConfigImpl.getServletConfig().getServletContext(); 
  return servletContext;
 }
}

2) PlutoServletContextProvider.java

import javax.portlet.GenericPortlet;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletResponse;
import org.apache.portals.bridges.common.ServletContextProvider;
public class PlutoServletContextProvider implements ServletContextProvider{
    public ServletContext getServletContext(GenericPortlet portlet){
     //Empty place holder
     System.err.println("Please use PlutoStrutsPortlet instead of StrutsPortlet");
     return null;
    }
    public HttpServletRequest getHttpServletRequest(GenericPortlet portlet, PortletRequest request){
     //Empty place holder 
     System.err.println("Please use PlutoStrutsPortlet instead of StrutsPortlet"); 
     return null;
    }
    public HttpServletResponse getHttpServletResponse(GenericPortlet portlet, PortletResponse response){
     //Empty place holder
     System.err.println("Please use PlutoStrutsPortlet instead of StrutsPortlet"); 
     return null;
    }
}

3) Inside your portlet.xml file use PlutoStrutsPortlet as portlet class and add these two initialization parameter

 <init-param>
            <name>ServletContextProvider</name>
            <value>com.sample.util.PlutoServletContextProvider</value>
 </init-param>
 <init-param>
            <name>ViewPage</name>
            <value>/index.jsp</value>
 </init-param> 

4) Make sure that your web.xml file contains definition for org.apache.portals.bridges.struts.PortletServlet servlet.

Pluto/UsingStrutsBridgeWithPluto (last edited 2009-09-20 23:46:33 by localhost)