mirror of
https://github.com/apache/struts.git
synced 2026-08-31 19:35:40 +00:00
Removing eplus copyright notice which was accidentally automatically added by an IDEA plugin and removing unused Spring integration classes
git-svn-id: https://svn.apache.org/repos/asf/incubator/webwork2@397918 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
-62
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright 2006 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.struts.action2.spring;
|
||||
|
||||
import org.apache.struts.action2.spring.lifecycle.ApplicationContextSessionListener;
|
||||
import com.opensymphony.xwork.ActionContext;
|
||||
import com.opensymphony.xwork.spring.SpringProxyableObjectFactory;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* SessionContextSpringProxyableObjectFactory
|
||||
*
|
||||
*/
|
||||
public class SessionContextSpringProxyableObjectFactory extends SpringProxyableObjectFactory {
|
||||
private static final Log log = LogFactory.getLog(SessionContextSpringProxyableObjectFactory.class);
|
||||
|
||||
protected ApplicationContext getApplicationContext(Map context) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Getting the session-scoped app context");
|
||||
}
|
||||
if (context == null) {
|
||||
return appContext;
|
||||
}
|
||||
Map session = (Map) context.get(ActionContext.SESSION);
|
||||
if (session == null) {
|
||||
log.warn("There is no session map in the ActionContext.");
|
||||
return appContext;
|
||||
}
|
||||
ApplicationContext sessionContext = (ApplicationContext) session.get(ApplicationContextSessionListener.APP_CONTEXT_SESSION_KEY);
|
||||
if (sessionContext == null) {
|
||||
throw new IllegalStateException("There is no application context in the user's session.");
|
||||
}
|
||||
return sessionContext;
|
||||
}
|
||||
|
||||
public Object buildBean(String beanName, Map extraContext) throws Exception {
|
||||
Object bean = super.buildBean(beanName, extraContext);
|
||||
AutowireCapableBeanFactory autoWiringBeanFactory = findAutoWiringBeanFactory(getApplicationContext(extraContext));
|
||||
return autoWireBean(bean, autoWiringBeanFactory);
|
||||
}
|
||||
|
||||
}
|
||||
+4
-2
@@ -29,6 +29,8 @@ import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import sun.rmi.runtime.Log;
|
||||
|
||||
/**
|
||||
* Struts object factory that integrates with Spring.
|
||||
* <p/>
|
||||
@@ -55,7 +57,7 @@ public class StrutsSpringObjectFactory extends SpringObjectFactory implements Ob
|
||||
log.fatal(message);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.setApplicationContext(appContext);
|
||||
|
||||
String autoWire = Configuration.getString(StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE);
|
||||
@@ -70,7 +72,7 @@ public class StrutsSpringObjectFactory extends SpringObjectFactory implements Ob
|
||||
type = AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR;
|
||||
}
|
||||
this.setAutowireStrategy(type);
|
||||
|
||||
|
||||
boolean useClassCache = "true".equals(Configuration.getString(StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_USE_CLASS_CACHE));
|
||||
this.setUseClassCache(useClassCache);
|
||||
|
||||
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2005 ePlus Corporation. All Rights Reserved.
|
||||
*/
|
||||
package org.apache.struts.action2.spring.interceptor;
|
||||
|
||||
import com.opensymphony.xwork.interceptor.AroundInterceptor;
|
||||
import com.opensymphony.xwork.ActionInvocation;
|
||||
import org.apache.struts.action2.spring.lifecycle.ApplicationContextSessionListener;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <!-- START SNIPPET: description -->
|
||||
* TODO: Give a description of the Interceptor.
|
||||
* <!-- END SNIPPET: description -->
|
||||
*
|
||||
* <!-- START SNIPPET: parameters -->
|
||||
* TODO: Describe the paramters for this Interceptor.
|
||||
* <!-- END SNIPPET: parameters -->
|
||||
*
|
||||
* <!-- START SNIPPET: extending -->
|
||||
* TODO: Discuss some possible extension of the Interceptor.
|
||||
* <!-- END SNIPPET: extending -->
|
||||
*
|
||||
* <pre>
|
||||
* <!-- START SNIPPET: example -->
|
||||
* <!-- TODO: Describe how the Interceptor reference will effect execution -->
|
||||
* <action name="someAction" class="com.examples.SomeAction">
|
||||
* TODO: fill in the interceptor reference.
|
||||
* <interceptor-ref name=""/>
|
||||
* <result name="success">good_result.ftl</result>
|
||||
* </action>
|
||||
* <!-- END SNIPPET: example -->
|
||||
* </pre>
|
||||
*
|
||||
* SessionContextAutowiringInterceptor
|
||||
*
|
||||
*/
|
||||
public class SessionContextAutowiringInterceptor extends AroundInterceptor {
|
||||
|
||||
private static final long serialVersionUID = 4352460072796174410L;
|
||||
|
||||
private Integer autowireStrategy = new Integer(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
|
||||
|
||||
public void setAutowireStrategy(Integer autowireStrategy) {
|
||||
this.autowireStrategy = autowireStrategy;
|
||||
}
|
||||
|
||||
protected void after(ActionInvocation dispatcher, String result) throws Exception {
|
||||
}
|
||||
|
||||
protected void before(ActionInvocation invocation) throws Exception {
|
||||
Map session = invocation.getInvocationContext().getSession();
|
||||
ApplicationContext applicationContext = (ApplicationContext) session.get(ApplicationContextSessionListener.APP_CONTEXT_SESSION_KEY);
|
||||
AutowireCapableBeanFactory factory = findAutoWiringBeanFactory(applicationContext);
|
||||
factory.autowireBeanProperties(invocation.getAction(),autowireStrategy.intValue(),false);
|
||||
}
|
||||
|
||||
protected AutowireCapableBeanFactory findAutoWiringBeanFactory(ApplicationContext context) {
|
||||
if (context instanceof AutowireCapableBeanFactory) {
|
||||
// Check the context
|
||||
return (AutowireCapableBeanFactory) context;
|
||||
} else if (context instanceof ConfigurableApplicationContext) {
|
||||
// Try and grab the beanFactory
|
||||
return ((ConfigurableApplicationContext) context).getBeanFactory();
|
||||
} else if (context.getParent() != null) {
|
||||
// And if all else fails, try again with the parent context
|
||||
return findAutoWiringBeanFactory(context.getParent());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-117
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright 2006 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.struts.action2.spring.lifecycle;
|
||||
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
import org.springframework.web.context.support.XmlWebApplicationContext;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.context.ApplicationContextException;
|
||||
|
||||
import javax.servlet.http.HttpSessionListener;
|
||||
import javax.servlet.http.HttpSessionEvent;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Used to set up a Spring {@link org.springframework.context.ApplicationContext}
|
||||
* in the HttpSession. It can be configured similarly to the
|
||||
*
|
||||
*/
|
||||
public class ApplicationContextSessionListener implements HttpSessionListener, Serializable {
|
||||
|
||||
private static final long serialVersionUID = -7190553643613133494L;
|
||||
|
||||
/**
|
||||
* Config param for the root WebApplicationContext implementation class to
|
||||
* use: "sessionContextClass"
|
||||
*/
|
||||
public static final String SESSION_CONTEXT_CLASS_PARAM = "sessionContextClass";
|
||||
|
||||
/**
|
||||
* Default context class for ContextLoader.
|
||||
* @see org.springframework.web.context.support.XmlWebApplicationContext
|
||||
*/
|
||||
public static final Class DEFAULT_SESSION_CONTEXT_CLASS = XmlWebApplicationContext.class;
|
||||
|
||||
/**
|
||||
* Name of servlet context parameter that can specify the config location
|
||||
* for the root context, falling back to the implementation's default
|
||||
* otherwise.
|
||||
* @see org.springframework.web.context.support.XmlWebApplicationContext#DEFAULT_CONFIG_LOCATION
|
||||
*/
|
||||
public static final String SESSION_CONFIG_LOCATION_PARAM = "sessionContextConfigLocation";
|
||||
|
||||
/**
|
||||
* Key to map the session-scoped application context into the session attributes.
|
||||
*/
|
||||
public static final String APP_CONTEXT_SESSION_KEY = "org.apache.struts.action2.spring.ApplicationContextSessionListener_APP_CONTEXT";
|
||||
|
||||
/**
|
||||
* The default session context configuration string:"classpath:session.xml"
|
||||
*/
|
||||
public static final String[] DEFAULT_SESSION_CONFIG = {"classpath:session.xml"};
|
||||
|
||||
/**
|
||||
* The application context instance created when the session is created, to be cleaned up when the session is destroyed
|
||||
*/
|
||||
private ConfigurableWebApplicationContext sessionContext;
|
||||
|
||||
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
|
||||
final HttpSession session = httpSessionEvent.getSession();
|
||||
final ServletContext servletContext = session.getServletContext();
|
||||
final WebApplicationContext appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
|
||||
|
||||
String contextClassName = servletContext.getInitParameter(SESSION_CONTEXT_CLASS_PARAM);
|
||||
Class contextClass = DEFAULT_SESSION_CONTEXT_CLASS;
|
||||
if (contextClassName != null) {
|
||||
try {
|
||||
contextClass = Class.forName(contextClassName, true, Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
throw new ApplicationContextException("Failed to load context class [" + contextClassName + "]", ex);
|
||||
}
|
||||
if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
|
||||
throw new ApplicationContextException("Custom context class [" + contextClassName +
|
||||
"] is not of type ConfigurableWebApplicationContext");
|
||||
}
|
||||
}
|
||||
|
||||
sessionContext = (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
|
||||
sessionContext.setParent(appContext);
|
||||
sessionContext.setServletContext(servletContext);
|
||||
String configLocation = servletContext.getInitParameter(SESSION_CONFIG_LOCATION_PARAM);
|
||||
if (configLocation != null) {
|
||||
sessionContext.setConfigLocations(StringUtils.tokenizeToStringArray(configLocation,
|
||||
ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));
|
||||
} else {
|
||||
sessionContext.setConfigLocations(DEFAULT_SESSION_CONFIG);
|
||||
}
|
||||
|
||||
sessionContext.refresh();
|
||||
session.setAttribute(APP_CONTEXT_SESSION_KEY, sessionContext);
|
||||
}
|
||||
|
||||
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
|
||||
sessionContext.close();
|
||||
this.sessionContext = null;
|
||||
}
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright 2006 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.struts.action2.spring.lifecycle;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
/**
|
||||
* ApplicationContextListener that sets up the environment so that XWork and
|
||||
* Struts can load data and information from Spring. Relies on Spring's
|
||||
* {@link org.springframework.web.context.ContextLoaderListener}having been
|
||||
* called first.
|
||||
*
|
||||
* @deprecated Please configure struts.property to use {@link org.apache.struts.action2.spring.StrutsSpringObjectFactory}
|
||||
*/
|
||||
public class SpringObjectFactoryListener implements ServletContextListener {
|
||||
private static final Log log = LogFactory.getLog(SpringObjectFactoryListener.class);
|
||||
|
||||
public void contextInitialized(ServletContextEvent event) {
|
||||
log.fatal("SpringObjectFactoryListener is deprecated and no longer does anything - you should remove it from web.xml\n" +
|
||||
"Please set struts.objectFactory = spring to enable Spring-Struts integration.");
|
||||
}
|
||||
|
||||
public void contextDestroyed(ServletContextEvent arg0) {
|
||||
// Nothing to do.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user