Author: richard.opalka(a)jboss.com
Date: 2009-08-10 06:40:17 -0400 (Mon, 10 Aug 2009)
New Revision: 10510
Added:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandlerJSE.java
Removed:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJSE.java
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/InvocationHandlerJAXRPC.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXWS.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-2720] fixing issue + other 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-10
08:48:08 UTC (rev 10509)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandler.java 2009-08-10
10:40:17 UTC (rev 10510)
@@ -26,17 +26,18 @@
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;
/**
+ * Base class for all Web Service invocation handlers inside AS.
+ *
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
* @author <a href="mailto:tdiesler@redhat.com">Thomas Diesler</a>
*/
-public abstract class AbstractInvocationHandler extends InvocationHandler
+abstract class AbstractInvocationHandler extends InvocationHandler
{
- public Invocation createInvocation()
+ public final Invocation createInvocation()
{
return new Invocation();
}
@@ -45,13 +46,13 @@
{
}
- protected Method getImplMethod(Class implClass, Method seiMethod) throws
ClassNotFoundException, NoSuchMethodException
+ protected Method getImplMethod(Class<?> implClass, Method seiMethod) throws
ClassNotFoundException, NoSuchMethodException
{
String methodName = seiMethod.getName();
- Class[] paramTypes = seiMethod.getParameterTypes();
+ Class<?>[] paramTypes = seiMethod.getParameterTypes();
for (int i = 0; i < paramTypes.length; i++)
{
- Class paramType = paramTypes[i];
+ Class<?> paramType = paramTypes[i];
if (JavaUtils.isPrimitive(paramType) == false)
{
String paramTypeName = paramType.getName();
@@ -60,29 +61,7 @@
}
}
- Method implMethod = implClass.getMethod(methodName, paramTypes);
- return implMethod;
+ return implClass.getMethod(methodName, paramTypes);
}
- 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;
- }
-
}
Added:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandlerJSE.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandlerJSE.java
(rev 0)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandlerJSE.java 2009-08-10
10:40:17 UTC (rev 10510)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.webservices.integration.invocation;
+
+import java.lang.reflect.Method;
+
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.invocation.Invocation;
+import org.jboss.wsf.spi.invocation.InvocationContext;
+
+/**
+ * Handles invocations on JSE endpoints.
+ *
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
+ * @author <a href="mailto:tdiesler@redhat.com">Thomas Diesler</a>
+ */
+abstract class AbstractInvocationHandlerJSE extends AbstractInvocationHandler
+{
+
+ AbstractInvocationHandlerJSE()
+ {
+ super();
+ }
+
+ 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);
+ this.onEndpointInstantiated(ep, epInv);
+ }
+ catch (Exception ex)
+ {
+ throw new IllegalStateException("Cannot get target bean instance",
ex);
+ }
+ }
+
+ return targetBean;
+ }
+
+ public void invoke(Endpoint ep, Invocation epInv) throws Exception
+ {
+ Object targetBean = null;
+ try
+ {
+ targetBean = this.getTargetBean(ep, epInv);
+
+ Class<?> implClass = targetBean.getClass();
+ Method seiMethod = epInv.getJavaMethod();
+ Method implMethod = getImplMethod(implClass, seiMethod);
+
+ Object[] args = epInv.getArgs();
+ this.onBeforeInvocation(epInv);
+ Object retObj = implMethod.invoke(targetBean, args);
+ epInv.setReturnValue(retObj);
+ }
+ catch (Exception e)
+ {
+ handleInvocationException(e);
+ }
+ finally
+ {
+ this.onAfterInvocation(epInv);
+ }
+ }
+
+ // TODO: document these template methods
+
+ protected void onEndpointInstantiated(Endpoint endpoint, final Invocation invocation)
throws Exception
+ {
+ // does nothing
+ }
+
+ protected void onBeforeInvocation(final Invocation invocation) throws Exception
+ {
+ // does nothing
+ }
+
+ protected void onAfterInvocation(final Invocation invocation) throws Exception
+ {
+ // does nothing
+ }
+
+}
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-10
08:48:08 UTC (rev 10509)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXRPC.java 2009-08-10
10:40:17 UTC (rev 10510)
@@ -24,51 +24,37 @@
import javax.xml.rpc.server.ServiceLifecycle;
import javax.xml.rpc.server.ServletEndpointContext;
+import org.jboss.wsf.common.injection.PreDestroyHolder;
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.invocation.Invocation;
import org.jboss.wsf.spi.invocation.InvocationContext;
/**
- * Handles invocations on JSE endpoints.
+ * Handles invocations on JAXRPC endpoints.
*
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
* @author <a href="mailto:tdiesler@redhat.com">Thomas Diesler</a>
*/
-public class InvocationHandlerJAXRPC extends InvocationHandlerJSE
+final class InvocationHandlerJAXRPC extends AbstractInvocationHandlerJSE
{
- public void invoke(Endpoint ep, Invocation epInv) throws Exception
+
+ InvocationHandlerJAXRPC()
{
- try
+ super();
+ }
+
+ protected void onEndpointInstantiated(final Endpoint endpoint, final Invocation
invocation) throws Exception
+ {
+ final InvocationContext invocationContext = invocation.getInvocationContext();
+ final Object targetBean = invocationContext.getTargetBean();
+ final boolean isJaxrpcLifecycleBean = targetBean instanceof ServiceLifecycle;
+
+ if (isJaxrpcLifecycleBean)
{
- // TODO: is it bug or feature? We're doing resource injection on JAXRPC
endpoints.
- Object targetBean = getTargetBean(ep, epInv);
-
- InvocationContext invContext = epInv.getInvocationContext();
- if (targetBean instanceof ServiceLifecycle)
- {
- 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
- {
- super.invoke(ep, epInv);
- }
- finally
- {
- if (targetBean instanceof ServiceLifecycle)
- {
- // TODO: This is bug! we're calling endpoint destroy method after each
JAXRPC endpoint invocation.
- ((ServiceLifecycle)targetBean).destroy();
- }
- }
+ ServletEndpointContext sepContext =
invocationContext.getAttachment(ServletEndpointContext.class);
+ ((ServiceLifecycle)targetBean).init(sepContext);
+ endpoint.addAttachment(PreDestroyHolder.class, new
PreDestroyHolder(targetBean));
}
- catch (Exception e)
- {
- handleInvocationException(e);
- }
}
+
}
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXWS.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXWS.java 2009-08-10
08:48:08 UTC (rev 10509)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXWS.java 2009-08-10
10:40:17 UTC (rev 10510)
@@ -21,12 +21,72 @@
*/
package org.jboss.webservices.integration.invocation;
+import javax.xml.ws.WebServiceContext;
+
+import org.jboss.wsf.common.injection.InjectionHelper;
+import org.jboss.wsf.common.injection.PreDestroyHolder;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
+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.ResourceInjector;
+import org.jboss.wsf.spi.invocation.ResourceInjectorFactory;
+import org.jboss.wsf.spi.metadata.injection.InjectionsMetaData;
+
/**
- * Handles invocations on JSE endpoints.
+ * Handles invocations on JAXWS endpoints.
*
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
* @author <a href="mailto:tdiesler@redhat.com">Thomas Diesler</a>
*/
-public class InvocationHandlerJAXWS extends InvocationHandlerJSE
+final class InvocationHandlerJAXWS extends AbstractInvocationHandlerJSE
{
+
+ private final ResourceInjector wsContextInjector;
+
+ InvocationHandlerJAXWS()
+ {
+ super();
+
+ final SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
+ final ResourceInjectorFactory resourceInjectorFactory =
spiProvider.getSPI(ResourceInjectorFactory.class);
+ wsContextInjector = resourceInjectorFactory.newResourceInjector();
+ }
+
+ protected void onEndpointInstantiated(final Endpoint endpoint, final Invocation
invocation)
+ {
+ final InvocationContext invocationContext = invocation.getInvocationContext();
+ final Object targetBean = invocationContext.getTargetBean();
+ final InjectionsMetaData injectionsMD =
endpoint.getAttachment(InjectionsMetaData.class);
+
+ InjectionHelper.injectResources(targetBean, injectionsMD);
+ InjectionHelper.callPostConstructMethod(targetBean);
+ endpoint.addAttachment(PreDestroyHolder.class, new PreDestroyHolder(targetBean));
+ }
+
+ protected void onBeforeInvocation(final Invocation invocation)
+ {
+ final InvocationContext invocationContext = invocation.getInvocationContext();
+ final WebServiceContext wsContext =
invocationContext.getAttachment(WebServiceContext.class);
+ final Object targetBean = invocationContext.getTargetBean();
+
+ if (wsContext != null)
+ {
+ this.wsContextInjector.inject(targetBean, wsContext);
+ }
+ }
+
+ protected void onAfterInvocation(final Invocation invocation)
+ {
+ final InvocationContext invocationContext = invocation.getInvocationContext();
+ final WebServiceContext wsContext =
invocationContext.getAttachment(WebServiceContext.class);
+ final Object targetBean = invocationContext.getTargetBean();
+
+ if (wsContext != null)
+ {
+ this.wsContextInjector.inject(targetBean, null);
+ }
+ }
+
}
Deleted:
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-10
08:48:08 UTC (rev 10509)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJSE.java 2009-08-10
10:40:17 UTC (rev 10510)
@@ -1,100 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.webservices.integration.invocation;
-
-import java.lang.reflect.Method;
-
-import javax.xml.ws.WebServiceContext;
-
-import org.jboss.wsf.common.injection.InjectionHelper;
-import org.jboss.wsf.common.injection.PreDestroyHolder;
-import org.jboss.wsf.spi.SPIProvider;
-import org.jboss.wsf.spi.SPIProviderResolver;
-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.ResourceInjector;
-import org.jboss.wsf.spi.invocation.ResourceInjectorFactory;
-import org.jboss.wsf.spi.metadata.injection.InjectionsMetaData;
-
-/**
- * Handles invocations on JSE endpoints.
- *
- * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
- * @author <a href="mailto:tdiesler@redhat.com">Thomas Diesler</a>
- */
-public class InvocationHandlerJSE extends AbstractInvocationHandler
-{
-
- private ResourceInjectorFactory resourceInjectorFactory;
-
- public InvocationHandlerJSE()
- {
- SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
- resourceInjectorFactory = spiProvider.getSPI(ResourceInjectorFactory.class);
- }
-
- protected Object getTargetBean(Endpoint ep, Invocation epInv) throws Exception
- {
- 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));
- }
-
- return targetBean;
- }
-
- public void invoke(Endpoint ep, Invocation epInv) throws Exception
- {
- try
- {
- 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);
- }
-
- Method method = getImplMethod(targetBean.getClass(), epInv.getJavaMethod());
- Object retObj = method.invoke(targetBean, epInv.getArgs());
- epInv.setReturnValue(retObj);
- if (wsContext != null) //JBWS-2662
- {
- injector.inject(targetBean, null);
- }
- }
- catch (Exception e)
- {
- handleInvocationException(e);
- }
- }
-
-}
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-10
08:48:08 UTC (rev 10509)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerMDB21.java 2009-08-10
10:40:17 UTC (rev 10510)
@@ -21,38 +21,21 @@
*/
package org.jboss.webservices.integration.invocation;
-import java.lang.reflect.Method;
-
-import org.jboss.wsf.spi.deployment.Endpoint;
-import org.jboss.wsf.spi.invocation.Invocation;
-
/**
* Handles invocations on MDB EJB21 endpoints.
*
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
* @author <a href="mailto:tdiesler@redhat.com">Thomas Diesler</a>
*/
-public class InvocationHandlerMDB21 extends AbstractInvocationHandler
+final class InvocationHandlerMDB21 extends AbstractInvocationHandlerJSE
{
-
- public void invoke(Endpoint ep, Invocation epInv) throws Exception
+
+ /**
+ * Constructor.
+ */
+ InvocationHandlerMDB21()
{
- try
- {
- Object targetBean = super.getTargetBean(ep, epInv);
-
- Class<?> implClass = targetBean.getClass();
- Method seiMethod = epInv.getJavaMethod();
- Method implMethod = getImplMethod(implClass, seiMethod);
-
- Object[] args = epInv.getArgs();
- Object retObj = implMethod.invoke(targetBean, args);
- epInv.setReturnValue(retObj);
- }
- catch (Exception e)
- {
- handleInvocationException(e);
- }
+ super();
}
}
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-10
08:48:08 UTC (rev 10509)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerMDB3.java 2009-08-10
10:40:17 UTC (rev 10510)
@@ -21,38 +21,21 @@
*/
package org.jboss.webservices.integration.invocation;
-import java.lang.reflect.Method;
-
-import org.jboss.wsf.spi.deployment.Endpoint;
-import org.jboss.wsf.spi.invocation.Invocation;
-
/**
* Handles invocations on MDB EJB3 endpoints.
*
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
* @author <a href="mailto:tdiesler@redhat.com">Thomas Diesler</a>
*/
-public class InvocationHandlerMDB3 extends AbstractInvocationHandler
+final class InvocationHandlerMDB3 extends AbstractInvocationHandlerJSE
{
- public void invoke(Endpoint ep, Invocation epInv) throws Exception
+ /**
+ * Constructor.
+ */
+ InvocationHandlerMDB3()
{
- try
- {
- Object targetBean = super.getTargetBean(ep, epInv);
-
- Class<?> implClass = targetBean.getClass();
- Method seiMethod = epInv.getJavaMethod();
- Method implMethod = getImplMethod(implClass, seiMethod);
-
- Object[] args = epInv.getArgs();
- Object retObj = implMethod.invoke(targetBean, args);
- epInv.setReturnValue(retObj);
- }
- catch (Exception e)
- {
- handleInvocationException(e);
- }
+ super();
}
-
+
}