Author: darran.lofthouse(a)jboss.com
Date: 2010-12-01 11:54:17 -0500 (Wed, 01 Dec 2010)
New Revision: 13372
Modified:
stack/cxf/branches/jbossws-cxf-3.1.2.SP7_JBPAPP-5489/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java
Log:
[JBPAPP-5489] CXF integration initialises endpoints multiple times.
Modified:
stack/cxf/branches/jbossws-cxf-3.1.2.SP7_JBPAPP-5489/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java
===================================================================
---
stack/cxf/branches/jbossws-cxf-3.1.2.SP7_JBPAPP-5489/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java 2010-12-01
16:14:21 UTC (rev 13371)
+++
stack/cxf/branches/jbossws-cxf-3.1.2.SP7_JBPAPP-5489/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java 2010-12-01
16:54:17 UTC (rev 13372)
@@ -67,6 +67,10 @@
{
public static final String PARAM_CXF_BEANS_URL = "jbossws.cxf.beans.url";
+ private static final String CHILD_CONTEXT_ATTRIBUTE =
"jbossws.cxf.childCtx";
+ private static final String BUS_ATTRIBUTE = "jbossws.cxf.bus";
+ private static final String CONTROLLER_ATTRIBUTE =
"jbossws.cxf.controller";
+
private static Logger log = Logger.getLogger(CXFServletExt.class);
protected Endpoint endpoint;
@@ -78,7 +82,7 @@
{
super.init(servletConfig);
}
-
+
@Override
public ServletController createServletController(ServletConfig servletConfig)
{
@@ -89,24 +93,44 @@
@Override
public void loadBus(ServletConfig servletConfig) throws ServletException
{
- super.loadBus(servletConfig);
-
ServletContext svCtx = getServletContext();
- ApplicationContext appCtx =
(ApplicationContext)svCtx.getAttribute("org.springframework.web.context.WebApplicationContext.ROOT");
+ synchronized (svCtx)
+ {
+ Bus bus = (Bus)svCtx.getAttribute(BUS_ATTRIBUTE);
+ if (bus != null)
+ {
+ this.bus = bus;
+ controller = (ServletController)svCtx.getAttribute(CONTROLLER_ATTRIBUTE);
+ }
+ else
+ {
+ super.loadBus(servletConfig);
+ bus = getBus();
+ svCtx.setAttribute(BUS_ATTRIBUTE, bus);
+ svCtx.setAttribute(CONTROLLER_ATTRIBUTE, getController());
+ svCtx.setAttribute(ServletController.class.getName(), getController());
+ }
- Bus bus = getBus();
- //Install our SoapTransportFactory to allow for proper soap address rewrite
- DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
- SoapTransportFactory factory = new SoapTransportFactoryExt();
- factory.setBus(bus);
- dfm.registerDestinationFactory(Constants.NS_SOAP11, factory);
- dfm.registerDestinationFactory(Constants.NS_SOAP12, factory);
+ ApplicationContext appCtx =
(ApplicationContext)svCtx.getAttribute("org.springframework.web.context.WebApplicationContext.ROOT");
- //Init the Endpoint
- initEndpoint(servletConfig);
-
- //Load additional configurations
- loadAdditionalConfigExt(appCtx, servletConfig);
+ //Install our SoapTransportFactory to allow for proper soap address rewrite
+ DestinationFactoryManager dfm =
bus.getExtension(DestinationFactoryManager.class);
+ SoapTransportFactory factory = new SoapTransportFactoryExt();
+ factory.setBus(bus);
+ dfm.registerDestinationFactory(Constants.NS_SOAP11, factory);
+ dfm.registerDestinationFactory(Constants.NS_SOAP12, factory);
+
+ //Init the Endpoint
+ initEndpoint(servletConfig);
+
+ childCtx =
(GenericApplicationContext)svCtx.getAttribute(CHILD_CONTEXT_ATTRIBUTE);
+ if (childCtx == null)
+ {
+ //Load additional configurations
+ loadAdditionalConfigExt(appCtx, servletConfig);
+ svCtx.setAttribute(CHILD_CONTEXT_ATTRIBUTE, childCtx);
+ }
+ }
}
private void initEndpoint(ServletConfig servletConfig)
@@ -117,15 +141,13 @@
ServletContext context = servletConfig.getServletContext();
String contextPath = context.getContextPath();
endpoint = initServiceEndpoint(contextPath);
-
+
//Install the JBossWS resource resolver
ResourceResolver resourceResolver =
endpoint.getAttachment(ResourceResolver.class);
if (resourceResolver != null)
{
bus.getExtension(ResourceManager.class).addResourceResolver(resourceResolver);
}
-
- context.setAttribute(ServletController.class.getName(), getController());
}
private void loadAdditionalConfigExt(ApplicationContext ctx, ServletConfig
servletConfig) throws ServletException
@@ -151,7 +173,7 @@
childCtx.refresh();
}
}
-
+
@Override
protected void invoke(HttpServletRequest req, HttpServletResponse res) throws
ServletException
{
@@ -177,7 +199,10 @@
public void destroy()
{
if (childCtx != null)
+ {
childCtx.destroy();
+ childCtx = null;
+ }
super.destroy();
}