[jbossws-commits] JBossWS SVN: r18273 - in container/jboss72/branches/jbossws-jboss720/server-integration/src/main/java/org/jboss/as/webservices: invocation and 1 other directory.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Thu Jan 23 04:57:29 EST 2014


Author: jim.ma
Date: 2014-01-23 04:57:29 -0500 (Thu, 23 Jan 2014)
New Revision: 18273

Modified:
   container/jboss72/branches/jbossws-jboss720/server-integration/src/main/java/org/jboss/as/webservices/injection/WSComponent.java
   container/jboss72/branches/jbossws-jboss720/server-integration/src/main/java/org/jboss/as/webservices/invocation/AbstractInvocationHandler.java
Log:
[JBWS-3670]:Set reference in the WSComponent to avoid duplicate targetBean construction

Modified: container/jboss72/branches/jbossws-jboss720/server-integration/src/main/java/org/jboss/as/webservices/injection/WSComponent.java
===================================================================
--- container/jboss72/branches/jbossws-jboss720/server-integration/src/main/java/org/jboss/as/webservices/injection/WSComponent.java	2014-01-22 14:53:45 UTC (rev 18272)
+++ container/jboss72/branches/jbossws-jboss720/server-integration/src/main/java/org/jboss/as/webservices/injection/WSComponent.java	2014-01-23 09:57:29 UTC (rev 18273)
@@ -23,6 +23,7 @@
 
 import org.jboss.as.ee.component.BasicComponent;
 import org.jboss.as.ee.component.BasicComponentInstance;
+import org.jboss.as.naming.ManagedReference;
 
 /**
  * @author <a href="mailto:ropalka at redhat.com">Richard Opalka</a>
@@ -30,6 +31,7 @@
 public final class WSComponent extends BasicComponent {
 
     private volatile BasicComponentInstance wsComponentInstance;
+    private volatile ManagedReference reference;
 
     /**
      * We can't lock on <code>this</code> because the
@@ -43,16 +45,24 @@
     }
 
     public BasicComponentInstance getComponentInstance() {
-        if (wsComponentInstance == null) {
-            synchronized (lock) {
-                if (wsComponentInstance == null) {
-                    wsComponentInstance = (BasicComponentInstance) createInstance();
-                }
-            }
-        }
-        return wsComponentInstance;
+       if (wsComponentInstance == null) {
+          synchronized (lock) {
+              if (wsComponentInstance == null && reference == null) {
+                  wsComponentInstance = (BasicComponentInstance) createInstance();
+              }
+              if (wsComponentInstance == null && reference != null) {
+                  wsComponentInstance = (BasicComponentInstance) this.createInstance(reference.getInstance());
+              }
+          }
+      }
+      return wsComponentInstance;
     }
 
+
+    public void setReference(ManagedReference reference) {
+        this.reference = reference;
+    }
+    
     @Override
     public void stop() {
         if (wsComponentInstance == null) return;

Modified: container/jboss72/branches/jbossws-jboss720/server-integration/src/main/java/org/jboss/as/webservices/invocation/AbstractInvocationHandler.java
===================================================================
--- container/jboss72/branches/jbossws-jboss720/server-integration/src/main/java/org/jboss/as/webservices/invocation/AbstractInvocationHandler.java	2014-01-22 14:53:45 UTC (rev 18272)
+++ container/jboss72/branches/jbossws-jboss720/server-integration/src/main/java/org/jboss/as/webservices/invocation/AbstractInvocationHandler.java	2014-01-23 09:57:29 UTC (rev 18273)
@@ -36,6 +36,7 @@
 import org.jboss.as.ee.component.Component;
 import org.jboss.as.ee.component.ComponentView;
 import org.jboss.as.naming.ManagedReference;
+import org.jboss.as.webservices.injection.WSComponent;
 import org.jboss.invocation.InterceptorContext;
 import org.jboss.msc.service.ServiceName;
 import org.jboss.wsf.spi.deployment.Endpoint;
@@ -69,18 +70,20 @@
    protected ComponentView getComponentView() {
        // we need to check both, otherwise it is possible for
        // componentView to be initialized before reference
-      if (componentView == null || reference == null) {
+      if (componentView == null) {
          synchronized(this) {
             if (componentView == null) {
                componentView = getMSCService(componentViewName, ComponentView.class);
                if (componentView == null) {
                   throw MESSAGES.cannotFindComponentView(componentViewName);
                }
-                try {
-                    reference = componentView.createInstance();
-                } catch (Exception e) {
-                    throw new RuntimeException(e);
-                }
+               if (reference == null) {
+                  try {
+                      reference = componentView.createInstance();
+                  } catch (Exception e) {
+                      throw new RuntimeException(e);
+                  }
+               }
             }
          }
       }
@@ -98,8 +101,22 @@
       try {
          // prepare for invocation
          onBeforeInvocation(wsInvocation);
+         //for spring integration we don't need to go into ee's interceptors
+         if(wsInvocation.getInvocationContext().getTargetBean() != null) {
+             this.reference = new ManagedReference() {
+               public void release() {  
+               }
+               public Object getInstance()
+               {
+                  return wsInvocation.getInvocationContext().getTargetBean();
+               }
+             };
+         }
          // prepare invocation data
          final ComponentView componentView = getComponentView();
+         if (reference != null) {
+             ((WSComponent)componentView.getComponent()).setReference(reference);
+         }
          final Method method = getComponentViewMethod(wsInvocation.getJavaMethod(), componentView.getViewMethods());
          final InterceptorContext context = new InterceptorContext();
          prepareForInvocation(context, wsInvocation);
@@ -108,7 +125,7 @@
          context.setTarget(reference.getInstance());
          context.putPrivateData(Component.class, componentView.getComponent());
          context.putPrivateData(ComponentView.class, componentView);
-          // invoke method
+         // invoke method
          final Object retObj = componentView.invoke(context);
          // set return value
          wsInvocation.setReturnValue(retObj);



More information about the jbossws-commits mailing list