Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2011, Red Hat, Inc., 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.as.webservices.invocation;
 
 import static org.jboss.as.webservices.WSMessages.MESSAGES;
 import static org.jboss.as.webservices.metadata.model.AbstractEndpoint.COMPONENT_VIEW_NAME;
 import static org.jboss.as.webservices.util.ASHelper.getMSCService;
 
 
 
 import  org.jboss.invocation.InterceptorContext;
Invocation abstraction for all endpoint types

Author(s):
Richard Opalka
Jim Ma
 
 
    private ServiceName componentViewName;
    private volatile ComponentView componentView;
    protected volatile ManagedReference reference;

   
Initializes component view name.

Parameters:
endpoint web service endpoint
 
    public void init(final Endpoint endpoint) {
    }

   
Gets endpoint container lazily.

Returns:
endpoint container
 
    protected ComponentView getComponentView() {
        // we need to check both, otherwise it is possible for
        // componentView to be initialized before reference
       if ( == null) {
          synchronized(this) {
             if ( == null) {
                 = getMSCService(ComponentView.class);
                if ( == null) {
             	   throw .cannotFindComponentView();
                }
                if ( == null) {
                   try {
                        = .createInstance();
                   } catch (Exception e) {
                       throw new RuntimeException(e);
                   }
                }
             }
          }
       }
       return ;
    }

   
Invokes WS endpoint.

Parameters:
endpoint WS endpoint
wsInvocation web service invocation
Throws:
Exception if any error occurs
   public void invoke(final Endpoint endpointfinal Invocation wsInvocationthrows Exception {
      try {
         // prepare for invocation
         onBeforeInvocation(wsInvocation);
         // prepare invocation data
         final ComponentView componentView = getComponentView();
         Component component = componentView.getComponent();
         //for spring integration and @FactoryType is annotated we don't need to go into ee's interceptors
         if(wsInvocation.getInvocationContext().getTargetBean() != null
                 && (endpoint.getProperty("SpringBus") != null)
                 || wsInvocation.getInvocationContext().getProperty("forceTargetBean") != null) {
             this. = new ManagedReference() {
                 public void release() {
                 }
                 public Object getInstance() {
                     return wsInvocation.getInvocationContext().getTargetBean();
                 }
             };
             if (component instanceof WSComponent) {
                 ((WSComponentcomponent).setReference();
             }
         }
         final Method method = getComponentViewMethod(wsInvocation.getJavaMethod(), componentView.getViewMethods());
         final InterceptorContext context = new InterceptorContext();
         prepareForInvocation(contextwsInvocation);
         context.setMethod(method);
         context.setParameters(wsInvocation.getArgs());
         context.putPrivateData(Component.classcomponent);
         context.putPrivateData(ComponentView.classcomponentView);
         if(wsInvocation.getInvocationContext().getProperty("forceTargetBean") != null) {
             context.putPrivateData(ManagedReference.class);
         }
         // invoke method
         final Object retObj = componentView.invoke(context);
         // set return value
         wsInvocation.setReturnValue(retObj);
      }
      catch (Throwable t) {
         handleInvocationException(t);
      }
      finally {
         onAfterInvocation(wsInvocation);
      }
   }
   protected void prepareForInvocation(final InterceptorContext contextfinal Invocation wsInvocation) {
      // does nothing
   }

   
Translates SEI method to component view method.

Parameters:
seiMethod SEI method
viewMethods component view methods
Returns:
matching component view method
   protected Method getComponentViewMethod(final Method seiMethodfinal Collection<MethodviewMethods) {
       for (final Method viewMethod : viewMethods) {
           if (matches(seiMethodviewMethod)) {
               return viewMethod;
           }
       }
       throw new IllegalStateException();
   }
   protected void handleInvocationException(final Throwable tthrows Exception {
      if (t instanceof MBeanException) {
         throw ((MBeanExceptiont).getTargetException();
      }
      if (t instanceof Exception) {
         if (t instanceof InvocationTargetException) {
            throw (Exceptiont;
         } else {
            SOAPFaultException ex = findSoapFaultException(t);
            if (ex != null) {
               throw new InvocationTargetException(ex);
            }
            throw new InvocationTargetException(t);
         }
      }
      if (t instanceof Error) {
         throw (Errort;
      }
      throw new UndeclaredThrowableException(t);
    }
        if (ex instanceof SOAPFaultException) {
            return (SOAPFaultExceptionex;
        }
        if (ex.getCause() != null) {
            return findSoapFaultException(ex.getCause());
        }
        return null;
    }

   
Compares two methods if they are identical.

Parameters:
seiMethod reference method
viewMethod target method
Returns:
true if they match, false otherwise
   private boolean matches(final Method seiMethodfinal Method viewMethod) {
       if (!seiMethod.getName().equals(viewMethod.getName())) return false;
       final Class<?>[] sourceParams = seiMethod.getParameterTypes();
       final Class<?>[] targetParams = viewMethod.getParameterTypes();
       if (sourceParams.length != targetParams.lengthreturn false;
       for (int i = 0; i < sourceParams.lengthi++) {
           if (!sourceParams[i].equals(targetParams[i])) return false;
       }
       return true;
   }
New to GrepCode? Check out our FAQ X