Author: alessio.soldano(a)jboss.com
Date: 2011-04-16 21:57:59 -0400 (Sat, 16 Apr 2011)
New Revision: 14125
Added:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/SecurityActions.java
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerAdapter.java
Log:
[JBWS-3239] Fix NettyHttpServerAdapter classloading
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerAdapter.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerAdapter.java 2011-04-17
01:54:10 UTC (rev 14124)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerAdapter.java 2011-04-17
01:57:59 UTC (rev 14125)
@@ -41,6 +41,7 @@
import org.jboss.wsf.framework.deployment.URLPatternDeploymentAspect;
import org.jboss.wsf.spi.SPIProvider;
import org.jboss.wsf.spi.SPIProviderResolver;
+import org.jboss.wsf.spi.classloading.ClassLoaderProvider;
import org.jboss.wsf.spi.deployment.ArchiveDeployment;
import org.jboss.wsf.spi.deployment.Deployment;
import org.jboss.wsf.spi.deployment.Deployment.DeploymentType;
@@ -59,16 +60,19 @@
final class NettyHttpServerAdapter implements HttpServer
{
- /** JBossWS SPI provider. */
- private static final SPIProvider SPI_PROVIDER =
SPIProviderResolver.getInstance().getProvider();
-
/** Deployment model factory. */
- private static final DeploymentModelFactory DEPLOYMENT_FACTORY =
NettyHttpServerAdapter.SPI_PROVIDER
- .getSPI(DeploymentModelFactory.class);
+ private static final DeploymentModelFactory DEPLOYMENT_FACTORY;
/** Request handler factory. */
private static final NettyRequestHandlerFactory<NettyRequestHandlerImpl>
REQUEST_HANDLER_FACTORY = NettyRequestHandlerFactoryImpl
.getInstance();
+
+ static
+ {
+ final ClassLoader cl =
ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader();
+ final SPIProvider spiProvider = SPIProviderResolver.getInstance(cl).getProvider();
+ DEPLOYMENT_FACTORY = spiProvider.getSPI(DeploymentModelFactory.class, cl);
+ }
/**
* Constructor.
@@ -103,7 +107,18 @@
final DeploymentAspectManagerImpl daManager = new DeploymentAspectManagerImpl();
daManager.setDeploymentAspects(this.getDeploymentAspects());
- daManager.deploy(dep);
+ ClassLoader orig = SecurityActions.getContextClassLoader();
+ try
+ {
+ SecurityActions.setContextClassLoader(ClassLoaderProvider.getDefaultProvider()
+ .getServerIntegrationClassLoader());
+ daManager.deploy(dep);
+ }
+ finally
+ {
+ SecurityActions.setContextClassLoader(orig);
+ }
+
epImpl.setDeployment(dep);
final NettyHttpServer server =
NettyHttpServerFactory.getNettyHttpServer(epImpl.getPort(),
NettyHttpServerAdapter.REQUEST_HANDLER_FACTORY);
@@ -127,7 +142,17 @@
final DeploymentAspectManagerImpl daManager = new DeploymentAspectManagerImpl();
daManager.setDeploymentAspects(this.getDeploymentAspects());
- daManager.undeploy(epImpl.getDeployment());
+ ClassLoader orig = SecurityActions.getContextClassLoader();
+ try
+ {
+ SecurityActions.setContextClassLoader(ClassLoaderProvider.getDefaultProvider()
+ .getServerIntegrationClassLoader());
+ daManager.undeploy(epImpl.getDeployment());
+ }
+ finally
+ {
+ SecurityActions.setContextClassLoader(orig);
+ }
}
/**
@@ -181,18 +206,27 @@
{
final List<DeploymentAspect> retVal = new
LinkedList<DeploymentAspect>();
- // TODO: native stack can't use framework classes directly
- retVal.add(new NettyHandlerDeploymentAspect());
- retVal.add(new BackwardCompatibleContextRootDeploymentAspect());
- retVal.add(new URLPatternDeploymentAspect());
- retVal.add(new EndpointAddressDeploymentAspect());
- retVal.add(new EndpointNameDeploymentAspect());
- retVal.add(new UnifiedMetaDataDeploymentAspect());
- retVal.add(new ServiceEndpointInvokerDeploymentAspect());
- retVal.add(new PublishContractDeploymentAspect());
- retVal.add(new EagerInitializeDeploymentAspect());
- retVal.add(new EndpointRegistryDeploymentAspect());
- retVal.add(new EndpointLifecycleDeploymentAspect());
+ ClassLoader orig = SecurityActions.getContextClassLoader();
+ try
+ {
+
SecurityActions.setContextClassLoader(ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader());
+ // TODO: native stack can't use framework classes directly
+ retVal.add(new NettyHandlerDeploymentAspect());
+ retVal.add(new BackwardCompatibleContextRootDeploymentAspect());
+ retVal.add(new URLPatternDeploymentAspect());
+ retVal.add(new EndpointAddressDeploymentAspect());
+ retVal.add(new EndpointNameDeploymentAspect());
+ retVal.add(new UnifiedMetaDataDeploymentAspect());
+ retVal.add(new ServiceEndpointInvokerDeploymentAspect());
+ retVal.add(new PublishContractDeploymentAspect());
+ retVal.add(new EagerInitializeDeploymentAspect());
+ retVal.add(new EndpointRegistryDeploymentAspect());
+ retVal.add(new EndpointLifecycleDeploymentAspect());
+ }
+ finally
+ {
+ SecurityActions.setContextClassLoader(orig);
+ }
return retVal;
}
Added:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/SecurityActions.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/SecurityActions.java
(rev 0)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/SecurityActions.java 2011-04-17
01:57:59 UTC (rev 14125)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.core.jaxws.spi.http;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 17-Feb-2010
+ *
+ */
+class SecurityActions
+{
+ /**
+ * Get context classloader.
+ *
+ * @return the current context classloader
+ */
+ static ClassLoader getContextClassLoader()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+
+ /**
+ * Set context classloader.
+ *
+ * @param classLoader the classloader
+ */
+ static void setContextClassLoader(final ClassLoader classLoader)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ }
+ else
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ return null;
+ }
+ });
+ }
+ }
+
+}