Skip to content

Commit

Permalink
Support for @stateless JAXRS resources (EJB integration)
Browse files Browse the repository at this point in the history
  • Loading branch information
asoldano committed Feb 17, 2016
1 parent f6695bf commit f6165e3
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
@@ -0,0 +1,104 @@
/*
* 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.stack.cxf;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import org.apache.cxf.jaxrs.JAXRSInvoker;
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
import org.apache.cxf.jaxrs.utils.InjectionUtils;
import org.apache.cxf.service.invoker.Invoker;
import org.jboss.wsf.stack.cxf.deployment.JNDIComponentResourceProvider;

/**
* A JBossWS extension of the Apache CXF JAXRSInvoker invoker.
*
* @author alessio.soldano@jboss.com
*
*/
public class JBossWSJAXRSInvoker extends JAXRSInvoker implements Invoker
{
@Override
protected Method getMethodToInvoke(ClassResourceInfo cri, OperationResourceInfo ori, Object resourceObject)
{
Method resourceMethod = cri.getMethodDispatcher().getMethod(ori);

Method methodToInvoke = null;
if (Proxy.class.isInstance(resourceObject))
{
methodToInvoke = cri.getMethodDispatcher().getProxyMethod(resourceMethod);
if (methodToInvoke == null)
{
methodToInvoke = InjectionUtils.checkProxy(resourceMethod, resourceObject);
cri.getMethodDispatcher().addProxyMethod(resourceMethod, methodToInvoke);
}
}
else if (cri.getResourceProvider() instanceof JNDIComponentResourceProvider)
{
methodToInvoke = processJNDIRef(resourceMethod, resourceObject);
}
else
{
methodToInvoke = resourceMethod;
}
return methodToInvoke;
}

private Method processJNDIRef(Method methodToInvoke, Object resourceObject)
{
String methodToInvokeName = methodToInvoke.getName();
Class<?>[] methodToInvokeTypes = methodToInvoke.getParameterTypes();

for (Class<?> c : resourceObject.getClass().getInterfaces())
{
try
{
return c.getMethod(methodToInvokeName, methodToInvokeTypes);
}
catch (NoSuchMethodException ex)
{
//ignore
}
if (methodToInvokeTypes.length > 0)
{
for (Method m : c.getMethods())
{
if (m.getName().equals(methodToInvokeName) && m.getParameterTypes().length == methodToInvokeTypes.length)
{
Class<?>[] methodTypes = m.getParameterTypes();
for (int i = 0; i < methodTypes.length; i++)
{
if (!methodTypes[i].isAssignableFrom(methodToInvokeTypes[i]))
{
break;
}
}
return m;
}
}
}
}
return methodToInvoke;
}
}
Expand Up @@ -46,6 +46,7 @@
import org.jboss.wsf.spi.WSFException;
import org.jboss.wsf.spi.deployment.Deployment;
import org.jboss.wsf.spi.metadata.JAXRSDeploymentMetadata;
import org.jboss.wsf.stack.cxf.JBossWSJAXRSInvoker;
import org.jboss.wsf.stack.cxf.Messages;
import org.jboss.wsf.stack.cxf.client.configuration.JBossWSBusFactory;
import org.jboss.wsf.stack.cxf.deployment.JNDIComponentResourceProvider;
Expand Down Expand Up @@ -122,6 +123,7 @@ private static void createFromApplication(JAXRSDeploymentMetadata md, Class<?> a
JAXRSServerFactoryBean bean = ResourceUtils.createApplication(app, md.isIgnoreApplicationPath(), false);
bean.setBus(bus);
bean.setApplicationInfo(providerApp);
bean.setInvoker(new JBossWSJAXRSInvoker());
List<Class<?>> additionalResources = new ArrayList<>();
if (app.getClasses().isEmpty() && app.getSingletons().isEmpty()) {
processResources(bean, md, bus, classLoader, additionalResources);
Expand All @@ -139,6 +141,7 @@ private static void create(JAXRSDeploymentMetadata md, Bus bus, ClassLoader clas
JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
bean.setBus(bus);
bean.setAddress("/"); //TODO!!!
bean.setInvoker(new JBossWSJAXRSInvoker());
//resources...
List<Class<?>> resources = new ArrayList<>();
processResources(bean, md, bus, classLoader, resources);
Expand Down

0 comments on commit f6165e3

Please sign in to comment.