Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2013, 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.verification;
 
 import static org.jboss.as.webservices.WSLogger.ROOT_LOGGER;
 
 import java.util.List;
 
 
Verifies the structural correctness of JSR-181 style web services.
  • web methods must not be static or final
  • web methods must be public
  • web service implementation class must not declare a finalize method

      We don't check for the

      Author(s):
      sfcoy
      WebService:
      annotation or whether the class is abstract, final or public because these checks are performed by org.jboss.as.webservices.util.ASHelper.isJaxwsEndpoint(ClassInfo, CompositeIndex) from org.jboss.as.webservices.deployers.AbstractIntegrationProcessorJAXWS.deploy(DeploymentPhaseContext).
 
 public final class JwsWebServiceEndpointVerifier {
 
 
     private final Class<?> endpointClass;
 
     private final Class<?> endpointInterfaceClass;
 
 
     public JwsWebServiceEndpointVerifier(Class<?> endpointClassClass<?> endpointInterfaceClass,
             DeploymentReflectionIndex deploymentReflectionIndex) {
         this. = deploymentReflectionIndex;
         this. = endpointClass;
         this. = endpointInterfaceClass;
     }
 
     public void verify() {
         if ( != null) {
             for (Method endpointInterfaceDefinedWebMethod : endpointInterfaceDefinedWebMethods()) {
                 verifyWebMethod(endpointInterfaceDefinedWebMethod);
             }
         } // else implicit web methods are valid by definition
         verifyFinalizeMethod();
     }
 
     public boolean failed() {
         return !.isEmpty();
     }
 
     public void logFailures() {
         for (VerificationFailure verificationFailure : )
             verificationFailure.logFailure();
     }
 
     void verifyWebMethod(final Method endpointInterfaceDefinedWebMethod) {
         final Method endpointImplementationMethod = findEndpointImplMethodMatching(endpointInterfaceDefinedWebMethod);
         if (endpointImplementationMethod != null) {
             final int methodModifiers = endpointImplementationMethod.getModifiers();
             final WebMethod possibleWebMethodAnnotation = endpointImplementationMethod.getAnnotation(WebMethod.class);
             if (possibleWebMethodAnnotation == null || !possibleWebMethodAnnotation.exclude()) {
                 if (Modifier.isPublic(methodModifiers)) {
                     if (Modifier.isStatic(methodModifiers) || Modifier.isFinal(methodModifiers)) {
                         .add(new WebMethodIsStaticOrFinal(endpointImplementationMethod));
                     }
                 } else {
                     .add(new WebMethodIsNotPublic(endpointImplementationMethod));
                }
            }
        }
    }
    void verifyFinalizeMethod() {
        ClassReflectionIndex<?> classReflectionIndex = .getClassIndex();
        Method finalizeMethod = classReflectionIndex.getMethod(void.class"finalize");
        if (finalizeMethod != null) {
            .add(new ImplementationHasFinalize());
        }
    }
    }
    Method findEndpointImplMethodMatching(final Method endpointInterfaceDefinedWebMethod) {
        try {
            return .getMethod(endpointInterfaceDefinedWebMethod.getName(),
                    endpointInterfaceDefinedWebMethod.getParameterTypes());
        } catch (NoSuchMethodException e) {
            try {
                return .getDeclaredMethod(endpointInterfaceDefinedWebMethod.getName(),
                        endpointInterfaceDefinedWebMethod.getParameterTypes());
            } catch (NoSuchMethodException e1) {
                .add(new WebServiceMethodNotFound(endpointInterfaceDefinedWebMethod));
            }
        } catch (SecurityException e) {
            .add(new WebServiceMethodNotAccessible(endpointInterfaceDefinedWebMethode));
        }
        return null;
    }
    abstract class VerificationFailure {
        abstract void logFailure();
    }
    abstract class MethodVerificationFailure extends VerificationFailure {
        protected final Method failedMethod;
        protected MethodVerificationFailure(Method failedMethod) {
            this. = failedMethod;
        }
    }
    final class ImplementationHasFinalize extends VerificationFailure {
        @Override
        public void logFailure() {
        }
    }
    final class WebMethodIsStaticOrFinal extends MethodVerificationFailure {
        WebMethodIsStaticOrFinal(Method failedMethod) {
            super(failedMethod);
        }
        @Override
        public void logFailure() {
        }
    }
    final class WebMethodIsNotPublic extends MethodVerificationFailure {
        WebMethodIsNotPublic(Method failedMethod) {
            super(failedMethod);
        }
        @Override
        public void logFailure() {
        }
    }
    final class WebServiceMethodNotFound extends MethodVerificationFailure {
        WebServiceMethodNotFound(Method failedMethod) {
            super(failedMethod);
        }
        @Override
        public void logFailure() {
        }
    }
        private final SecurityException securityException;
        WebServiceMethodNotAccessible(Method failedMethodSecurityException e) {
            super(failedMethod);
            this. = e;
        }
        @Override
        public void logFailure() {
        }
    }
New to GrepCode? Check out our FAQ X