portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlest...@apache.org
Subject svn commit: r209328 [2/14] - in /portals/jetspeed-2/trunk/components/portal: src/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jetspeed/ src/java/org/apache/jetspeed/aggregator/ src/java/org/apache/jetspeed/aggregator/impl/ src/java...
Date Tue, 05 Jul 2005 21:55:50 GMT
Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletContentImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletContentImpl.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletContentImpl.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletContentImpl.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.aggregator.impl;
+
+import java.io.CharArrayWriter;
+import java.io.PrintWriter;
+
+import org.apache.jetspeed.aggregator.PortletContent;
+
+
+public class PortletContentImpl implements PortletContent
+{
+    private CharArrayWriter cw;
+    private PrintWriter writer;
+    private boolean complete = false;
+
+    PortletContentImpl()
+    {
+        init();
+    }
+
+    public PrintWriter getWriter()
+    {
+        return writer;
+    }
+
+    public void init()
+    {
+        cw = new CharArrayWriter();
+        writer = new PrintWriter(cw);
+    }
+
+    public void release()
+    {
+        writer.close();
+    }
+
+    public String toString()
+    {
+        writer.flush();
+        return cw.toString();
+    }
+
+    public void writeTo( java.io.Writer out ) throws java.io.IOException
+    {
+        writer.flush();
+        cw.writeTo(out);
+    }
+
+    public char[] toCharArray()
+    {
+        writer.flush();
+        return cw.toCharArray();
+    }
+
+    public boolean isComplete()
+    {
+        return complete;
+    }
+
+    void setComplete( boolean state )
+    {
+        this.complete = state;
+    }
+    
+    public String getContent()
+    {
+        return toString();
+    }
+    /**
+     * <p>
+     * complete
+     * </p>
+     *
+     * @see org.apache.jetspeed.aggregator.PortletContent#complete()
+     * 
+     */
+    public void complete()
+    {
+       setComplete(true);
+    }
+}
\ No newline at end of file

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletRendererImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletRendererImpl.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletRendererImpl.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletRendererImpl.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,247 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.aggregator.impl;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.PortalReservedParameters;
+import org.apache.jetspeed.aggregator.ContentDispatcher;
+import org.apache.jetspeed.aggregator.ContentDispatcherCtrl;
+import org.apache.jetspeed.aggregator.FailedToRenderFragmentException;
+import org.apache.jetspeed.aggregator.PortletContent;
+import org.apache.jetspeed.aggregator.PortletRenderer;
+import org.apache.jetspeed.aggregator.UnknownPortletDefinitionException;
+import org.apache.jetspeed.components.portletentity.PortletEntityNotStoredException;
+import org.apache.jetspeed.container.window.FailedToRetrievePortletWindow;
+import org.apache.jetspeed.container.window.PortletWindowAccessor;
+import org.apache.jetspeed.om.page.ContentFragment;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.util.JetspeedObjectID;
+import org.apache.pluto.PortletContainer;
+import org.apache.pluto.om.common.ObjectID;
+import org.apache.pluto.om.entity.PortletEntity;
+import org.apache.pluto.om.window.PortletWindow;
+
+/**
+ * <h4>PortletRendererService <br />
+ * Jetspeed-2 Rendering service.</h4>
+ * <p>
+ * This service process all portlet rendering requests and interfaces with the
+ * portlet container to generate the resulting markup
+ * </p>
+ * 
+ * @author <a href="mailto:raphael@apache.org">Rapha�l Luta </a>
+ * @version $Id: PortletRendererImpl.java,v 1.30 2005/05/20 14:54:22 ate Exp $
+ */
+public class PortletRendererImpl implements PortletRenderer
+{
+    protected final static Log log = LogFactory.getLog(PortletRendererImpl.class);
+
+    private WorkerMonitor monitor;
+
+    private PortletContainer container;
+    private PortletWindowAccessor windowAccessor;
+
+    public PortletRendererImpl( PortletContainer container, PortletWindowAccessor windowAccessor )
+    {
+        this.container = container;
+        this.windowAccessor = windowAccessor;
+    }
+
+    public void start()
+    {
+        this.monitor = new WorkerMonitor();
+        this.monitor.init();
+    }
+
+    public void stop()
+    {
+        // this.monitor.shutdown ?
+    }
+
+    /**
+     * Render the specified Page fragment. Result is returned in the
+     * PortletResponse.
+     * 
+     * @throws FailedToRenderFragmentException
+     * @throws FailedToRetrievePortletWindow
+     */
+    public void renderNow( ContentFragment fragment, RequestContext requestContext )
+    {
+
+        HttpServletRequest servletRequest = null;
+        HttpServletResponse servletResponse = null;
+        ContentDispatcher dispatcher = null;
+        PortletWindow portletWindow = null;
+        
+        try
+        {
+            portletWindow = getPortletWindow(fragment);
+            ContentDispatcherCtrl dispatcherCtrl = getDispatcherCtrl(requestContext, true);
+            dispatcher = getDispatcher(requestContext, true);
+            servletRequest = requestContext.getRequestForWindow(portletWindow);
+            servletResponse = dispatcherCtrl.getResponseForWindow(portletWindow, requestContext);
+
+            RenderingJob rJob = buildRenderingJob(fragment, servletRequest, servletResponse, requestContext);
+            rJob.execute();
+
+        }
+        catch (Exception e)
+        {
+            fragment.overrideRenderedContent(e.toString());
+            log.error(e.toString(), e);
+        }
+    }
+
+    /**
+     * Render the specified Page fragment. Result is returned in the
+     * PortletResponse.
+     * 
+     * @throws FailedToRenderFragmentException
+     * @throws FailedToRetrievePortletWindow
+     */
+    public void renderNow( ContentFragment fragment, HttpServletRequest request, HttpServletResponse response )          
+    {
+
+        RequestContext requestContext = (RequestContext) request
+                .getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
+        ContentDispatcher dispatcher = getDispatcher(requestContext, true);
+        PortletWindow portletWindow = null;
+        
+        try
+        {
+            portletWindow = getPortletWindow(fragment);
+            ContentDispatcherCtrl dispatcherCtrl = getDispatcherCtrl(requestContext, true);
+            
+            HttpServletRequest servletRequest = requestContext.getRequestForWindow(portletWindow);
+            HttpServletResponse servletResponse = dispatcherCtrl.getResponseForWindow(portletWindow, requestContext);
+
+            RenderingJob rJob = buildRenderingJob(fragment, servletRequest, servletResponse, requestContext);
+            rJob.execute();
+        }
+        catch (Exception e)
+        {
+            fragment.overrideRenderedContent(e.toString());
+            log.error(e.toString(), e);
+        }
+    }
+
+    /**
+     * Render the specified Page fragment. The method returns before rendering
+     * is complete, rendered content can be accessed through the
+     * ContentDispatcher
+     * @throws FailedToRetrievePortletWindow
+     * 
+     * @throws UnknownPortletDefinitionException
+     * @throws FailedToRetrievePortletWindow
+     */
+    public void render( ContentFragment fragment, RequestContext requestContext )
+    {
+        PortletWindow portletWindow;
+        
+        ContentDispatcherCtrl dispatcherCtrl = getDispatcherCtrl(requestContext, true);
+        ContentDispatcher dispatcher = getDispatcher(requestContext, true);
+
+        HttpServletRequest servletRequest =null;
+        HttpServletResponse servletResponse = null;
+
+        try
+        {
+            portletWindow = getPortletWindow(fragment);
+            servletRequest = requestContext.getRequestForWindow(portletWindow);
+            servletResponse = dispatcherCtrl.getResponseForWindow(portletWindow, requestContext);
+            RenderingJob rJob = buildRenderingJob(fragment, servletRequest, servletResponse, requestContext);
+            monitor.process(rJob);            
+        }
+        catch (Exception e1)
+        {
+            servletRequest = requestContext.getRequest();
+            servletResponse = dispatcherCtrl.getResponseForFragment(fragment, requestContext);
+            log.error("render() failed: " + e1.toString(), e1);
+            fragment.overrideRenderedContent(e1.toString());            
+//            ObjectID oid = JetspeedObjectID.createFromString(fragment.getId());
+        //    ((ContentDispatcherImpl) dispatcherCtrl).notify(oid);
+        }
+
+    }
+
+    /**
+     * Retrieve the ContentDispatcher for the specified request
+     */
+    public ContentDispatcher getDispatcher( RequestContext request, boolean isParallel )
+    {
+        return (ContentDispatcher) getDispatcherCtrl(request, isParallel);
+    }
+
+    /**
+     * Retrieve the ContentDispatcherCtrl for the specified request
+     */
+    protected ContentDispatcherCtrl getDispatcherCtrl( RequestContext request, boolean isParallel )
+    {
+        if (request.getContentDispatcher() == null)
+        {
+            request.setContentDispatcher(new ContentDispatcherImpl(isParallel));
+        }
+
+        return (ContentDispatcherCtrl) request.getContentDispatcher();
+    }
+
+    protected PortletWindow getPortletWindow( ContentFragment fragment ) throws FailedToRetrievePortletWindow, PortletEntityNotStoredException
+    {
+
+            ObjectID oid = JetspeedObjectID.createFromString(fragment.getId());
+
+            PortletWindow portletWindow = windowAccessor.getPortletWindow(fragment);
+            if (portletWindow == null)
+            {
+                throw new FailedToRetrievePortletWindow("Portlet Window creation failed for fragment: "
+                        + fragment.getId() + ", " + fragment.getName());
+            }
+            PortletEntity portletEntity = portletWindow.getPortletEntity();
+
+            return portletWindow;
+
+    }
+
+    protected RenderingJob buildRenderingJob( ContentFragment fragment, HttpServletRequest request,
+            HttpServletResponse response, RequestContext requestContext ) throws FailedToRetrievePortletWindow,
+            FailedToRenderFragmentException, PortletEntityNotStoredException
+    {
+        ContentDispatcher dispatcher = null;
+        RenderingJob rJob;
+
+        PortletWindow portletWindow = getPortletWindow(fragment);
+        ContentDispatcherCtrl dispatcherCtrl = getDispatcherCtrl(requestContext, true);
+        dispatcher = getDispatcher(requestContext, true);        
+        request = requestContext.getRequestForWindow(portletWindow);
+        response = dispatcherCtrl.getResponseForWindow(portletWindow, requestContext);
+       
+        
+        request.setAttribute(PortalReservedParameters.PAGE_ATTRIBUTE, requestContext.getPage());
+        request.setAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE, fragment);
+        request.setAttribute(PortalReservedParameters.CONTENT_DISPATCHER_ATTRIBUTE, dispatcher);
+        request.setAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE, requestContext);        
+        request.setAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE, fragment);
+        
+        PortletContent portletContent = dispatcher.getPortletContent(fragment);
+        fragment.setPortletContent(portletContent);
+        return new RenderingJob(container, portletContent, fragment, request, response, requestContext, portletWindow);
+
+    }
+}

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/RenderingJob.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/RenderingJob.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/RenderingJob.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/RenderingJob.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.aggregator.impl;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.PortalReservedParameters;
+import org.apache.jetspeed.aggregator.PortletContent;
+import org.apache.jetspeed.om.page.ContentFragment;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.pluto.PortletContainer;
+import org.apache.pluto.om.window.PortletWindow;
+
+/**
+ * The RenderingJob is responsible for storing all necessary objets for
+ * asynchronous portlet rendering as well as implementing the rendering logic
+ * in its Runnable method.
+ *
+ * @author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
+ * @version $Id: RenderingJob.java 188558 2005-04-29 14:02:35Z weaver $
+ */
+public class RenderingJob implements Runnable
+{
+    /** Commons logging */
+    protected final static Log log = LogFactory.getLog(RenderingJob.class);
+
+    /** WorkerMonitor used to flush the queue */
+    private PortletWindow window = null;
+    private HttpServletRequest request = null;
+    private HttpServletResponse response = null;
+    
+    private PortletContainer container = null;
+    private ContentFragment fragment = null;
+    private RequestContext requestContext = null;
+
+    private PortletContent portletContent;
+    
+    public RenderingJob(PortletContainer container, PortletContent portletContent, ContentFragment fragment, HttpServletRequest request, HttpServletResponse response, RequestContext requestContext, PortletWindow window)
+    {
+        this.container = container;
+        
+        this.fragment = fragment;
+        this.request = request;
+        this.response = response;
+        this.requestContext = requestContext; 
+        this.window = window;
+        this.portletContent = portletContent;     
+        
+    }
+
+    /**
+     * Checks if queue is empty, if not try to empty it by calling
+     * the WorkerMonitor. When done, pause until next scheduled scan.
+     */
+    public void run()
+    {       
+        try
+        {
+            // A little baby hack to make sure the worker thread has PortletContent to write too.
+            fragment.setPortletContent(portletContent);
+            execute();                     
+        }
+        finally
+        {
+            
+            synchronized (portletContent)
+            {
+               log.debug("Notifying completion of rendering job for fragment " + fragment.getId());                
+               portletContent.notifyAll();
+            }
+        }
+    }
+    
+    /**
+     * <p>
+     * execute
+     * </p>
+     *
+     * 
+     */
+    protected void execute()
+    {
+        
+        try
+        {           
+            log.debug("Rendering OID "+this.window.getId()+" "+ this.request +" "+this.response);            
+            this.request.setAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE, fragment);
+            this.request.setAttribute(PortalReservedParameters.PAGE_ATTRIBUTE, requestContext.getPage());
+            this.request.setAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE, requestContext);
+          //  this.request.setAttribute(PortalReservedParameters.CONTENT_DISPATCHER_ATTRIBUTE,dispatcher);
+            container.renderPortlet(this.window, this.request, this.response);               
+            this.response.flushBuffer();                           
+        }
+        catch (Throwable t)
+        {
+            // this will happen is request is prematurely aborted            
+            log.error("Error rendering portlet OID " + this.window.getId(), t);
+            fragment.overrideRenderedContent(t.getMessage());
+        }
+        finally
+        {
+            portletContent.complete();
+        }
+
+    }
+
+    /**
+     * 
+     * <p>
+     * getWindow
+     * </p>
+     *
+     * @return The window this job is in charge of rendering
+     */
+    public PortletWindow getWindow()
+    {
+        return window;
+    }
+}
\ No newline at end of file

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/Worker.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/Worker.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/Worker.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/Worker.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,200 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.aggregator.impl;
+
+import java.security.AccessControlContext;
+import java.security.PrivilegedAction;
+
+import javax.security.auth.Subject;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Worker thread processes jobs and notify its WorkerMonitor when completed.
+ * When no work is available, the worker simply sets itself in a waiting mode
+ * pending reactivation by the WorkerMonitor
+ *
+ * @author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
+ * @version $Id: Worker.java 188142 2005-01-04 16:05:45Z weaver $
+ */
+public class Worker extends Thread
+{
+    /** Commons logging */
+    protected final static Log log = LogFactory.getLog(Worker.class);
+
+    /** Running status of this worker */
+    private boolean running = true;
+
+    /** Counter of consecutive jobs that can be processed before the
+        worker being actually put back on the idle queue */
+    private int jobCount = 0;
+
+    /** Job to process */
+    private Runnable job = null;
+
+    /** Context to process job within */
+    private AccessControlContext context = null;
+
+    /** Monitor for this Worker */
+    private WorkerMonitor monitor = null;
+
+    public Worker(WorkerMonitor monitor)
+    {
+        super();
+        this.setMonitor(monitor);
+        this.setDaemon(true);
+    }
+
+    public Worker(WorkerMonitor monitor, ThreadGroup tg, String name)
+    {
+        super(tg, name);
+        this.setMonitor(monitor);
+        this.setDaemon(true);
+    }
+
+    /**
+     * Return the number of jobs processed by this worker since the last time it
+     * has been on the idle queue
+     */
+    public int getJobCount()
+    {
+        return this.jobCount;
+    }
+
+    /**
+     * Reset the processed job counter
+     */
+    public void resetJobCount()
+    {
+        this.jobCount=0;
+    }
+
+    /**
+     * Sets the running status of this Worker. If set to false, the Worker will
+     * stop after processing its current job.
+     */
+    public void setRunning(boolean status)
+    {
+        this.running = status;
+    }
+
+    /**
+     * Sets the moitor of this worker
+     */
+    public void setMonitor(WorkerMonitor monitor)
+    {
+        this.monitor = monitor;
+    }
+
+    /**
+     * Sets the job to execute in security context
+     */
+    public void setJob(Runnable job, AccessControlContext context)
+    {
+        this.job = job;
+        this.context = context;
+    }
+
+    /**
+     * Sets the job to execute
+     */
+    public void setJob(Runnable job)
+    {
+        this.job = job;
+        this.context = null;
+    }
+
+    /**
+     * Retrieves the job to execute
+     */
+    public Runnable getJob()
+    {
+        return this.job;
+    }
+
+    /**
+     * Process the job assigned, then notify Monitor. If no job available,
+     * go into sleep mode
+     */
+    public void run()
+    {
+        while (running)
+        {
+            // wait for a job to come
+            synchronized (this)
+            {
+                if (this.job == null)
+                {
+                    try
+                    {
+                        this.wait();
+                    }
+                    catch (InterruptedException e)
+                    {
+                        // nothing done
+                    }
+                }
+            }
+
+            // process it
+            if (this.job != null)
+            {
+                log.debug("Processing job for window :" + ((RenderingJob)job).getWindow().getId());
+                Subject subject = null;
+                if (this.context != null)
+                {
+                    subject = Subject.getSubject(this.context);
+                }
+                if (subject != null)
+                {
+                    Subject.doAsPrivileged(subject, new PrivilegedAction()
+                        {
+                            public Object run()
+                            {
+                                try 
+                                {
+                                    Worker.this.job.run();
+                                }
+                                catch (Throwable t)
+                                {                        
+                                    log.error("Thread error", t);
+                                }
+                                return null;                    
+                            }
+                        }, this.context);
+                }
+                else
+                {
+                    try
+                    {
+                        this.job.run();
+                    }
+                    catch (Throwable t)
+                    {
+                        log.error("Thread error", t);
+                    }
+                }
+            }
+
+            this.jobCount++;
+
+            // release the worker
+            monitor.release(this);
+        }
+    }
+}

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/WorkerMonitor.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/WorkerMonitor.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/WorkerMonitor.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/WorkerMonitor.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,193 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.aggregator.impl;
+
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.util.Stack;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.util.Queue;
+import org.apache.jetspeed.util.FIFOQueue;
+
+/**
+ * The WorkerMonitor is responsible for dispatching jobs to workers
+ * It uses an Apache HTTPd configuration style of min/max/spare workers
+ * threads to throttle the rendering work.
+ * If jobs come in faster that processing, they are stored in a queue
+ * which is flushed periodically by a QueueMonitor.
+ *
+ * @author <a href="mailto:raphael@apache.org">Rapha\u00ebl Luta</a>
+ * @version $Id: WorkerMonitor.java 188405 2005-03-19 12:47:14Z sgala $
+ */
+public class WorkerMonitor
+{
+    /** Commons logging */
+    protected final static Log log = LogFactory.getLog(WorkerMonitor.class);
+
+    /** Static counters for identifying workers */
+    private static long sCount = 0;
+
+    /** Minimum number of wokers to create */
+    private int minWorkers = 5;
+
+    /** Maximum number of workers */
+    private int maxWorkers = 50;
+
+    /** Minimum amount of spare workers */
+    private int spareWorkers = 3;
+
+    /** Maximum of job processed by a worker before being released */
+    private int maxJobsPerWorker = 10;
+
+    /** Stack containing currently idle workers */
+    private Stack workers = new Stack();
+
+    /** The thread group used to group all worker threads */
+    private ThreadGroup tg = new ThreadGroup("Workers");
+
+    /** Job queue */
+    private Queue queue;
+
+    public void init()
+    {
+        addWorkers(this.minWorkers);
+        setQueue(new FIFOQueue());
+    }
+
+    public void setQueue(Queue queue)
+    {
+        this.queue = queue;
+    }
+
+    /**
+     * Create the request number of workers and add them to
+     * list of available workers.
+     *
+     * @param wCount the number of workers to create
+     */
+    protected synchronized void addWorkers(int wCount)
+    {
+        int wCurrent = this.tg.activeCount();
+
+        if (wCurrent < maxWorkers)
+        {
+            if (wCurrent + wCount > maxWorkers)
+            {
+                wCount = maxWorkers - wCurrent;
+            }
+
+            log.info("Creating "+ wCount +" workers -> "+ (wCurrent + wCount));
+
+            for (int i = 0; i < wCount; ++i)
+            {
+                Worker worker = new Worker(this, this.tg, "WORKER_" + (++sCount));
+                worker.start();
+                workers.push(worker);
+            }
+        }
+    }
+
+    /**
+     * Retrieves an idle worker
+     *
+     * @return a Worker from the idle pool or null if non available
+     */
+    public Worker getWorker()
+    {
+        synchronized(this.workers)
+        {
+            if (this.workers.size() < spareWorkers)
+            {
+                addWorkers(spareWorkers);
+            }
+
+            if (this.workers.size() == 0)
+            {
+                return null;
+            }
+
+            return (Worker)workers.pop();
+        }
+    }
+
+    /**
+     * Assign a job to a worker and execute it or queue the job if no
+     * worker is available.
+     *
+     * @param job the Job to process
+     */
+    public void process(RenderingJob job)
+    {
+        Worker worker = this.getWorker();
+
+        AccessControlContext context = AccessController.getContext();
+        if (worker==null)
+        {
+            queue.push(job);
+            queue.push(context);
+        }
+        else
+        {
+            try
+            {
+                synchronized (worker)
+                {
+                    worker.setJob(job, context);
+                    worker.notify();
+                }
+            }
+            catch (Throwable t)
+            {
+                log.error("Worker exception", t);
+            }
+        }
+    }
+
+    /**
+     * Put back the worker in the idle queue unless there are pending jobs and
+     * worker can still be committed to a new job before being released.
+     */
+    public void release(Worker worker)
+    {
+        // if worker can still proces some jobs assign the first
+        // backlog job to this worker, else reset job count and put
+        // it on the idle queue.
+
+        synchronized (worker)
+        {
+            if ((worker.getJobCount()<this.maxJobsPerWorker)&&(queue.size()>0))
+            {
+                RenderingJob job = (RenderingJob)queue.pop();
+                AccessControlContext context = (AccessControlContext)queue.pop();
+                worker.setJob(job, context);
+                return;
+            }
+            else
+            {
+                worker.setJob(null);
+                worker.resetJobCount();
+            }
+        }
+
+        synchronized (this.workers)
+        {
+            this.workers.push(worker);
+        }
+    }
+}

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXFilter.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXFilter.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXFilter.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXFilter.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.ajax;
+
+import java.io.IOException;
+
+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.HttpServletResponse;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.web.context.WebApplicationContext;
+
+/**
+ * Simple ServletFilter for invoking AJAX services.
+ * 
+ * 
+ * @author <href a="mailto:weaver@apache.org">Scott T. Weaver</a>
+ *
+ */
+public class AJAXFilter implements Filter
+{
+    private ApplicationContext ctx;
+    private AJAXService ajaxService;
+    private FilterConfig config;
+    
+    public void init(FilterConfig config) throws ServletException
+    {
+        this.config = config;
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response,
+            FilterChain arg2) throws IOException, ServletException
+    {        
+        try
+        {
+            response.setContentType("text/xml");
+            if(ctx == null)
+            {
+                ctx = (ApplicationContext)config.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
+                ajaxService = (AJAXService) ctx.getBean("AJAXService");
+            }
+            
+            AJAXRequest ajaxRequest = new AJAXRequestImpl((HttpServletRequest) request, (HttpServletResponse) response, config.getServletContext());
+            AJAXResponse ajaxReponse = ajaxService.processRequest(ajaxRequest);
+            ajaxReponse.complete();
+        }
+        catch (AJAXException e)
+        {
+           ((HttpServletResponse) response).sendError(500, e.getMessage());
+        }
+        catch(Exception e)
+        {
+            throw new ServletException(e.getMessage(), e);
+        }
+    }
+
+    public void destroy()
+    {
+        // do nothing
+
+    }
+
+}

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXRequestImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXRequestImpl.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXRequestImpl.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXRequestImpl.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,180 @@
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.ajax;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Request used for AJAX services.
+ * 
+ * @author <href a="mailto:weaver@apache.org">Scott T. Weaver</a>
+ *
+ */
+public class AJAXRequestImpl implements AJAXRequest
+{
+    public static final String AJAX_SERVICE = "ajax_service";
+    public static final String AJAX_PARAM_PREFIX = "ajax_param_";
+    
+    private final HttpServletRequest request;
+    private List ajaxParams;
+    private final String serviceName;
+    private final String methodName;
+    private HttpServletResponse response;
+    private ServletContext context;
+
+    public AJAXRequestImpl(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws AJAXException
+    {
+        this.request = request;
+        this.response = response;
+        this.context = context;
+        String serviceRequest =  request.getParameter(AJAX_SERVICE);
+        if(serviceRequest == null )
+        {
+            throw new AJAXException("No '"+AJAX_SERVICE+"' parameter could be found in the request or it was not in the '{service_name}.{method_name}' format.");
+        }
+        final String split = serviceRequest.split("\\.")[0];
+        serviceName = split;
+        methodName = serviceRequest.split("\\.")[1];
+        
+        parseRequestArguments();
+        
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.ajax.AJAXRequest#getParameters()
+     */
+    public List getParameters()
+    {
+        return ajaxParams;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.ajax.AJAXRequest#getServiceName()
+     */
+    public String getServiceName()
+    {
+        return serviceName;
+    }
+
+    protected List parseRequestArguments() throws AJAXException
+    {
+        try
+        {
+            ajaxParams = new ArrayList();
+            Map rawParams = request.getParameterMap();
+            Iterator entryItr = rawParams.entrySet().iterator();
+            while(entryItr.hasNext())
+            {
+                Map.Entry entry = (Map.Entry) entryItr.next();
+                String key = entry.getKey().toString();
+                
+                if(key.startsWith(AJAX_PARAM_PREFIX))
+                {
+                    String[] paramInfo = key.split("_");
+                    int index = Integer.parseInt(paramInfo[2]);
+                    String type = paramInfo[3]; 
+                    AJAXParameter ajaxParam = new AJAXParameter(type, (String[])entry.getValue());
+                    ajaxParams.add(index, ajaxParam);
+                }
+            }
+            return ajaxParams;
+        }
+        catch (Throwable e)
+        {
+            throw new AJAXException("Errors were encountered parsing request parameters for the AJAX service "+serviceName+": "+e.getMessage(), e);
+        }
+    }
+    
+    public class AJAXParameter
+    {
+        private Object value;
+             
+        public AJAXParameter(String typeName, String[] paramValues)
+        {
+            if(typeName.equals("int"))
+            {                
+                if(paramValues.length > 1)
+                {
+                    int[] intValues = new int[paramValues.length];
+                    for(int i=0; i<paramValues.length; i++)
+                    {
+                        intValues[i] = Integer.parseInt(paramValues[i]);
+                    }
+                }
+                else
+                {
+                    value = new Integer(paramValues[0]);
+                }
+            }
+            else if(typeName.equals("str"))
+            {
+              if(paramValues.length > 1)
+              {    
+                  value = paramValues;
+              }
+              else
+              {
+                  value = paramValues[0];
+              }
+            }
+        }
+        
+        public Object getValue()
+        {
+            return value;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.ajax.AJAXRequest#getMethodName()
+     */
+    public String getMethodName()
+    {
+        return methodName;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.ajax.AJAXRequest#getContext()
+     */
+    public ServletContext getContext()
+    {
+        return context;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.ajax.AJAXRequest#getServletRequest()
+     */
+    public HttpServletRequest getServletRequest()
+    {
+        return request;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.ajax.AJAXRequest#getServletResponse()
+     */
+    public HttpServletResponse getServletResponse()
+    {
+        return response;
+    }
+}

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXResponseImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXResponseImpl.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXResponseImpl.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXResponseImpl.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.ajax;
+
+import java.io.Reader;
+import java.io.Writer;
+
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.context.Context;
+
+/**
+ * Response object used for AJAX services.
+ * 
+ * @author <href a="mailto:weaver@apache.org">Scott T. Weaver</a>
+ *
+ */
+public class AJAXResponseImpl implements AJAXResponse
+{   
+
+    private Context context;
+    private VelocityEngine engine;
+    private Reader template;
+    private Writer output;
+
+    public AJAXResponseImpl(Context context, VelocityEngine engine, Reader template, Writer output)
+    {
+        this.context = context;
+        this.engine = engine;
+        this.template = template;
+        this.output = output;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.ajax.AJAXResponse#complete()
+     */
+    public void complete() throws AJAXException
+    {
+        try
+        {
+            engine.evaluate(context, output, "AJAX processor", template);
+        }
+        catch (Exception e)
+        {
+            throw new AJAXException("Failed to render velocity xml template: "+e.getMessage(), e);
+        }
+     
+    }
+
+    
+
+}

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXServiceImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXServiceImpl.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXServiceImpl.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXServiceImpl.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.ajax;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.context.Context;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+
+/**
+ * Performs invocation of the actual AJAX request and returns
+ * a result object to converted into XML.
+ * 
+ * @author <href a="mailto:weaver@apache.org">Scott T. Weaver</a>
+ *
+ */
+public class AJAXServiceImpl implements AJAXService, BeanFactoryAware
+{
+
+    private Map serviceToBeans;
+
+    private BeanFactory beanFactory;
+    private VelocityEngine engine;
+
+    public AJAXServiceImpl(Map serviceToBeans)
+    {
+        this.serviceToBeans = serviceToBeans;
+        
+    }
+
+    public AJAXResponse processRequest(AJAXRequest request)
+            throws AJAXException
+    {
+        final String serviceName = request.getServiceName();
+        final String methodName = request.getMethodName();
+        final String templateName = request.getServletRequest().getServletPath();
+
+        final String mappedServiceName = (serviceName+"."+methodName).trim();
+        try
+        {
+            if(engine == null)
+            {
+                engine = new VelocityEngine();
+                Properties props = new Properties();
+                props.load(request.getContext().getResourceAsStream("/WEB-INF/velocity.properties"));
+                engine.init();
+            }
+            
+            
+            if(!serviceToBeans.containsKey(mappedServiceName))
+            {
+                throw new AJAXException("There is no AJAX service named '"+mappedServiceName+"' defined.  "+ 
+                        "Please make sure that your ajax.xml is set up correctly.");
+            }
+            
+            String beanId = ((String)serviceToBeans.get(mappedServiceName)).trim();
+            Object targetService = beanFactory.getBean(beanId);
+            final List parameters = request.getParameters();
+            Method method = targetService.getClass().getMethod(methodName, getTypes(parameters));
+            Object result = method.invoke(targetService, getValues(parameters));
+            Context context = new VelocityContext();
+            context.put("ajaxRequest", request);
+            context.put("result", result);            
+            
+            final InputStream templateResource = request.getContext().getResourceAsStream(templateName);
+            
+            if(templateResource == null)
+            {
+                request.getServletResponse().sendError(404, templateName+" ajax template could not be found.");
+                throw new IOException(templateName+" does not exist");
+            }
+            Reader template = new InputStreamReader(templateResource);
+            
+            return new AJAXResponseImpl(context, engine, template, request.getServletResponse().getWriter());
+        }
+        catch(AJAXException ae)
+        {
+            throw ae;
+        }
+        catch (Exception e)
+        {
+            throw new AJAXException("Unable to process service" + mappedServiceName + ": " + e.getMessage(), e);
+        }
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
+     */
+    public void setBeanFactory(BeanFactory beanFactory) throws BeansException
+    {
+        this.beanFactory = beanFactory;
+    }
+
+    protected Class[] getTypes(List objects)
+    {
+        Class[] args = new Class[objects.size()];
+        Iterator itr = objects.iterator();
+        int i = 0;
+        while (itr.hasNext())
+        {
+            args[i] = ((AJAXRequestImpl.AJAXParameter)itr.next()).getValue().getClass();
+            i++;
+        }
+        return args;
+    }
+    
+    protected Object[] getValues(List objects)
+    {
+        Object[] args = new Object[objects.size()];
+        Iterator itr = objects.iterator();
+        int i = 0;
+        while (itr.hasNext())
+        {
+            args[i] = ((AJAXRequestImpl.AJAXParameter)itr.next()).getValue();
+            i++;
+        }
+        return args;
+    }
+
+}

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXValve.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXValve.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXValve.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AJAXValve.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.ajax;
+
+import org.apache.jetspeed.pipeline.PipelineException;
+import org.apache.jetspeed.pipeline.valve.AbstractValve;
+import org.apache.jetspeed.pipeline.valve.ValveContext;
+import org.apache.jetspeed.request.RequestContext;
+
+/**
+ * This should eventually replace the AJAX ServletFilter.
+ * 
+ * @author <href a="mailto:weaver@apache.org">Scott T. Weaver</a>
+ *
+ */
+public class AJAXValve extends AbstractValve
+{
+    public AJAXValve()
+    {
+        super();
+        
+    }
+
+    public void invoke(RequestContext request, ValveContext context)
+            throws PipelineException
+    {
+       
+
+    }
+
+}

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/capabilities/impl/CapabilityValveImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/capabilities/impl/CapabilityValveImpl.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/capabilities/impl/CapabilityValveImpl.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/capabilities/impl/CapabilityValveImpl.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.capabilities.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.capabilities.Capabilities;
+import org.apache.jetspeed.capabilities.CapabilityMap;
+import org.apache.jetspeed.capabilities.MediaType;
+import org.apache.jetspeed.capabilities.MimeType;
+import org.apache.jetspeed.capabilities.UnableToBuildCapabilityMapException;
+import org.apache.jetspeed.pipeline.PipelineException;
+import org.apache.jetspeed.pipeline.valve.CapabilityValve;
+import org.apache.jetspeed.pipeline.valve.ValveContext;
+import org.apache.jetspeed.profiler.rules.ProfilingRule;
+import org.apache.jetspeed.request.RequestContext;
+
+/**
+ * Invokes the capability mapper in the request pipeline
+ * 
+ * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann </a>
+ * @version $Id: CapabilityValveImpl.java 188143 2005-01-04 16:06:21Z weaver $
+ */
+public class CapabilityValveImpl implements CapabilityValve
+{
+    private static final Log log = LogFactory.getLog(CapabilityValveImpl.class);
+    String resourceDefault; // the default name for a resource
+    private Capabilities capabilities;
+
+    public CapabilityValveImpl( Capabilities capabilities )
+    {
+        this.capabilities = capabilities;
+    }
+
+    /**
+     * Initialize the valve before using in a pipeline.
+     */
+    public void initialize() throws PipelineException
+    {
+
+    }
+
+    public void invoke( RequestContext request, ValveContext context ) throws PipelineException
+    {
+
+        String requestMediaType = request.getRequestParameter(ProfilingRule.STANDARD_MEDIATYPE);
+        String agent = request.getRequest().getHeader("User-Agent");
+
+        // Get capability map
+        CapabilityMap cm;
+        try
+        {
+            cm = capabilities.getCapabilityMap(agent);
+        }
+        catch (UnableToBuildCapabilityMapException e)
+        {
+           throw new PipelineException("Falied to create capabilitied:  "+e.getMessage(), e);
+        }
+        
+        MediaType mediaType = cm.getPreferredMediaType();
+        MimeType mimeType = cm.getPreferredType();
+
+        if (mediaType == null)
+        {
+            log.error("CapabilityMap returned a null media type");
+            throw new PipelineException("CapabilityMap returned a null media type");
+        }
+
+        if (mimeType == null)
+        {
+            log.error("CapabilityMap returned a null mime type");
+            throw new PipelineException("CapabilityMap returned a null mime type");
+        }
+
+        String encoding = request.getRequest().getCharacterEncoding();
+
+        if (encoding == null)
+        {
+            if (mediaType != null && mediaType.getCharacterSet() != null)
+            {
+                encoding = mediaType.getCharacterSet();
+            }
+        }
+
+        if (log.isDebugEnabled())
+        {
+            log.debug("MediaType: " + mediaType.getName());
+            log.debug("Encoding: " + encoding);
+            log.debug("Mimetype: " + mimeType.getName());
+        }
+
+        // Put the encoding in the request
+        request.setCharacterEncoding(encoding);
+
+        // Put the CapabilityMap into the request
+        request.setCapabilityMap(cm);
+
+        // Put the Media Type into the request
+        request.setMediaType(mediaType.getName());
+
+        // Put the Mime Type into the request
+        request.setMimeType(mimeType.getName());
+
+        // Put the Mime Type and Charset into the response
+        StringBuffer contentType = new StringBuffer(mimeType.getName());
+        if (encoding != null)
+        {
+            contentType.append("; charset=" + encoding);
+        }
+        request.getResponse().setContentType(contentType.toString());
+
+        // Pass control to the next Valve in the Pipeline
+        context.invokeNext(request);
+    }
+
+    public String toString()
+    {
+        return "CapabilityValveImpl";
+    }
+}

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/ContainerValve.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/ContainerValve.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/ContainerValve.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/ContainerValve.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.container;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.container.state.NavigationalState;
+import org.apache.jetspeed.container.url.PortalURL;
+import org.apache.jetspeed.pipeline.PipelineException;
+import org.apache.jetspeed.pipeline.valve.AbstractValve;
+import org.apache.jetspeed.pipeline.valve.ValveContext;
+import org.apache.pluto.om.window.PortletWindow;
+
+/**
+ * Determines the action window in the current request
+ * If no action was found, sets the request context's action window to null
+ * denoting that there is no targeted action for this request otherwise
+ * the target action window is set here 
+ *
+ * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
+ * @version $Id: ContainerValve.java 187753 2004-10-15 21:47:25Z ate $
+ */
+public class ContainerValve
+       extends AbstractValve
+{
+    private static final Log log = LogFactory.getLog( ContainerValve.class );
+        
+    public void invoke( RequestContext request, ValveContext context )
+        throws PipelineException
+    {
+        try
+        {  
+            // create a session if not already created, necessary for Tomcat 5
+            request.getRequest().getSession(true);
+            
+            //PortletContainerServices.prepare();
+            NavigationalState state = request.getPortalURL().getNavigationalState();
+            if (state != null)
+            {
+                state.sync(request);
+            }
+            
+            PortalURL url = request.getPortalURL();
+            PortletWindow actionWindow = url.getNavigationalState().getPortletWindowOfAction();
+            if (null == actionWindow)
+            {
+                // set to null to denote that no action was requested
+                request.setActionWindow(null);           
+            }
+            else
+            {
+                // set the requested action window
+                request.setActionWindow(actionWindow);                                
+            }
+        }
+        catch (Exception e)
+        {
+            throw new PipelineException(e);
+        }
+        // Pass control to the next Valve in the Pipeline
+        context.invokeNext( request );
+    }
+
+    public String toString()
+    {
+        return "ContainerValve";
+    }
+}
\ No newline at end of file

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/JetspeedPortletContainerWrapper.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/JetspeedPortletContainerWrapper.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/JetspeedPortletContainerWrapper.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/JetspeedPortletContainerWrapper.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.container;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import javax.portlet.PortletException;
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.engine.servlet.ServletObjectAccess;
+import org.apache.pluto.PortletContainer;
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.om.window.PortletWindow;
+import org.apache.pluto.services.PortletContainerEnvironment;
+
+/**
+ * Portlet Container Wrapper to secure access to portlet container.
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: JetspeedPortletContainerWrapper.java 187042 2004-07-20 13:52:20Z weaver $
+ */
+public class JetspeedPortletContainerWrapper implements PortletContainerWrapper
+{
+    private boolean initialized = false;
+    private static final Log log = LogFactory.getLog(JetspeedPortletContainerWrapper.class);
+    private PortletContainer pluto;
+
+    public JetspeedPortletContainerWrapper(PortletContainer pluto)
+    {
+        this.pluto = pluto;
+    }
+
+  
+    /**
+     * initialization is still handled outside component architecture, since Pluto is not a component
+     */
+    public synchronized void init(
+        String uniqueContainerId,
+        ServletConfig servletConfig,
+        PortletContainerEnvironment environment,
+        Properties props)
+        throws PortletContainerException
+    {
+
+        pluto.init(uniqueContainerId, servletConfig, environment, props);
+        initialized = true;
+    }
+
+    public synchronized void shutdown() throws PortletContainerException
+    {
+        initialized = false;
+        pluto.shutdown();
+    }
+
+    public void renderPortlet(PortletWindow portletWindow, HttpServletRequest servletRequest, HttpServletResponse servletResponse)
+        throws PortletException, IOException, PortletContainerException
+    {
+                
+        if(portletWindow.getPortletEntity() == null)
+        {
+            log.warn("Could not render PortletWindow "+ portletWindow.getId() + " as it has no PortletEntity defined.");
+            return;
+        }        
+        
+        if(portletWindow.getPortletEntity().getPortletDefinition() == null)
+        {
+            log.warn("Could not render PortletWindow"+ portletWindow.getId() + " as it has no PortletDefintion defined.");
+            return;
+        }
+        pluto.renderPortlet(portletWindow, servletRequest, servletResponse);
+        // TODO: figure out how to access pluto-services before container kicks in
+        //                              ServletObjectAccess.getServletRequest(servletRequest),
+        //                              ServletObjectAccess.getServletResponse(servletResponse));
+    }
+
+    public void processPortletAction(
+        PortletWindow portletWindow,
+        HttpServletRequest servletRequest,
+        HttpServletResponse servletResponse)
+        throws PortletException, IOException, PortletContainerException
+    {
+        pluto.processPortletAction(portletWindow, servletRequest, servletResponse);
+        //                                     ServletObjectAccess.getServletRequest(servletRequest),
+        //                                     ServletObjectAccess.getServletResponse(servletResponse));
+    }
+
+    public void portletLoad(PortletWindow portletWindow, HttpServletRequest servletRequest, HttpServletResponse servletResponse)
+        throws PortletException, PortletContainerException
+    {
+        pluto.portletLoad(
+            portletWindow,
+            ServletObjectAccess.getServletRequest(servletRequest, portletWindow),
+            ServletObjectAccess.getServletResponse(servletResponse, portletWindow));
+    }
+
+    /**
+     * <p>
+     * isInitialized
+     * </p>
+     *
+     * @see org.apache.pluto.PortletContainer#isInitialized()
+     * @return
+     */
+    public boolean isInitialized()
+    {
+        return initialized;
+    }
+
+}

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/PortletContainerWrapper.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/PortletContainerWrapper.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/PortletContainerWrapper.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/PortletContainerWrapper.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.container;
+
+import org.apache.pluto.PortletContainer;
+
+/**
+ * Portlet Container Wrapper inteface
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: PortletContainerWrapper.java 186143 2004-03-17 01:50:13Z taylor $
+ */
+public interface PortletContainerWrapper extends PortletContainer
+{
+}

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/JetspeedPortletInvoker.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/JetspeedPortletInvoker.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/JetspeedPortletInvoker.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/JetspeedPortletInvoker.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.container.invoker;
+
+import javax.servlet.ServletConfig;
+
+import org.apache.jetspeed.factory.PortletFactory;
+import org.apache.pluto.invoker.PortletInvoker;
+import org.apache.pluto.om.portlet.PortletDefinition;
+
+/**
+ * JetspeedPortletInvoker extends Pluto's portlet invoker and extends it
+ * with lifecycle management. Portlet Invokers can be pooled, and activated
+ * and passivated per request cycle.
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: JetspeedPortletInvoker.java 188436 2005-03-23 22:54:30Z ate $
+ */
+public interface JetspeedPortletInvoker extends PortletInvoker
+{
+    /**
+     * Activating an invoker makes it ready to invoke portlets.
+     * If an invoker's state is not activated, it can not invoke.
+     * 
+     * @param portletFactory The factory to get access to the portlet being invoked.
+     * @param portletDefinition The portlet's definition that is being invoked.
+     * @param servletConfig The servlet configuration of the portal. 
+     * @param containerServlet
+     */
+    void activate(PortletFactory portletFactory, PortletDefinition portletDefinition, ServletConfig servletConfig);
+
+    /**
+     * Activating an invoker makes it ready to invoke portlets.
+     * If an invoker's state is not activated, it can not invoke.
+     * This second signature allows for activating with an extra property.
+     * 
+     * @param portletFactory The factory to get access to the portlet being invoked.
+     * @param portletDefinition The portlet's definition that is being invoked.
+     * @param servletConfig The servlet configuration of the portal. 
+     * @param property Implementation specific property
+     * @param containerServlet
+     */
+    void activate(PortletFactory portletFactory, PortletDefinition portletDefinition, ServletConfig servletConfig, String property);
+    
+    /**
+     * Passivates an invoker, freeing it back to the invoker pool.
+     * If an invoker's state is passivated, it cannot be used to invoke portlets.
+     */
+    void passivate();
+    
+    /**
+     * Returns true if the state of this invoke is 'activated', and false if it is 'passivated'.
+     * @return True if the current state of the invoker is 'activated' otherwise false.
+     */
+    boolean isActivated();
+}

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/LocalPortletInvoker.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/LocalPortletInvoker.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/LocalPortletInvoker.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/LocalPortletInvoker.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,211 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.container.invoker;
+
+import java.io.IOException;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.PortalReservedParameters;
+import org.apache.jetspeed.container.ContainerConstants;
+import org.apache.jetspeed.factory.PortletFactory;
+import org.apache.jetspeed.factory.PortletInstance;
+import org.apache.jetspeed.om.common.portlet.PortletApplication;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.pluto.om.portlet.PortletDefinition;
+
+/**
+ * LocalPortletInvoker invokes local (internal) portlet applications.
+ * Local portlet applications are stored within the Jetspeed Portlet application.
+ * They are not separate web applications; but are stored under Jetspeed's
+ * WEB-INF/apps directory.
+ * <h3>Sample Configuration</h3>
+ * <pre>
+ * <code>
+ * factory.invoker.local = org.apache.jetspeed.container.invoker.LocalPortletInvoker
+ * factory.invoker.local.pool.size = 50
+ * </code> 
+ * </pre>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: LocalPortletInvoker.java 188614 2005-05-25 01:30:38Z ate $
+ */
+public class LocalPortletInvoker implements JetspeedPortletInvoker
+{
+    private final static Log log = LogFactory.getLog(LocalPortletInvoker.class);
+
+    protected PortletFactory portletFactory;
+    protected ServletContext jetspeedContext;
+    protected ServletConfig jetspeedConfig;
+    protected PortletDefinition portletDefinition;
+    protected boolean activated = false;
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(PortletFactory,org.apache.pluto.om.portlet.PortletDefinition, javax.servlet.ServletConfig)
+     */
+    public void activate(PortletFactory portletFactory, PortletDefinition portletDefinition, ServletConfig servletConfig)
+    {
+        this.portletFactory = portletFactory;
+        this.jetspeedConfig = servletConfig;
+        jetspeedContext = servletConfig.getServletContext();
+        this.portletDefinition = portletDefinition;
+        activated = true;        
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#passivate()
+     */
+    public void passivate()
+    {
+        activated = false;    
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#isActivated()
+     */
+    public boolean isActivated()
+    {
+        return activated;
+    }
+    
+    public LocalPortletInvoker()
+    {
+        activated = false;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.pluto.invoker.PortletInvoker#action(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
+     */
+    public void action(ActionRequest request, ActionResponse response)
+        throws PortletException, IOException
+    {
+        invoke(request, response, ContainerConstants.METHOD_ACTION);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.pluto.invoker.PortletInvoker#render(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
+     */
+    public void render(RenderRequest request, RenderResponse response)
+        throws PortletException, IOException
+    {
+        invoke(request, response, ContainerConstants.METHOD_RENDER);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.pluto.invoker.PortletInvoker#load(javax.portlet.PortletRequest, javax.portlet.RenderResponse)
+     */
+    public void load(PortletRequest request, RenderResponse response)
+        throws PortletException
+    {
+        try
+        {
+            invoke(request, response, ContainerConstants.METHOD_NOOP);
+        }
+        catch (IOException e)
+        {
+            log.error("LocalPortletInvokerImpl.load() - Error while dispatching portlet.", e);
+            throw new PortletException(e);
+        }
+    }
+    
+    
+    /**
+     * Invokes the specific request denoted by the <code>method</code> parameter on a portlet.
+     * The portlet is invoked with a direct method call on the portlet. It is not invoked in another web application.
+     * This requires manipulation of the current thread's classpath.
+     * 
+     * @param portletRequest
+     * @param portletResponse
+     * @param methodID
+     * @throws PortletException
+     * @throws IOException
+     */
+    protected void invoke(PortletRequest portletRequest, PortletResponse portletResponse, Integer method)
+        throws PortletException, IOException
+    {
+        ClassLoader paClassLoader = portletFactory.getPortletApplicationClassLoader((PortletApplication)portletDefinition.getPortletApplicationDefinition());
+        PortletInstance portletInstance = portletFactory.getPortletInstance(jetspeedContext,portletDefinition);
+
+        if (method == ContainerConstants.METHOD_NOOP)
+        {
+            return;
+        }
+
+        // gather all required data from request and response
+        ServletRequest servletRequest = ((javax.servlet.http.HttpServletRequestWrapper) portletRequest).getRequest();
+
+        ServletResponse servletResponse = ((javax.servlet.http.HttpServletResponseWrapper) portletResponse).getResponse();
+
+        ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();            
+        try
+        {
+            servletRequest.setAttribute(ContainerConstants.PORTLET_CONFIG, portletInstance.getConfig());
+            servletRequest.setAttribute(ContainerConstants.PORTLET_REQUEST, portletRequest);
+            servletRequest.setAttribute(ContainerConstants.PORTLET_RESPONSE, portletResponse);
+            RequestContext requestContext = (RequestContext)servletRequest.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
+            servletRequest.setAttribute(ContainerConstants.PORTAL_CONTEXT, requestContext.getRequest().getContextPath());
+
+            Thread.currentThread().setContextClassLoader(paClassLoader);
+
+        if (method == ContainerConstants.METHOD_ACTION)
+        {
+            ActionRequest actionRequest = (ActionRequest)portletRequest;            
+            ActionResponse actionResponse = (ActionResponse)portletResponse;
+
+                portletInstance.processAction(actionRequest, actionResponse);
+        }
+        else if (method == ContainerConstants.METHOD_RENDER)
+        {
+            RenderRequest renderRequest = (RenderRequest)portletRequest;            
+            RenderResponse renderResponse = (RenderResponse)portletResponse;
+            
+            renderResponse.setContentType("text/html");            
+// TODO: ???    renderResponse.getWriter().print(portletDefinition.getName());
+
+                portletInstance.render(renderRequest, renderResponse);
+        }
+        }
+        finally
+        {
+            servletRequest.removeAttribute(ContainerConstants.PORTLET_CONFIG);
+            servletRequest.removeAttribute(ContainerConstants.PORTLET_REQUEST);
+            servletRequest.removeAttribute(ContainerConstants.PORTLET_RESPONSE);
+            servletRequest.removeAttribute(ContainerConstants.PORTAL_CONTEXT);
+
+        Thread.currentThread().setContextClassLoader(oldLoader);                 
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(PortletFactory,org.apache.pluto.om.portlet.PortletDefinition, javax.servlet.ServletConfig, java.lang.String)
+     */
+    public void activate(PortletFactory portletFactory, PortletDefinition portletDefinition, ServletConfig servletConfig, String servletMappingName)
+    {
+        activate(portletFactory, portletDefinition, servletConfig);
+    }
+    
+}

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/PortletInvokerFactoryImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/PortletInvokerFactoryImpl.java?rev=209328&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/PortletInvokerFactoryImpl.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/PortletInvokerFactoryImpl.java Tue Jul  5 14:55:37 2005
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.container.invoker;
+
+import java.util.Map;
+
+import javax.servlet.ServletConfig;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.jetspeed.Jetspeed;
+import org.apache.jetspeed.PortalContext;
+import org.apache.jetspeed.factory.PortletFactory;
+import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
+import org.apache.pluto.factory.PortletInvokerFactory;
+import org.apache.pluto.om.portlet.PortletDefinition;
+import org.apache.pluto.invoker.PortletInvoker;
+
+/**
+ * <p>
+ * Portlet Invoker Factory creates portlet invokers based on the servlet context.
+ * This class is part of the contract between Pluto and the Jetspeed Portal as defined
+ * in the interfaces under <code>org.apache.pluto.factory</code>
+ * The Pluto container uses portlet invokers to abstract access to portlets.
+ * An invoker interfaces defines which actions are performed between the portal and container,
+ * namely action, render and optionally load. Portlet invoker factories are implemented by
+ * the portal implementation. The Pluto container uses pluggable portlet invoker factories
+ * in order to get portlet invokers, and then invoke methods on portlets (render, action, load). 
+ * </p>
+ * <p>
+ * The Portlet Invoker Factory is a Pluto factory. Pluto defines a basic lifecycle for Pluto
+ * factory services in the <code>org.apach.pluto.factory.Factory</code> interface with
+ * standard <code>init</code> and <code>destroy</code> methods.
+ * </p>
+ * <p>
+ * The Jetspeed portlet invoker factory supports two kinds of invokers: local and servlet.
+ * Local portlet invokers call portlets located in the same web applications.
+ * With local invokers, a simple java method invocation is called on the portlet.
+ * Servlet portlet invokers call portlets located in another web application.
+ * With servlet invokers, the servlet request dispatcher is used to call methods on the portlet. 
+ * </p>
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: PortletInvokerFactoryImpl.java 188436 2005-03-23 22:54:30Z ate $
+ */
+public class PortletInvokerFactoryImpl
+    implements PortletInvokerFactory
+{
+    
+    public final static String INVOKER_SERVLET_MAPPING_NAME = "factory.invoker.servlet.mapping.name";
+    public final static String DEFAULT_MAPPING_NAME = "/container";
+    
+    private final static Log log = LogFactory.getLog(PortletInvokerFactoryImpl.class);
+
+    /** The servlet configuration for the Jetspeed portal */
+    private ServletConfig servletConfig;
+
+    private Map props;
+
+    private PortalContext portalContext;
+    
+    private PortletFactory portletFactory;
+               
+    /* (non-Javadoc)
+     * @see org.apache.pluto.factory.Factory#init(javax.servlet.ServletConfig, java.util.Map)
+     */
+    public void init(ServletConfig config, Map properties)
+    throws Exception
+    {
+        servletConfig = config;        
+        portalContext = Jetspeed.getContext();
+        props = properties;                        
+        portletFactory = (PortletFactory)props.get("PortletFactory");
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.pluto.factory.Factory#destroy()
+     */
+    public void destroy()
+    throws Exception
+    {
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.pluto.factory.PortletInvokerFactory#getPortletInvoker(org.apache.pluto.om.portlet.PortletDefinition)
+     */
+    public PortletInvoker getPortletInvoker(PortletDefinition portletDefinition)
+    {
+        JetspeedPortletInvoker invoker = null;
+
+        MutablePortletApplication app = (MutablePortletApplication)portletDefinition.getPortletApplicationDefinition();
+        if(app == null)
+        {
+        	throw new IllegalStateException("Portlet definition \""+portletDefinition.getName()+"\" is not assigned to a portlet application.");
+        }
+        
+        if (app.getApplicationType() == MutablePortletApplication.LOCAL)
+        {
+                invoker =  (JetspeedPortletInvoker) props.get("LocalPortletInvoker"); 
+                invoker.activate(portletFactory, portletDefinition, servletConfig);
+                return invoker;           
+        }
+        else
+        {
+            invoker =  (JetspeedPortletInvoker) props.get("ServletPortletInvoker"); 
+            String servletMappingName = portalContext.getConfigurationProperty(INVOKER_SERVLET_MAPPING_NAME, DEFAULT_MAPPING_NAME);
+            invoker.activate(portletFactory, portletDefinition, servletConfig, servletMappingName);            
+            return invoker;
+        }
+
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.pluto.factory.PortletInvokerFactory#releasePortletInvoker(org.apache.pluto.invoker.PortletInvoker)
+     */
+    public void releasePortletInvoker(PortletInvoker invoker)
+    {
+        // this is now taken care off by Spring's CommonsPoolingTargetSource
+//        try
+//        {
+//            if (invoker instanceof ServletPortletInvoker)
+//            {
+//                servletInvokerFactory.releaseObject(invoker);                
+//            }
+//            else
+//            {
+//                localInvokerFactory.releaseObject(invoker);                            
+//            }
+//        }
+//        catch (Exception e)
+//        {
+//            log.error(e);
+//        }
+    }
+    
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message