Author: richard.opalka(a)jboss.com
Date: 2009-08-07 08:02:53 -0400 (Fri, 07 Aug 2009)
New Revision: 10503
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandler.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB21.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB3.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXRPC.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJSE.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerMDB21.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerMDB3.java
Log:
[JBWS-2332] refactoring
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandler.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandler.java 2009-08-07
10:10:51 UTC (rev 10502)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandler.java 2009-08-07
12:02:53 UTC (rev 10503)
@@ -24,6 +24,9 @@
import java.lang.reflect.Method;
import org.jboss.wsf.common.JavaUtils;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.invocation.Invocation;
+import org.jboss.wsf.spi.invocation.InvocationContext;
import org.jboss.wsf.spi.invocation.InvocationHandler;
/**
@@ -32,6 +35,16 @@
*/
public abstract class AbstractInvocationHandler extends InvocationHandler
{
+
+ public Invocation createInvocation()
+ {
+ return new Invocation();
+ }
+
+ public void init(Endpoint ep)
+ {
+ }
+
protected Method getImplMethod(Class implClass, Method seiMethod) throws
ClassNotFoundException, NoSuchMethodException
{
String methodName = seiMethod.getName();
@@ -50,4 +63,26 @@
Method implMethod = implClass.getMethod(methodName, paramTypes);
return implMethod;
}
+
+ protected Object getTargetBean(Endpoint ep, Invocation epInv) throws Exception
+ {
+ InvocationContext invCtx = epInv.getInvocationContext();
+ Object targetBean = invCtx.getTargetBean();
+ if (targetBean == null)
+ {
+ try
+ {
+ Class<?> epImpl = ep.getTargetBeanClass();
+ targetBean = epImpl.newInstance();
+ invCtx.setTargetBean(targetBean);
+ }
+ catch (Exception ex)
+ {
+ throw new IllegalStateException("Cannot get target bean instance",
ex);
+ }
+ }
+
+ return targetBean;
+ }
+
}
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB21.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB21.java 2009-08-07
10:10:51 UTC (rev 10502)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB21.java 2009-08-07
12:02:53 UTC (rev 10503)
@@ -49,7 +49,6 @@
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.invocation.HandlerCallback;
import org.jboss.wsf.spi.invocation.Invocation;
-import org.jboss.wsf.spi.invocation.InvocationHandler;
import org.jboss.wsf.spi.invocation.SecurityAdaptor;
import org.jboss.wsf.spi.invocation.SecurityAdaptorFactory;
import org.jboss.wsf.spi.metadata.j2ee.EJBArchiveMetaData;
@@ -61,7 +60,7 @@
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
* @author <a href="mailto:tdiesler@redhat.com">Thomas Diesler</a>
*/
-public class InvocationHandlerEJB21 extends InvocationHandler
+public class InvocationHandlerEJB21 extends AbstractInvocationHandler
{
// provide logging
private static final Logger log = Logger.getLogger(InvocationHandlerEJB21.class);
@@ -74,11 +73,6 @@
{
}
- public Invocation createInvocation()
- {
- return new Invocation();
- }
-
public void init(Endpoint ep)
{
String ejbName = ep.getShortName();
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB3.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB3.java 2009-08-07
10:10:51 UTC (rev 10502)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB3.java 2009-08-07
12:02:53 UTC (rev 10503)
@@ -52,16 +52,10 @@
houston = KernelLocator.getKernel().getController();
}
- public Invocation createInvocation()
- {
- return new Invocation();
- }
-
public void init(Endpoint ep)
{
containerName = (String)ep.getProperty(InvocationHandlerEJB3.CONTAINER_NAME);
assert containerName != null : "Target container name not set";
-
}
private ServiceEndpointContainer lazyInitializeInvocationTarget()
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXRPC.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXRPC.java 2009-08-07
10:10:51 UTC (rev 10502)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXRPC.java 2009-08-07
12:02:53 UTC (rev 10503)
@@ -40,6 +40,7 @@
{
try
{
+ // TODO: is it bug or feature? We're doing resource injection on JAXRPC
endpoints.
Object targetBean = getTargetBean(ep, epInv);
InvocationContext invContext = epInv.getInvocationContext();
@@ -48,6 +49,8 @@
ServletEndpointContext sepContext =
invContext.getAttachment(ServletEndpointContext.class);
if (sepContext != null)
((ServiceLifecycle)targetBean).init(sepContext);
+ // TODO: shouldn't we call init method also in case
ServletEndpointContext
+ // TODO: isn't available to ensure lifecycle method calls?
}
try
@@ -58,6 +61,7 @@
{
if (targetBean instanceof ServiceLifecycle)
{
+ // TODO: This is bug! we're calling endpoint destroy method after each
JAXRPC endpoint invocation.
((ServiceLifecycle)targetBean).destroy();
}
}
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJSE.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJSE.java 2009-08-07
10:10:51 UTC (rev 10502)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJSE.java 2009-08-07
12:02:53 UTC (rev 10503)
@@ -25,7 +25,6 @@
import javax.xml.ws.WebServiceContext;
-import org.jboss.wsf.common.JavaUtils;
import org.jboss.wsf.common.injection.InjectionHelper;
import org.jboss.wsf.common.injection.PreDestroyHolder;
import org.jboss.wsf.spi.SPIProvider;
@@ -33,7 +32,6 @@
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.invocation.Invocation;
import org.jboss.wsf.spi.invocation.InvocationContext;
-import org.jboss.wsf.spi.invocation.InvocationHandler;
import org.jboss.wsf.spi.invocation.ResourceInjector;
import org.jboss.wsf.spi.invocation.ResourceInjectorFactory;
import org.jboss.wsf.spi.metadata.injection.InjectionsMetaData;
@@ -44,43 +42,23 @@
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
* @author <a href="mailto:tdiesler@redhat.com">Thomas Diesler</a>
*/
-public class InvocationHandlerJSE extends InvocationHandler
+public class InvocationHandlerJSE extends AbstractInvocationHandler
{
- private SPIProvider spiProvider;
+
private ResourceInjectorFactory resourceInjectorFactory;
public InvocationHandlerJSE()
{
- spiProvider = SPIProviderResolver.getInstance().getProvider();
+ SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
resourceInjectorFactory = spiProvider.getSPI(ResourceInjectorFactory.class);
}
- public Invocation createInvocation()
- {
- return new Invocation();
- }
-
- public void init(Endpoint ep)
- {
- }
-
protected Object getTargetBean(Endpoint ep, Invocation epInv) throws Exception
{
- InvocationContext invCtx = epInv.getInvocationContext();
- Object targetBean = invCtx.getTargetBean();
- if (targetBean == null)
- {
- try
- {
- Class<?> epImpl = ep.getTargetBeanClass();
- targetBean = epImpl.newInstance();
- invCtx.setTargetBean(targetBean);
- }
- catch (Exception ex)
- {
- throw new IllegalStateException("Cannot get target bean instance",
ex);
- }
+ Object targetBean = super.getTargetBean(ep, epInv);
+ if (ep.getAttachment(PreDestroyHolder.class) == null)
+ {
InjectionHelper.injectResources(targetBean,
ep.getAttachment(InjectionsMetaData.class));
InjectionHelper.callPostConstructMethod(targetBean);
ep.addAttachment(PreDestroyHolder.class, new PreDestroyHolder(targetBean));
@@ -93,13 +71,14 @@
{
try
{
- Object targetBean = getTargetBean(ep, epInv);
+ Object targetBean = this.getTargetBean(ep, epInv);
InvocationContext invContext = epInv.getInvocationContext();
WebServiceContext wsContext =
invContext.getAttachment(WebServiceContext.class);
ResourceInjector injector = null;
if (wsContext != null)
{
+ // TODO: is it bug or feature? We're doing WebServiceContext injection on
JAXRPC endpoints too?
injector = resourceInjectorFactory.newResourceInjector();
injector.inject(targetBean, wsContext);
}
@@ -118,22 +97,4 @@
}
}
- protected Method getImplMethod(Class<?> implClass, Method seiMethod) throws
ClassNotFoundException, NoSuchMethodException
- {
- String methodName = seiMethod.getName();
- Class<?>[] paramTypes = seiMethod.getParameterTypes();
- for (int i = 0; i < paramTypes.length; i++)
- {
- Class<?> paramType = paramTypes[i];
- if (JavaUtils.isPrimitive(paramType) == false)
- {
- String paramTypeName = paramType.getName();
- paramType = JavaUtils.loadJavaType(paramTypeName);
- paramTypes[i] = paramType;
- }
- }
-
- Method implMethod = implClass.getMethod(methodName, paramTypes);
- return implMethod;
- }
}
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerMDB21.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerMDB21.java 2009-08-07
10:10:51 UTC (rev 10502)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerMDB21.java 2009-08-07
12:02:53 UTC (rev 10503)
@@ -23,10 +23,8 @@
import java.lang.reflect.Method;
-import org.jboss.logging.Logger;
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.invocation.Invocation;
-import org.jboss.wsf.spi.invocation.InvocationContext;
/**
* Handles invocations on MDB EJB21 endpoints.
@@ -36,41 +34,14 @@
*/
public class InvocationHandlerMDB21 extends AbstractInvocationHandler
{
- // provide logging
- private static final Logger log = Logger.getLogger(InvocationHandlerMDB21.class);
- public Invocation createInvocation()
- {
- return new Invocation();
- }
-
- public void init(Endpoint ep)
- {
-
- }
-
public void invoke(Endpoint ep, Invocation epInv) throws Exception
{
- log.debug("Invoke: " + epInv.getJavaMethod().getName());
-
try
{
- InvocationContext invCtx = epInv.getInvocationContext();
- Object targetBean = invCtx.getTargetBean();
- if (targetBean == null)
- {
- try
- {
- Class epImpl = ep.getTargetBeanClass();
- targetBean = epImpl.newInstance();
- invCtx.setTargetBean(targetBean);
- }
- catch (Exception ex)
- {
- throw new IllegalStateException("Canot get target bean
instance", ex);
- }
- }
- Class implClass = targetBean.getClass();
+ Object targetBean = super.getTargetBean(ep, epInv);
+
+ Class<?> implClass = targetBean.getClass();
Method seiMethod = epInv.getJavaMethod();
Method implMethod = getImplMethod(implClass, seiMethod);
@@ -83,4 +54,5 @@
handleInvocationException(e);
}
}
+
}
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerMDB3.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerMDB3.java 2009-08-07
10:10:51 UTC (rev 10502)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerMDB3.java 2009-08-07
12:02:53 UTC (rev 10503)
@@ -23,10 +23,8 @@
import java.lang.reflect.Method;
-import org.jboss.logging.Logger;
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.invocation.Invocation;
-import org.jboss.wsf.spi.invocation.InvocationContext;
/**
* Handles invocations on MDB EJB3 endpoints.
@@ -36,41 +34,14 @@
*/
public class InvocationHandlerMDB3 extends AbstractInvocationHandler
{
- // provide logging
- private static final Logger log = Logger.getLogger(InvocationHandlerMDB3.class);
- public Invocation createInvocation()
- {
- return new Invocation();
- }
-
- public void init(Endpoint ep)
- {
-
- }
-
public void invoke(Endpoint ep, Invocation epInv) throws Exception
{
- log.debug("Invoke: " + epInv.getJavaMethod().getName());
-
try
{
- InvocationContext invCtx = epInv.getInvocationContext();
- Object targetBean = invCtx.getTargetBean();
- if (targetBean == null)
- {
- try
- {
- Class epImpl = ep.getTargetBeanClass();
- targetBean = epImpl.newInstance();
- invCtx.setTargetBean(targetBean);
- }
- catch (Exception ex)
- {
- throw new IllegalStateException("Canot get target bean
instance", ex);
- }
- }
- Class implClass = targetBean.getClass();
+ Object targetBean = super.getTargetBean(ep, epInv);
+
+ Class<?> implClass = targetBean.getClass();
Method seiMethod = epInv.getJavaMethod();
Method implMethod = getImplMethod(implClass, seiMethod);
@@ -83,4 +54,5 @@
handleInvocationException(e);
}
}
+
}