Author: alessio.soldano(a)jboss.com
Date: 2011-04-11 18:35:36 -0400 (Mon, 11 Apr 2011)
New Revision: 14056
Added:
common/branches/asoldano/src/main/java/org/jboss/ws/core/utils/DelegateClassLoader.java
Modified:
common/branches/asoldano/src/main/java/org/jboss/wsf/common/servlet/AbstractEndpointServlet.java
Log:
Using proper classloader for getting endpoint registry in AbstractEndpointServlet + adding
DelegateClassLoader to jbws-common
Added:
common/branches/asoldano/src/main/java/org/jboss/ws/core/utils/DelegateClassLoader.java
===================================================================
---
common/branches/asoldano/src/main/java/org/jboss/ws/core/utils/DelegateClassLoader.java
(rev 0)
+++
common/branches/asoldano/src/main/java/org/jboss/ws/core/utils/DelegateClassLoader.java 2011-04-11
22:35:36 UTC (rev 14056)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.security.SecureClassLoader;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+
+/**
+ * A delegate classloader
+ *
+ * @author alessio.soldano(a)jboss.com
+ *
+ */
+public class DelegateClassLoader extends SecureClassLoader
+{
+ private ClassLoader delegate;
+
+ private ClassLoader parent;
+
+ public DelegateClassLoader(final ClassLoader delegate, final ClassLoader parent)
+ {
+ super(parent);
+ this.delegate = delegate;
+ this.parent = parent;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Class<?> loadClass(final String className) throws ClassNotFoundException
+ {
+ if (parent != null)
+ {
+ try
+ {
+ return parent.loadClass(className);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ //NOOP, use delegate
+ }
+ }
+ return delegate.loadClass(className);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public URL getResource(final String name)
+ {
+ URL url = null;
+ if (parent != null)
+ {
+ url = parent.getResource(name);
+ }
+ return (url == null) ? delegate.getResource(name) : url;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Enumeration<URL> getResources(final String name) throws IOException
+ {
+ final ArrayList<Enumeration<URL>> foundResources = new
ArrayList<Enumeration<URL>>();
+
+ foundResources.add(delegate.getResources(name));
+ if (parent != null)
+ {
+ foundResources.add(parent.getResources(name));
+ }
+
+ return new Enumeration<URL>()
+ {
+ private int position = foundResources.size() - 1;
+
+ public boolean hasMoreElements()
+ {
+ while (position >= 0)
+ {
+ if (foundResources.get(position).hasMoreElements())
+ {
+ return true;
+ }
+ position--;
+ }
+ return false;
+ }
+
+ public URL nextElement()
+ {
+ while (position >= 0)
+ {
+ try
+ {
+ return (foundResources.get(position)).nextElement();
+ }
+ catch (NoSuchElementException e)
+ {
+ }
+ position--;
+ }
+ throw new NoSuchElementException();
+ }
+ };
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public InputStream getResourceAsStream(final String name)
+ {
+ URL foundResource = getResource(name);
+ if (foundResource != null)
+ {
+ try
+ {
+ return foundResource.openStream();
+ }
+ catch (IOException e)
+ {
+ }
+ }
+ return null;
+ }
+}
\ No newline at end of file
Modified:
common/branches/asoldano/src/main/java/org/jboss/wsf/common/servlet/AbstractEndpointServlet.java
===================================================================
---
common/branches/asoldano/src/main/java/org/jboss/wsf/common/servlet/AbstractEndpointServlet.java 2011-04-11
22:32:53 UTC (rev 14055)
+++
common/branches/asoldano/src/main/java/org/jboss/wsf/common/servlet/AbstractEndpointServlet.java 2011-04-11
22:35:36 UTC (rev 14056)
@@ -35,6 +35,7 @@
import org.jboss.wsf.common.ObjectNameFactory;
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.Deployment;
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.invocation.EndpointAssociation;
@@ -54,7 +55,6 @@
public abstract class AbstractEndpointServlet extends HttpServlet
{
- private final SPIProvider spiProvider =
SPIProviderResolver.getInstance().getProvider();
protected Endpoint endpoint;
private EndpointRegistry epRegistry;
@@ -133,7 +133,9 @@
*/
private void initRegistry()
{
- epRegistry =
spiProvider.getSPI(EndpointRegistryFactory.class).getEndpointRegistry();
+ ClassLoader cl =
ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader();
+ SPIProvider spiProvider = SPIProviderResolver.getInstance(cl).getProvider();
+ epRegistry = spiProvider.getSPI(EndpointRegistryFactory.class,
cl).getEndpointRegistry();
}
/**