You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by we...@apache.org on 2004/07/20 15:55:12 UTC
cvs commit: jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine SpringEngine.java PicoEngine.java AbstractEngine.java JetspeedServlet.java Engine.java JetspeedEngine.java
weaver 2004/07/20 06:55:12
Modified: portal/src/java/org/apache/jetspeed/engine
JetspeedServlet.java Engine.java
Added: portal/src/java/org/apache/jetspeed/engine SpringEngine.java
PicoEngine.java AbstractEngine.java
Removed: portal/src/java/org/apache/jetspeed/engine
JetspeedEngine.java
Log:
- Added Spring Framework Engine.
- JetspeedEngine pulled up into an AbstractEngine and a Pico specific PicoEngine
Revision Changes Path
1.7 +9 -2 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/JetspeedServlet.java
Index: JetspeedServlet.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/JetspeedServlet.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JetspeedServlet.java 31 Mar 2004 01:19:24 -0000 1.6
+++ JetspeedServlet.java 20 Jul 2004 13:55:12 -0000 1.7
@@ -127,7 +127,14 @@
properties.setProperty(WEBAPP_ROOT_KEY, webappRoot);
console.info("JetspeedServlet attempting to create the portlet engine...");
- engine = Jetspeed.createEngine(properties, applicationRoot, config);
+ String engineClassName = config.getInitParameter("engine");
+ if(engineClassName == null)
+ {
+ throw new IllegalStateException("You must define the engine init-parameter org.apache.jetspeed.engine.JetspeedServlet servlet.");
+ }
+ Class engineClass = Class.forName(engineClassName);
+
+ engine = Jetspeed.createEngine(properties, applicationRoot, config, engineClass);
if (engine != null)
{
console.info("JetspeedServlet successfuly created the portal Engine. " + engine);
1.5 +2 -1 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/Engine.java
Index: Engine.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/Engine.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Engine.java 8 Mar 2004 00:26:46 -0000 1.4
+++ Engine.java 20 Jul 2004 13:55:12 -0000 1.5
@@ -19,6 +19,7 @@
import org.apache.commons.configuration.Configuration;
import org.apache.jetspeed.PortalContext;
+import org.apache.jetspeed.components.ComponentManagement;
import org.apache.jetspeed.components.ComponentManager;
import org.apache.jetspeed.exception.JetspeedException;
import org.apache.jetspeed.pipeline.Pipeline;
1.1 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/SpringEngine.java
Index: SpringEngine.java
===================================================================
/*
* 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.engine;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.naming.NamingException;
import org.apache.commons.configuration.Configuration;
import org.apache.jetspeed.components.SpringComponentManager;
import org.apache.jetspeed.components.datasource.DatasourceComponent;
import org.apache.jetspeed.components.jndi.JNDIComponent;
import org.springframework.beans.factory.xml.XmlBeanFactory;
/**
* <p>
* SpringEngine
* </p>
* <p>
*
* </p>
*
* @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
* @version $Id: SpringEngine.java,v 1.1 2004/07/20 13:55:11 weaver Exp $
*
*/
public class SpringEngine extends AbstractEngine
{
/**
* <p>
* initComponents
* </p>
*
* @see org.apache.jetspeed.engine.AbstractEngine#initComponents(org.apache.commons.configuration.Configuration)
* @param configuration
* @throws IOException
* @throws ClassNotFoundException
* @throws NamingException
*/
protected void initComponents( Configuration configuration ) throws IOException, ClassNotFoundException,
NamingException
{
String relativeApplicationRoot = getRealPath("/");
String absApplicationRoot = new File(relativeApplicationRoot).getCanonicalPath();
// String absoluteApplicationRoot = new File(relativeApplicationRoot).getCanonicalPath();
System.setProperty("applicationRoot", absApplicationRoot);
ArrayList configs = new ArrayList();
if (useInternalJNDI)
{
configs.add("file:///"+absApplicationRoot + configuration.getString("jetspeed.spring.datasource.xml",
"/WEB-INF/assembly/pooled-datasource-support.xml"));
}
configs.add("file:///"+absApplicationRoot + configuration.getString("jetspeed.spring.xml", "/WEB-INF/assembly/jetspeed-spring.xml"));
componentManager = new SpringComponentManager((String[])configs.toArray(new String[configs.size()]), null);
}
protected void enableJNDI( Configuration configuration ) throws IOException
{
try
{
XmlBeanFactory dsBeanFactory = null;
if (useInternalJNDI)
{
JNDIComponent jndi = (JNDIComponent) componentManager.getComponent(JNDIComponent.class.getName());
if (jndi != null)
{
DatasourceComponent ds = (DatasourceComponent) componentManager.getComponent(DatasourceComponent.class
.getName());
if (ds != null)
{
jndi.bindObject("comp/env/jdbc/jetspeed", ds.getDatasource());
jndi.bindToCurrentThread();
}
}
}
}
catch (NamingException e)
{
// skip for now
}
}
}
1.1 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/PicoEngine.java
Index: PicoEngine.java
===================================================================
/*
* 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.engine;
import java.io.File;
import java.io.IOException;
import javax.naming.NamingException;
import org.apache.commons.configuration.Configuration;
import org.apache.jetspeed.components.PicoComponentManager;
import org.apache.jetspeed.components.datasource.DatasourceComponent;
import org.apache.jetspeed.components.jndi.JNDIComponent;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.defaults.DefaultPicoContainer;
import org.picocontainer.defaults.ObjectReference;
import org.picocontainer.defaults.SimpleReference;
/**
* Jetspeed Engine implementation
*
* @author <a href="mailto:david@bluesunrise.com">David Sean Taylor </a>
* @version $Id: PicoEngine.java,v 1.1 2004/07/20 13:55:11 weaver Exp $
*/
public class PicoEngine extends AbstractEngine implements Engine
{
protected void initComponents( Configuration configuration )
throws IOException, ClassNotFoundException, NamingException
{
String applicationRoot = getRealPath("/");
String assemblyScript = configuration.getString(
"jetspeed.root.assembly", "/WEB-INF/assembly/jetspeed.groovy");
File containerAssembler = new File(applicationRoot + assemblyScript);
ObjectReference bootContainerRef = new SimpleReference();
MutablePicoContainer bootContainer = new DefaultPicoContainer();
bootContainer.registerComponentInstance("portal_configuration", configuration);
componentManager = new PicoComponentManager(containerAssembler, bootContainer, "PORTAL_SCOPE");
try
{
if (useInternalJNDI)
{
JNDIComponent jndi = (JNDIComponent) componentManager
.getComponent(JNDIComponent.class);
if (jndi != null)
{
DatasourceComponent ds = (DatasourceComponent) componentManager
.getComponent(DatasourceComponent.class);
if (ds != null)
{
jndi.bindObject("comp/env/jdbc/jetspeed", ds
.getDatasource());
jndi.bindToCurrentThread();
}
}
}
}
catch (NamingException e)
{
// skip for now
}
}
}
1.1 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/AbstractEngine.java
Index: AbstractEngine.java
===================================================================
/*
* 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.engine;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Properties;
import javax.naming.NamingException;
import javax.servlet.ServletConfig;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Log4jFactory;
import org.apache.jetspeed.JetspeedPortalContext;
import org.apache.jetspeed.PortalContext;
import org.apache.jetspeed.PortalReservedParameters;
import org.apache.jetspeed.components.ComponentManager;
import org.apache.jetspeed.components.jndi.JNDIComponent;
import org.apache.jetspeed.container.services.JetspeedContainerServices;
import org.apache.jetspeed.container.services.log.ContainerLogAdaptor;
import org.apache.jetspeed.cps.CPSInitializationException;
import org.apache.jetspeed.cps.CommonPortletServices;
import org.apache.jetspeed.exception.JetspeedException;
import org.apache.jetspeed.pipeline.Pipeline;
import org.apache.jetspeed.pipeline.descriptor.PipelineDescriptor;
import org.apache.jetspeed.pipeline.descriptor.XmlReader;
import org.apache.jetspeed.request.RequestContext;
import org.apache.jetspeed.services.factory.FactoryManager;
import org.apache.jetspeed.services.information.InformationProviderManager;
import org.apache.jetspeed.services.information.InformationProviderServiceService;
import org.apache.log4j.PropertyConfigurator;
import org.apache.ojb.broker.util.ClassHelper;
import org.apache.pluto.PortletContainer;
import org.apache.pluto.PortletContainerException;
import org.apache.pluto.services.information.InformationProviderService;
/**
* <p>
* AbstractEngine
* </p>
* <p>
*
* </p>
* @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
* @version $Id: AbstractEngine.java,v 1.1 2004/07/20 13:55:12 weaver Exp $
*
*/
public abstract class AbstractEngine implements Engine
{
protected static final String JNDI_SUPPORT_FLAG_KEY = "portal.use.internal.jndi";
private PortalContext context;
private ServletConfig config = null;
private Pipeline defaultPipeline = null;
private Class pipelineClass = null;
private HashMap pipelines = new HashMap();
protected ComponentManager componentManager = null;
private static final Log log = LogFactory.getLog(PicoEngine.class);
private static final Log console = LogFactory.getLog(CONSOLE_LOGGER);
/** stores the most recent RequestContext on a per thread basis */
private ThreadLocal tlRequestContext = new ThreadLocal();
protected boolean useInternalJNDI;
/**
* Initializes the engine with a commons configuration, starting all early
* initable services.
*
* @param configuration
* a commons <code>Configuration</code> set
* @param applicationRoot
* a <code>String</code> path to the application root for
* resources
* @param
* @throws JetspeedException
* when the engine fails to initilialize
*/
public void init( Configuration configuration, String applicationRoot, ServletConfig config ) throws JetspeedException
{
try
{
this.context = new JetspeedPortalContext(this);
this.config = config;
context.setApplicationRoot(applicationRoot);
context.setConfiguration(configuration);
useInternalJNDI = configuration.getBoolean(JNDI_SUPPORT_FLAG_KEY,
true);
configuration.setProperty(JetspeedEngineConstants.APPLICATION_ROOT_KEY, applicationRoot);
System.out.println("JNDI System Property flag "+System.getProperty(JNDI_SUPPORT_FLAG_KEY));
if(System.getProperty(JNDI_SUPPORT_FLAG_KEY) == null)
{
System.setProperty(JNDI_SUPPORT_FLAG_KEY, String
.valueOf(useInternalJNDI));
}
else
{
// System property over rides the configurtaion
useInternalJNDI = Boolean.getBoolean(JNDI_SUPPORT_FLAG_KEY);
log.warn("Internal JNDI has been flagged "+useInternalJNDI+" by the "+JNDI_SUPPORT_FLAG_KEY+" system property. This overrides the configuration setting of "+configuration.getBoolean(JNDI_SUPPORT_FLAG_KEY,
true));
}
//
// Configure Log4J
//
String log4jFile = configuration.getString(LOG4J_CONFIG_FILE,
LOG4J_CONFIG_FILE_DEFAULT);
log4jFile = getRealPath(log4jFile);
Properties p = new Properties();
p.load(new FileInputStream(log4jFile));
p.setProperty(APPLICATION_ROOT_KEY, context.getApplicationRoot());
PropertyConfigurator.configure(p);
log.info("Configured log4j from " + log4jFile);
// Set up Commons Logging to use the Log4J Logging
System.getProperties().setProperty(LogFactory.class.getName(),
Log4jFactory.class.getName());
//
// bootstrap the initable services
//
initComponents(configuration);
log.info("Components initialization complete");
initServices();
log.info("Service initialization complete");
// patch up OJB
ClassLoader ploader2 = this.getClass().getClassLoader();
ClassHelper.setClassLoader(ploader2);
//
// create the pipelines
//
log.info("Creating Jetspeed piplines...");
createPipelines();
log.info("Jetspeed piplines created sucessfully.");
//
// Make sure JMX is init'd
//
// log.info("Jump starting JMX MBean services...");
// JMX.startJMX();
// log.info("JMX services sucessfully started.");
}
catch (Throwable e)
{
e.printStackTrace();
log.error(e.toString());
throw new JetspeedException("Jetspeed Initialization exception!", e);
}
}
/**
* Get the servlet configuration if this engine is running under a servlet
* container.
*
* @return config The servlet configuration
*/
public ServletConfig getServletConfig()
{
return this.config;
}
/**
* Initializes the portlet container given a servlet configuration.
*
* @param config
* The servlet configuration.
*/
public void initContainer( ServletConfig config ) throws PortletContainerException
{
try
{
PortletContainer container = (PortletContainer) componentManager
.getComponent(PortletContainer.class);
JetspeedContainerServices environment = new JetspeedContainerServices();
environment.addService(ContainerLogAdaptor.getService());
environment.addService(FactoryManager.getService());
InformationProviderServiceService ips = InformationProviderManager
.getService();
ips.init(config, null);
environment.addServiceForClass(InformationProviderService.class,
ips);
//TODO !!! Pluto has changed this siganture There is now a
// container unique id string and Properties.
// WE need to figure what these are really for.
container.init("jetspeed", config, environment, new Properties());
}
catch (Throwable e)
{
console.error("Unable to initalize Engine.", e);
log.error("Unable to initalize Engine.", e);
if (e instanceof PortletContainerException)
{
throw (PortletContainerException) e;
}
else
{
throw new PortletContainerException(e);
}
}
}
public void shutdown() throws JetspeedException
{
CommonPortletServices.getInstance().shutdownServices();
try
{
PortletContainer container = (PortletContainer) componentManager
.getComponent(PortletContainer.class);
if (container != null)
{
container.shutdown();
}
componentManager.stop();
}
catch (PortletContainerException e)
{
throw new JetspeedException(e);
}
System.gc();
}
public void service( RequestContext context ) throws JetspeedException
{
// requestContextPerThread.put(Thread.currentThread(), context);
try
{
if (useInternalJNDI)
{
// bind the current JNDI context to this service thread.
JNDIComponent jndi = (JNDIComponent) componentManager
.getComponent(JNDIComponent.class);
if (jndi != null)
{
jndi.bindToCurrentThread();
}
}
String targetPipeline = context
.getRequestParameter(PortalReservedParameters.PIPELINE);
if (null == targetPipeline)
{
targetPipeline = (String)context.getAttribute(PortalReservedParameters.PIPELINE);
}
tlRequestContext.set(context);
Pipeline pipeline = defaultPipeline;
if (targetPipeline != null)
{
Pipeline specificPipeline = (Pipeline) pipelines
.get(targetPipeline);
if (specificPipeline != null)
{
pipeline = specificPipeline;
}
}
pipeline.invoke(context);
}
catch (Throwable t)
{
String msg = "JetspeedEngine unable to service request: "
+ t.toString();
log.error(msg, t);
// throw new JetspeedException(msg, t);
}
}
/**
* Returns the context associated with this engine.
*
* @return an <code>EngineContext</code> associated with this engine
*/
public PortalContext getContext()
{
return this.context;
}
/**
* Given a application relative path, returns the real path relative to the
* application root
*
*/
public String getRealPath( String path )
{
String result = "";
String base = context.getApplicationRoot();
if (base.endsWith(java.io.File.separator))
{
if (path.startsWith("/"))
{
result = base.concat(path.substring(1));
return result;
}
}
else
{
if (!path.startsWith("/"))
{
result = base.concat("/").concat(path);
return result;
}
}
return base.concat(path);
}
protected abstract void initComponents( Configuration configuration )
throws IOException, ClassNotFoundException, NamingException;
private void initServices() throws CPSInitializationException
{
// Get the instance of the service manager
// ServiceManager serviceManager = JetspeedServices.getInstance();
CommonPortletServices cps = CommonPortletServices.getInstance();
// Set the service managers application root. In our
// case it is the webapp context.
cps.init(this.getContext().getConfiguration(), context
.getApplicationRoot(), false);
//serviceManager.setApplicationRoot(context.getApplicationRoot());
//serviceManager.setConfiguration(this.getContext().getConfiguration());
// Initialize the service manager. Services
// that have its 'earlyInit' property set to
// a value of 'true' will be started when
// the service manager is initialized.
//serviceManager.init();
}
/**
* Creates the Jetspeed pipelines for request processing.
*
* @throws CPSInitializationException
*/
private void createPipelines() throws CPSInitializationException
{
String className = this.getContext().getConfiguration().getString(
PIPELINE_CLASS, null);
String defaultPipelineName = this.getContext().getConfiguration()
.getString(PIPELINE_DEFAULT, "jetspeed-pipeline");
if (null == className)
{
throw new CPSInitializationException(
"Failed to initialize pipeline, missing configuration entry: "
+ PIPELINE_CLASS);
}
try
{
pipelineClass = Class.forName(className);
}
catch (Exception e)
{
throw new CPSInitializationException(
"Failed to initialize pipeline, couldnt create pipeline class");
}
String pipelinesDir = this.getContext().getConfiguration().getString(
PIPELINE_DIRECTORY, "/WEB-INF/conf/pipelines/");
File directory = new File(getRealPath(pipelinesDir));
if (directory == null || !directory.exists())
{
throw new CPSInitializationException(
"Failed to initialize pipeline, could not find pipeline directory");
}
File[] pipelineDescriptors = directory.listFiles();
for (int ix = 0; ix < pipelineDescriptors.length; ix++)
{
if (pipelineDescriptors[ix].isDirectory())
{
continue;
}
Pipeline pipeline = createPipeline(pipelineDescriptors[ix]);
String name = pipelineDescriptors[ix].getName();
int index = name.lastIndexOf(".");
if (index > 0)
{
name = name.substring(0, index);
}
if (name.equalsIgnoreCase(defaultPipelineName))
{
defaultPipeline = pipeline;
}
pipelines.put(name, pipeline);
}
}
/**
* Creates a pipeline from a pipeline descriptor file.
*
* @param file
* the descriptor file describing the pipeline.
* @return The new pipeline.
* @throws CPSInitializationException
*/
private Pipeline createPipeline( File file ) throws CPSInitializationException
{
Pipeline pipeline;
PipelineDescriptor descriptor;
try
{
System.out.println("Class loader is " + Thread.currentThread().getContextClassLoader().getClass().getName());
pipeline = (Pipeline) pipelineClass.newInstance();
XmlReader reader = new XmlReader(PipelineDescriptor.class);
descriptor = (PipelineDescriptor) reader.parse(new FileInputStream(
file));
}
catch (Throwable e)
{
System.out.println("Failure *****************************");
e.printStackTrace();
throw new CPSInitializationException(
"Failed to read pipeline descriptor from deployment", e);
}
try
{
pipeline.setDescriptor(descriptor);
pipeline.initialize();
}
catch (Exception e)
{
throw new CPSInitializationException(
"Failed to initialize pipeline: ", e);
}
return pipeline;
}
public Pipeline getPipeline( String pipelineName )
{
return (Pipeline) this.pipelines.get(pipelineName);
}
public Pipeline getPipeline()
{
return this.defaultPipeline;
}
/**
* @see org.apache.jetspeed.engine.Engine#getCurrentRequestContext()
*/
public RequestContext getCurrentRequestContext()
{
return (RequestContext) tlRequestContext.get();
}
public ComponentManager getComponentManager()
{
return this.componentManager;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org