Skip to content

Commit

Permalink
Adding a metadata class for jaxrs and making WSFServlet suitable for …
Browse files Browse the repository at this point in the history
…jaxrs too
  • Loading branch information
asoldano committed Jan 18, 2016
1 parent a4d4aa9 commit ec4dcf6
Show file tree
Hide file tree
Showing 3 changed files with 283 additions and 2 deletions.
@@ -0,0 +1,113 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, 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.wsf.spi.classloading;

import java.security.AccessController;
import java.security.Permission;
import java.security.PrivilegedAction;

/**
* SPI for getting AS classloaders
*
* @author alessio.soldano@jboss.com
* @since 18-Jan-2016
*
*/
public abstract class JAXRSClassLoaderProvider
{
private static final RuntimePermission SET_DEFAULT_CLASSLOADER_PROVIDER = new RuntimePermission("org.jboss.wsf.spi.SET_DEFAULT_CLASSLOADER_PROVIDER");

private static JAXRSClassLoaderProvider provider = new JAXRSClassLoaderProvider()
{
@Override
public ClassLoader getJAXRSSubsystemClassLoader()
{
return getContextClassLoader();
}

@Override
public ClassLoader getServerIntegrationClassLoader()
{
return getContextClassLoader();
}

};
private static volatile boolean set = false;

public static void setDefaultProvider(JAXRSClassLoaderProvider p)
{
checkPermission(SET_DEFAULT_CLASSLOADER_PROVIDER);
provider = p;
set = true;
}

public static JAXRSClassLoaderProvider getDefaultProvider()
{
return provider;
}

public static boolean isSet()
{
return set;
}

/**
* Return the ClassLoader instance having visibility over the application server ws subsystem only
*
* @return classloader
*/
public abstract ClassLoader getJAXRSSubsystemClassLoader();

/**
* Return the ClassLoader instance having visibility over the all server side ws libraries (for JAXWS usage)
*
* @return classloader
*/
public abstract ClassLoader getServerIntegrationClassLoader();

static ClassLoader getContextClassLoader()
{
if (System.getSecurityManager() == null)
{
return Thread.currentThread().getContextClassLoader();
}
else
{
return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
public ClassLoader run()
{
return Thread.currentThread().getContextClassLoader();
}
});
}
}

private static void checkPermission(final Permission permission)
{
SecurityManager securityManager = System.getSecurityManager();
if (securityManager != null)
{
AccessController.checkPermission(permission);
}
}
}
12 changes: 10 additions & 2 deletions src/main/java/org/jboss/wsf/spi/deployment/WSFServlet.java
Expand Up @@ -33,6 +33,7 @@
import javax.servlet.http.HttpServletResponse;

import org.jboss.wsf.spi.classloading.ClassLoaderProvider;
import org.jboss.wsf.spi.classloading.JAXRSClassLoaderProvider;

/**
*
Expand All @@ -45,6 +46,7 @@ public class WSFServlet extends HttpServlet
private static final long serialVersionUID = -1958443536378468262L;

public static final String STACK_SERVLET_DELEGATE_CLASS = "org.jboss.wsf.spi.deployment.stackServletDelegateClass";
public static final String JAXRS_SERVLET_MODE = "org.jboss.wsf.spi.deployment.jaxrsServletMode";

private volatile ServletDelegate delegate = null;

Expand All @@ -71,8 +73,14 @@ public void init(ServletConfig servletConfig) throws ServletException
*/
protected ServletDelegate getDelegate(ServletConfig servletConfig)
{
ClassLoaderProvider clProvider = ClassLoaderProvider.getDefaultProvider();
ClassLoader cl = clProvider.getWebServiceSubsystemClassLoader();
final ClassLoader cl;
if (Boolean.parseBoolean(servletConfig.getInitParameter(JAXRS_SERVLET_MODE))) {
JAXRSClassLoaderProvider clProvider = JAXRSClassLoaderProvider.getDefaultProvider();
cl = clProvider.getJAXRSSubsystemClassLoader();
} else {
ClassLoaderProvider clProvider = ClassLoaderProvider.getDefaultProvider();
cl = clProvider.getWebServiceSubsystemClassLoader();
}
ServiceLoader<ServletDelegateFactory> sl = ServiceLoader.load(ServletDelegateFactory.class, cl);
ServletDelegateFactory factory = sl.iterator().next();
return factory.newServletDelegate(servletConfig.getInitParameter(STACK_SERVLET_DELEGATE_CLASS));
Expand Down
160 changes: 160 additions & 0 deletions src/main/java/org/jboss/wsf/spi/metadata/JAXRSDeploymentMetadata.java
@@ -0,0 +1,160 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2006, 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.wsf.spi.metadata;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
* JAXRS deployment metadata
*
* @author alessio.soldano@jboss.com
* @since 18-Jan-2016
*
*/
public final class JAXRSDeploymentMetadata
{
private boolean scanAll;
private boolean scanResources;
private boolean scanProviders;
private boolean dispatcherCreated;
private final Set<String> scannedResourceClasses = new LinkedHashSet<String>();
private final Set<String> scannedProviderClasses = new LinkedHashSet<String>();
private List<Class<?>> scannedApplicationClasses = new ArrayList<>();
private boolean bootClasses;
private boolean unwrappedExceptionsParameterSet;
private final Set<String> scannedJndiComponentResources = new LinkedHashSet<String>();

/**
* Merges a list of additional JAX-RS deployment data with this lot of deployment data.
*
* @param deploymentData
*/
public void merge(final List<JAXRSDeploymentMetadata> deploymentData)
{
for (JAXRSDeploymentMetadata data : deploymentData)
{
scannedApplicationClasses.addAll(data.getScannedApplicationClasses());
if (scanResources)
{
scannedResourceClasses.addAll(data.getScannedResourceClasses());
scannedJndiComponentResources.addAll(data.getScannedJndiComponentResources());
}
if (scanProviders)
{
scannedProviderClasses.addAll(data.getScannedProviderClasses());
}
}
}

public Set<String> getScannedJndiComponentResources()
{
return scannedJndiComponentResources;
}

public boolean isDispatcherCreated()
{
return dispatcherCreated;
}

public void setDispatcherCreated(boolean dispatcherCreated)
{
this.dispatcherCreated = dispatcherCreated;
}

public List<Class<?>> getScannedApplicationClasses()
{
return scannedApplicationClasses;
}

public boolean hasBootClasses()
{
return bootClasses;
}

public void setBootClasses(boolean bootClasses)
{
this.bootClasses = bootClasses;
}

public boolean shouldScan()
{
return scanAll || scanResources || scanProviders;
}

public boolean isScanAll()
{
return scanAll;
}

public void setScanAll(boolean scanAll)
{
if (scanAll)
{
scanResources = true;
scanProviders = true;
}
this.scanAll = scanAll;
}

public boolean isScanResources()
{
return scanResources;
}

public void setScanResources(boolean scanResources)
{
this.scanResources = scanResources;
}

public boolean isScanProviders()
{
return scanProviders;
}

public void setScanProviders(boolean scanProviders)
{
this.scanProviders = scanProviders;
}

public Set<String> getScannedResourceClasses()
{
return scannedResourceClasses;
}

public Set<String> getScannedProviderClasses()
{
return scannedProviderClasses;
}

public boolean isUnwrappedExceptionsParameterSet()
{
return unwrappedExceptionsParameterSet;
}

public void setUnwrappedExceptionsParameterSet(boolean unwrappedExceptionsParameterSet)
{
this.unwrappedExceptionsParameterSet = unwrappedExceptionsParameterSet;
}
}

0 comments on commit ec4dcf6

Please sign in to comment.