ate 2005/03/23 14:20:37
Modified: commons/src/java/org/apache/jetspeed/container
PortletConfigFactory.java
JetspeedPortletContext.java
JetspeedPortletConfig.java ContainerConstants.java
JetspeedContainerServlet.java PortalAccessor.java
InternalPortletConfig.java
commons/src/java/org/apache/jetspeed/util
DirectoryHelper.java
Removed: commons/src/java/org/apache/jetspeed/factory
JetspeedPortletFactoryProxy.java
Log:
Resolving http://issues.apache.org/jira/browse/JS2-210
Revision Changes Path
1.3 +3 -7
jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/PortletConfigFactory.java
Index: PortletConfigFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/PortletConfigFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PortletConfigFactory.java 8 Mar 2004 00:41:26 -0000 1.2
+++ PortletConfigFactory.java 23 Mar 2005 22:20:37 -0000 1.3
@@ -15,7 +15,6 @@
*/
package org.apache.jetspeed.container;
-import javax.servlet.ServletConfig;
import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
@@ -29,12 +28,9 @@
*/
public class PortletConfigFactory
{
- public static PortletConfig createPortletConfig(
- ServletConfig servletConfig,
- PortletContext portletContext,
- PortletDefinition portletDefinition)
+ public static PortletConfig createPortletConfig(PortletContext
portletContext,PortletDefinition portletDefinition)
{
- return new JetspeedPortletConfig(servletConfig, portletContext,
portletDefinition);
+ return new JetspeedPortletConfig(portletContext, portletDefinition);
}
}
1.8 +5 -1
jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedPortletContext.java
Index: JetspeedPortletContext.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedPortletContext.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- JetspeedPortletContext.java 6 Jul 2004 23:30:48 -0000 1.7
+++ JetspeedPortletContext.java 23 Mar 2005 22:20:37 -0000 1.8
@@ -232,6 +232,9 @@
{
return "/";
}
+ return path;
+ // TODO: local PA with own/extra resource paths support
+/*
if (app.getApplicationType() == MutablePortletApplication.WEBAPP)
{
return path;
@@ -246,5 +249,6 @@
pathBuffer.append(path);
String result = pathBuffer.toString();
return result;
+*/
}
}
1.7 +2 -11
jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedPortletConfig.java
Index: JetspeedPortletConfig.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedPortletConfig.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JetspeedPortletConfig.java 6 Oct 2004 01:51:20 -0000 1.6
+++ JetspeedPortletConfig.java 23 Mar 2005 22:20:37 -0000 1.7
@@ -20,7 +20,6 @@
import java.util.Locale;
import java.util.ResourceBundle;
-import javax.servlet.ServletConfig;
import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
@@ -41,13 +40,11 @@
{
// private static final Log log =
LogFactory.getLog(JetspeedPortletConfig.class);
- private ServletConfig servletConfig;
private PortletContext portletContext;
private PortletDefinition portletDefinition;
- public JetspeedPortletConfig(ServletConfig servletConfig, PortletContext
portletContext, PortletDefinition portletEntity)
+ public JetspeedPortletConfig(PortletContext portletContext,
PortletDefinition portletEntity)
{
- this.servletConfig = servletConfig;
this.portletContext = portletContext;
this.portletDefinition = portletEntity;
}
@@ -116,12 +113,6 @@
}
// internal portlet config implementation
-
- public javax.servlet.ServletConfig getServletConfig()
- {
- return servletConfig;
- }
-
public PortletDefinition getPortletDefinition()
{
return portletDefinition;
1.6 +2 -1
jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/ContainerConstants.java
Index: ContainerConstants.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/ContainerConstants.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ContainerConstants.java 19 Aug 2004 23:54:06 -0000 1.5
+++ ContainerConstants.java 23 Mar 2005 22:20:37 -0000 1.6
@@ -29,6 +29,7 @@
public final static String PORTLET_CONFIG = "javax.portlet.config";
public final static String PORTAL_CONTEXT =
"org.apache.jetspeed.context";
public final static String METHOD_ID = "org.apache.jetspeed.method";
+ public final static String PORTLET = "org.apache.jetspeed.portlet";
public final static Integer METHOD_RENDER = new Integer(1);
public final static Integer METHOD_ACTION = new Integer(3);
public final static Integer METHOD_NOOP = new Integer(5);
1.22 +96 -119
jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedContainerServlet.java
Index: JetspeedContainerServlet.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedContainerServlet.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- JetspeedContainerServlet.java 2 Feb 2005 03:20:14 -0000 1.21
+++ JetspeedContainerServlet.java 23 Mar 2005 22:20:37 -0000 1.22
@@ -33,15 +33,13 @@
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
-import org.apache.jetspeed.factory.JetspeedPortletFactoryProxy;
import org.apache.jetspeed.services.JetspeedPortletServices;
import org.apache.jetspeed.services.PortletServices;
-import org.apache.jetspeed.tools.pamanager.DeploymentRegistration;
+import org.apache.jetspeed.tools.pamanager.PortletApplicationManagement;
import org.apache.jetspeed.util.DirectoryHelper;
-import org.apache.jetspeed.util.FileSystemHelper;
-import org.apache.pluto.om.portlet.PortletDefinition;
/**
* Jetspeed Container entry point.
@@ -51,98 +49,93 @@
*/
public class JetspeedContainerServlet extends HttpServlet
{
- // private final static Log log =
LogFactory.getLog(JetspeedContainerServlet.class);
- // private final static Log console = LogFactory.getLog(CONSOLE_LOGGER);
-
- /**
- * Whether init succeeded or not.
- */
- private static Throwable initFailure = null;
-
-
- private static String webappRoot;
+ private String contextName;
+ private boolean started = false;
+ private Timer startTimer = null;
// -------------------------------------------------------------------
// I N I T I A L I Z A T I O N
// -------------------------------------------------------------------
private static final String JCS = "JetspeedContainerServlet: ";
- private static final String INIT_START_MSG = JCS + "starting
initialization of context ";
- private static final String INIT_DONE_MSG = JCS + "Initialization
complete for context ";
+ private static final String INIT_START_MSG = JCS + "starting
initialization of Portlet Application at: ";
+ private static final String TRY_START_MSG = JCS + "attemping to start
Portlet Application at: ";
+ private static final String STARTED_MSG = JCS + "started Portlet
Application at: ";
+ private static final String INIT_FAILED_MSG = JCS + "initialization
failed for Portlet Application at: ";
+ private static final String INIT_DONE_MSG = JCS + "initialization done
for Portlet Application at: ";
+ private static final String STOP_MSG = JCS + "shutting down portlet
application at: ";
+ private static final String STOP_FAILED_MSG = JCS + "shutting down error
for portlet application at: ";
- /**
- * Intialize Servlet.
- */
public synchronized final void init(ServletConfig config) throws
ServletException
{
synchronized (this.getClass())
{
super.init(config);
+
ServletContext context = getServletContext();
- String name = context.getServletContextName();
- if (name == null || name.length() == 0)
- {
- name = context.getRealPath("/");
- if (name == null)
+
+ started = false;
+ startTimer = null;
+ contextName = config.getInitParameter("contextName");
+
+ if (null == contextName || contextName.length() == 0)
+ {
+ contextName = null; // just to make sure for the destroy
method
+
+ throw new ServletException(JCS + "Portlet Application
contextName not supplied in Init Parameters.");
+ }
+ String paDir = context.getRealPath("/");
+ if ( paDir == null )
{
- name = "Jetspeed";
+ throw new ServletException(JCS + " Initialization of
PortletApplication at "+contextName+" without access to its real path not
supported");
}
- }
- context.log(INIT_START_MSG + name);
- System.out.println(INIT_START_MSG + name);
+
+ context.log(INIT_START_MSG + contextName);
+ System.out.println(INIT_START_MSG + contextName);
try
{
- String registerAtInit =
config.getInitParameter("registerAtInit");
- if (null != registerAtInit)
- {
- context.log(JCS + "Considering PA for registration
during servlet init: " + name);
- String portletApplication =
config.getInitParameter("portletApplication");
- if (null == portletApplication)
- {
- throw new ServletException(JCS + "Portlet
Application Name not supplied in Init Parameters.");
- }
-
- registerPortletApplication(context, portletApplication);
-
- }
+ startPortletApplication(context, paDir,
Thread.currentThread().getContextClassLoader());
}
catch (Exception e)
{
- initFailure = e;
- String message = JCS + "Initialization of servlet " + name +
" failed.";
+ String message = INIT_FAILED_MSG + contextName;
context.log(message, e);
System.err.println(message);
- e.printStackTrace(System.err);
throw new ServletException(message, e);
}
- context.log(INIT_DONE_MSG + name);
- System.out.println(INIT_DONE_MSG + name);
+ context.log(INIT_DONE_MSG + contextName);
+ System.out.println(INIT_DONE_MSG + contextName);
}
}
- private void registerPortletApplication(final ServletContext context,
final String portletApplicationName)
+ private void startPortletApplication(final ServletContext context, final
String paDir, final ClassLoader paClassLoader)
throws ServletException
{
- context.log(JCS + "Attempting to register portlet application:
name=" + portletApplicationName);
- if (attemptRegistration(context, portletApplicationName))
+ if (attemptStart(context, contextName, paDir, paClassLoader))
{
- context.log(JCS + "Registered portlet application: name=" +
portletApplicationName);
+ started = true;
return;
}
- context.log(JCS + "Could not registered portlet application;
starting back ground thread to register when jetspeed comes online: name=" +
portletApplicationName);
- final Timer timer = new Timer(true);
- timer.schedule(
+ final String START_DELAYED_MSG = JCS + "Could not yet start portlet
application at: "+contextName+". Starting back ground thread to start when the
portal comes online.";
+ context.log(START_DELAYED_MSG);
+ startTimer = new Timer(true);
+ startTimer.schedule(
new TimerTask() {
public void run() {
- context.log(JCS + "Attempting to register portlet
application: name=" + portletApplicationName);
- if (attemptRegistration(context,
portletApplicationName)) {
- context.log(JCS + "Registered portlet
application: name=" + portletApplicationName);
- timer.cancel();
+ synchronized(contextName)
+ {
+ if (startTimer != null)
+ {
+ if (attemptStart(context, contextName, paDir,
paClassLoader)) {
+ startTimer.cancel();
+ startTimer = null;
} else {
- context.log(JCS + "Could not register portlet
application; will try again later: name=" + portletApplicationName);
+ context.log(START_DELAYED_MSG);
+ }
+ }
}
}
},
@@ -150,34 +143,31 @@
10000);
}
- private static boolean attemptRegistration(ServletContext context,
String portletApplicationName)
+ private boolean attemptStart(ServletContext context, String contextPath,
String paDir, ClassLoader paClassLoader)
{
try
{
+ context.log(TRY_START_MSG + contextPath);
PortletServices services =
JetspeedPortletServices.getSingleton();
if (services != null)
{
- DeploymentRegistration registrar =
- (DeploymentRegistration)services.getService("PAM");
+ PortletApplicationManagement pam =
+ (PortletApplicationManagement)services.getService("PAM");
- if (registrar != null)
+ if (pam != null)
{
- FileSystemHelper webapp = new DirectoryHelper(new
File(context.getRealPath("/")));
- if (registrar.registerPortletApplication(webapp,
portletApplicationName))
- {
- context.log(JCS + "Portlet Application Registered at
Servlet Init: " + portletApplicationName);
- }
- else
- {
- context.log(JCS + "Portlet Application did not
change. Not Registered at Servlet Init: " + portletApplicationName);
- }
+ DirectoryHelper paDirHelper = new DirectoryHelper(new
File(paDir));
+ pam.startPortletApplication(contextPath, paDirHelper,
paClassLoader);
+ started = true;
+ context.log(STARTED_MSG + contextPath);
return true;
}
}
}
catch (Exception e)
{
- context.log(JCS + "Failed to register PA: " +
portletApplicationName, e);
+ context.log(INIT_FAILED_MSG + contextPath, e);
+ return true; // don't try again
}
return false;
}
@@ -200,28 +190,21 @@
Integer method = ContainerConstants.METHOD_NOOP;
try
{
- // Check to make sure that we started up properly.
- if (initFailure != null)
- {
- throw initFailure;
- }
-
- // infuseClasspath();
-
method = (Integer)
request.getAttribute(ContainerConstants.METHOD_ID);
if (method == ContainerConstants.METHOD_NOOP)
{
return;
}
- PortletDefinition portletDefinition =
JetspeedPortletFactoryProxy.getCurrentPortletDefinition();
- portletName = portletDefinition.getName();
- Portlet portlet =
JetspeedPortletFactoryProxy.getPortlet(this.getServletConfig(),
portletDefinition);
+ Portlet portlet =
(Portlet)request.getAttribute(ContainerConstants.PORTLET);
+ request.removeAttribute(ContainerConstants.PORTLET);
if (method == ContainerConstants.METHOD_ACTION)
{
ActionRequest actionRequest = (ActionRequest)
request.getAttribute(ContainerConstants.PORTLET_REQUEST);
ActionResponse actionResponse = (ActionResponse)
request.getAttribute(ContainerConstants.PORTLET_RESPONSE);
+ // inject the current request into the actionRequest handler
(o.a.j.engine.servlet.ServletRequestImpl)
+
((HttpServletRequestWrapper)((HttpServletRequestWrapper)actionRequest).getRequest()).setRequest(request);
portlet.processAction(actionRequest, actionResponse);
}
@@ -229,6 +212,8 @@
{
RenderRequest renderRequest = (RenderRequest)
request.getAttribute(ContainerConstants.PORTLET_REQUEST);
RenderResponse renderResponse = (RenderResponse)
request.getAttribute(ContainerConstants.PORTLET_RESPONSE);
+ // inject the current request into the renderRequest handler
(o.a.j.engine.servlet.ServletRequestImpl)
+
((HttpServletRequestWrapper)((HttpServletRequestWrapper)renderRequest).getRequest()).setRequest(request);
portlet.render(renderRequest, renderResponse);
}
@@ -302,50 +287,42 @@
// S E R V L E T S H U T D O W N
// -------------------------------------------------------------------
- /**
- * The <code>Servlet</code> destroy method. Invokes
<code>ServiceBroker</code>
- * tear down method.
- */
public final void destroy()
{
- getServletContext().log(JCS + "Shutting down portlet app context: "
+ getServletContext().getServletContextName());
+ if ( contextName != null )
+ {
+ synchronized (contextName)
+ {
+ if ( startTimer != null )
+ {
+ startTimer.cancel();
+ startTimer = null;
}
+ else if ( started )
+ {
+ started = false;
+ PortletServices services =
JetspeedPortletServices.getSingleton();
+ if (services != null)
+ {
+ PortletApplicationManagement pam =
+ (PortletApplicationManagement)services.getService("PAM");
- public static final String LOCAL_CLASSES = "/WEB-INF/classes/";
- public static final String LOCAL_JARS = "/WEB-INF/lib/";
-
- private void infuseClasspath()
+ if (pam != null)
{
+ getServletContext().log(STOP_MSG + contextName);
try
{
- ClassLoader oldLoader =
Thread.currentThread().getContextClassLoader();
- ClassLoader defaultLoader = Class.class.getClassLoader();
-
- System.out.println("thread Loader is " + oldLoader);
- System.out.println("defaultLoader is " + defaultLoader);
- /*
- ClassLoader loader; // =
(ClassLoader)classLoaders.get(portletApplicationName);
- // if (null == loader)
- {
- StringBuffer localPath = new StringBuffer("file:");
- //
localPath.append(jetspeedContext.getRealPath(JetspeedPortletContext.LOCAL_PA_ROOT));
- // localPath.append(portletApplicationName);
- String localAppPath =
"file://c:/bluesunrise/apache/catalina/webapps/jetspeed";
- //localPath.toString();
- URL[] urls = { new URL(localAppPath + LOCAL_CLASSES), new
URL(localAppPath + LOCAL_JARS)};
- loader = new URLClassLoader(urls, oldLoader);
- // classLoaders.put(portletApplicationName, loader);
+ pam.stopPortletApplication(contextName);
+ }
+ catch (Exception e)
+ {
+ getServletContext().log(STOP_FAILED_MSG + contextName,
e);
+ }
+ }
+ }
+ contextName = null;
}
- Thread.currentThread().setContextClassLoader(loader);
- */
}
- catch (Exception e)
- {
- e.printStackTrace();
- return;
}
-
}
-
-
}
1.3 +3 -5
jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/PortalAccessor.java
Index: PortalAccessor.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/PortalAccessor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PortalAccessor.java 8 Mar 2004 00:41:26 -0000 1.2
+++ PortalAccessor.java 23 Mar 2005 22:20:37 -0000 1.3
@@ -16,7 +16,6 @@
package org.apache.jetspeed.container;
import javax.servlet.ServletContext;
-import javax.servlet.ServletConfig;
import javax.portlet.PortletContext;
import javax.portlet.PortletConfig;
@@ -33,11 +32,10 @@
public class PortalAccessor
{
- public static PortletConfig createPortletConfig(ServletConfig
servletConfig,
- PortletContext
portletContext,
+ public static PortletConfig createPortletConfig(PortletContext
portletContext,
PortletDefinition
portletDefinition)
{
- return PortletConfigFactory.createPortletConfig(servletConfig,
portletContext, portletDefinition);
+ return PortletConfigFactory.createPortletConfig(portletContext,
portletDefinition);
}
public static PortletContext createPortletContext(ServletContext
servletContext,
1.3 +1 -5
jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/InternalPortletConfig.java
Index: InternalPortletConfig.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/InternalPortletConfig.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InternalPortletConfig.java 8 Mar 2004 00:41:26 -0000 1.2
+++ InternalPortletConfig.java 23 Mar 2005 22:20:37 -0000 1.3
@@ -17,8 +17,6 @@
import org.apache.pluto.om.portlet.PortletDefinition;
-import javax.servlet.ServletConfig;
-
/**
* This interface defines the internal methods used on the Portlet Config.
*
@@ -28,8 +26,6 @@
*/
public interface InternalPortletConfig
{
- public ServletConfig getServletConfig();
-
public PortletDefinition getPortletDefinition();
}
1.5 +34 -5
jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util/DirectoryHelper.java
Index: DirectoryHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util/DirectoryHelper.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DirectoryHelper.java 31 Jul 2004 20:05:28 -0000 1.4
+++ DirectoryHelper.java 23 Mar 2005 22:20:37 -0000 1.5
@@ -18,14 +18,13 @@
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
- *
+ * @version $Id$
*/
public class DirectoryHelper
extends
@@ -108,7 +107,11 @@
*/
protected void copyFiles(File srcDir, File dstDir, FileFilter
fileFilter) throws IOException
{
-
+ FileChannel srcChannel = null;
+ FileChannel dstChannel = null;
+
+ try
+ {
File[] children = srcDir.listFiles(fileFilter);
for(int i=0; i<children.length; i++)
{
@@ -117,8 +120,8 @@
{
File toFile = new File(dstDir, child.getName());
toFile.createNewFile();
- FileChannel srcChannel = new
FileInputStream(child).getChannel();
- FileChannel dstChannel = new
FileOutputStream(toFile).getChannel();
+ srcChannel = new FileInputStream(child).getChannel();
+ dstChannel = new FileOutputStream(toFile).getChannel();
dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
srcChannel.close();
dstChannel.close();
@@ -130,6 +133,32 @@
copyFiles(child, newSubDir, fileFilter);
}
}
+ }
+ finally
+ {
+ if ( srcChannel != null && srcChannel.isOpen() )
+ {
+ try
+ {
+ srcChannel.close();
+ }
+ catch (Exception e)
+ {
+
+ }
+ }
+ if ( dstChannel != null && dstChannel.isOpen() )
+ {
+ try
+ {
+ dstChannel.close();
+ }
+ catch (Exception e)
+ {
+
+ }
+ }
+ }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]