Package com.sun.enterprise.deployment.annotation

Examples of com.sun.enterprise.deployment.annotation.AnnotationProcessorException


                // this is a method injection
                declaringClass = ((Method) annElem).getDeclaringClass();
            } else if (annInfo.getElementType().equals(ElementType.TYPE)) {
                declaringClass = (Class) annElem;
            } else {
                throw new AnnotationProcessorException(
                        localStrings.getLocalString(
                        "enterprise.deployment.annotation.handlers.invalidtype",
                        "annotation not allowed on this element."),  annInfo);
            }
        }
View Full Code Here


                        Class endpointIntf;
                        try {
                            endpointIntf = declaringClass.getClassLoader().loadClass(webService.endpointInterface());
                        } catch(java.lang.ClassNotFoundException cfne) {
                            throw new AnnotationProcessorException(
                                    localStrings.getLocalString("enterprise.deployment.annotation.handlers.classnotfound",
                                        "class {0} referenced from annotation symbol cannot be loaded",
                                        new Object[] { webService.endpointInterface() }), annInfo);
                        }
                        if (endpointIntf.getAnnotation(HandlerChain.class)!=null) {
                            hChain = (HandlerChain) endpointIntf.getAnnotation(HandlerChain.class);
                        }
                    }
                }
            }
        } else {
            // this is a client side handler chain
            hChain = annElem.getAnnotation(HandlerChain.class);
            clientSideHandlerChain = true;
        }
       
        // At this point the hChain should be the annotation to use.
        if(hChain == null) {
            return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);           
        }
        // At this point the hChain should be the annotation to use.
        String handlerFile = hChain.file();
       
        HandlerChainContainer[] containers=null;
        if (annCtx instanceof HandlerContext) {
            containers = ((HandlerContext) annCtx).getHandlerChainContainers(serviceSideChain, declaringClass);
        }

        if (!clientSideHandlerChain && (containers==null || containers.length==0)) {
            // could not find my web service...
            throw new AnnotationProcessorException(
                    localStrings.getLocalString(
                        "enterprise.deployment.annotation.handlers.componentnotfound",
                        "component referenced from annotation symbol cannot be found"),
                    annInfo);
        }
       
        try {
            URL handlerFileURL=null;
            try {
                handlerFileURL = new URL(handlerFile);
            } catch(java.net.MalformedURLException e) {
                // swallowing purposely
            }
               
            InputStream handlerFileStream;
            if (handlerFileURL==null) {
                ClassLoader clo = annInfo.getProcessingContext().getProcessingInput().getClassLoader();
                handlerFileStream = clo.getResourceAsStream(handlerFile);
                if (handlerFileStream==null) {
                    String y = declaringClass.getPackage().getName().replaceAll("\\.","/");
                    handlerFileStream = clo.getResourceAsStream(
                            declaringClass.getPackage().getName().replaceAll("\\.","/") + "/" + handlerFile);                   
                }
                if(handlerFileStream==null) {
                    // This could be a handler file generated by jaxws customization
                    // So check in the generated SEI's package
                    if(annElem instanceof Class) {
                        String y = ((Class)annElem).getPackage().getName().replaceAll("\\.","/");
                        handlerFileStream = clo.getResourceAsStream(
                                ((Class)annElem).getPackage().getName().replaceAll("\\.","/") + "/" + handlerFile);                                           
                    }
                }
            } else {
                handlerFileStream = handlerFileURL.openConnection().getInputStream();
            }
            if (handlerFileStream==null) {
                throw new AnnotationProcessorException(
                        localStrings.getLocalString(
                            "enterprise.deployment.annotation.handlers.handlerfilenotfound",
                            "handler file {0} not found",
                            new Object[] { handlerFile }),
                         annInfo);
            }
            Document document;
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                factory.setNamespaceAware(true);
                DocumentBuilder builder = factory.newDocumentBuilder();
                document = builder.parse(handlerFileStream);
            } catch (SAXParseException spe) {
                throw new AnnotationProcessorException(
                        localStrings.getLocalString(
                            "enterprise.deployment.annotation.handlers.parserexception",
                            "{0} XML Parsing error : line  {1} ; Error = {2}",
                            new Object[] { handlerFile, spe.getLineNumber(), spe.getMessage()}));
            } finally {
                if (handlerFileStream!=null) {
                    handlerFileStream.close();
                }
            }
            for (HandlerChainContainer container : containers) {
                boolean fromDD=true;
                if (!container.hasHandlerChain()) {
                    fromDD = false;
                    processHandlerFile(document, container);
                }
               
                // we now need to create the right context to push on the stack
                // and manually invoke the handlers annotation processing since
                // we know they are Jax-ws handlers.
                List<WebServiceHandlerChain> chains = container.getHandlerChain();
                ArrayList<Class> handlerClasses = new ArrayList<Class>();
                ClassLoader clo = annInfo.getProcessingContext().getProcessingInput().getClassLoader();
                for (WebServiceHandlerChain chain : chains) {
                    for (WebServiceHandler handler : chain.getHandlers()) {
                        String className = handler.getHandlerClass();
                        try {
                            handlerClasses.add(clo.loadClass(className));
                        } catch(ClassNotFoundException e) {
                            if (fromDD) {
                                logger.log(Level.WARNING, localStrings.getLocalString(
                                    "enterprise.deployment.annotation.handlers.ddhandlernotfound",
                                    "handler class {0} specified in deployment descriptors",
                                    new Object[] {className}));                                                              
                            } else {
                                logger.log(Level.WARNING, localStrings.getLocalString(
                                    "enterprise.deployment.annotation.handlers.handlerfilehandlernotfound",
                                    "handler class {0} specified in handler file {1} cannot be loaded",
                                    new Object[] {className, handlerFile}));                                  
                            }
                        }
                    }
                }
                // we have the list of handler classes, we can now
                // push the context and call back annotation processing.                               
                Descriptor jndiContainer=null;
                if (serviceSideChain) {
                    WebServiceEndpoint endpoint = (WebServiceEndpoint) container;
                    if (ModuleType.WAR.equals(endpoint.getBundleDescriptor().getModuleType())) {
                        jndiContainer = endpoint.getBundleDescriptor();                
                    } else {
                        jndiContainer = endpoint.getEjbComponentImpl();
                    }
                } else {
                    ServiceReferenceDescriptor ref = (ServiceReferenceDescriptor) container;
                    if(ModuleType.EJB.equals(ref.getBundleDescriptor().getModuleType())) {
                        EjbBundleDescriptor ejbBundle = (EjbBundleDescriptor) ref.getBundleDescriptor();
                        Iterator<EjbDescriptor> ejbsIter = ejbBundle.getEjbs().iterator();
                        while(ejbsIter.hasNext()) {
                            EjbDescriptor ejb = ejbsIter.next();
                            try {
                                if(ejb.getServiceReferenceByName(ref.getName()) != null) {
                                    // found the ejb; break out of the loop
                                    jndiContainer = ejb;
                                    break;
                                }
                            } catch (IllegalArgumentException illex) {
                                // this ejb does not have a service-ref by this name;
                                // swallow this exception and  go to next
                            }
                        }
                    } else {
                        jndiContainer = ref.getBundleDescriptor();
                    }
                }
                ResourceContainerContextImpl newContext = new ResourceContainerContextImpl(jndiContainer);
                ProcessingContext ctx = annInfo.getProcessingContext();
               
                ctx.pushHandler(newContext);
                // process the classes
                annInfo.getProcessingContext().getProcessor().process(
                        annInfo.getProcessingContext(),
                        handlerClasses.toArray(new Class[0]));

                ctx.popHandler();
            }
        } catch(Throwable t) {
            throw new AnnotationProcessorException(t.getMessage(), annInfo);
        }
        return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);       
    }
View Full Code Here

        AnnotatedElement annElem = annInfo.getAnnotatedElement();
        AnnotatedElement origAnnElem = annElem;
       
        // sanity check
        if (!(annElem instanceof Class)) {
            AnnotationProcessorException ape = new AnnotationProcessorException(
                    localStrings.getLocalString("enterprise.deployment.annotation.handlers.wrongannotationlocation",
                        "symbol annotation can only be specified on TYPE"),annInfo);
            annInfo.getProcessingContext().getErrorHandler().error(ape);
            return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED);                       
        }
       
       
        // Ignore @WebService annotation on an interface; process only those in an actual service impl class
        if (((Class)annElem).isInterface()) {        
            return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);           
        }       

        // let's get the main annotation of interest.
        javax.jws.WebService ann = (javax.jws.WebService) annInfo.getAnnotation();
       
        BundleDescriptor bundleDesc;
       
        // Ensure that an EJB endpoint is packaged in EJBJAR and a servlet endpoint is packaged in a WAR
        if(annCtx instanceof EjbContext &&
                (annElem.getAnnotation(javax.ejb.Stateless.class) == null)) {
            AnnotationProcessorException ape = new AnnotationProcessorException(
                    localStrings.getLocalString("enterprise.deployment.annotation.handlers.webeppkgwrong",
                        "Class {0} is annotated with @WebService and without @Stateless but is packaged in a JAR." +
                        " If it is supposed to be a servlet endpoint, it should be packaged in a WAR; Deployment will continue assuming  this " +
                        "class to be just a POJO used by other classes in the JAR being deployed",
                        new Object[] {((Class)annElem).getName()}),annInfo);
            ape.setFatal(false);
            throw ape;
        }
        if(annCtx instanceof EjbBundleContext &&
                (annElem.getAnnotation(javax.ejb.Stateless.class) == null)) {
            AnnotationProcessorException ape = new AnnotationProcessorException(
                    localStrings.getLocalString("enterprise.deployment.annotation.handlers.webeppkgwrong",
                        "Class {0} is annotated with @WebService and without @Stateless but is packaged in a JAR." +
                        " If it is supposed to be a servlet endpoint, it should be packaged in a WAR; Deployment will continue assuming this " +
                        "class to be just a POJO used by other classes in the JAR being deployed",
                        new Object[] {((Class)annElem).getName()}),annInfo);
            ape.setFatal(false);
            throw ape;
        }
        if(annCtx instanceof WebBundleContext &&
                (annElem.getAnnotation(javax.ejb.Stateless.class) != null)) {
            AnnotationProcessorException ape = new AnnotationProcessorException(
                    localStrings.getLocalString("enterprise.deployment.annotation.handlers.ejbeppkgwrong",
                        "Class {0} is annotated with @WebService and @Stateless but is packaged in a WAR." +
                        " If it is supposed to be an EJB endpoint, it should be packaged in a JAR; Deployment will continue assuming this " +
                        " class to be just a POJO used by other classes in the WAR being deployed",
                        new Object[] {((Class)annElem).getName()}),annInfo);
            ape.setFatal(false);
            throw ape;
        }
       
        // let's see the type of web service we are dealing with...
        if (annElem.getAnnotation(javax.ejb.Stateless.class)!=null) {
            // this is an ejb !
            EjbContext ctx = (EjbContext) annCtx;
            bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor();
            bundleDesc.setSpecVersion("3.0");
        } else {
            // this has to be a servlet since there is no @Servlet annotation yet
            if(annCtx instanceof WebComponentContext) {
                bundleDesc = ((WebComponentContext)annCtx).getDescriptor().getWebBundleDescriptor();
            } else {
                bundleDesc = ((WebBundleContext)annCtx).getDescriptor();
            }
            bundleDesc.setSpecVersion("2.5");           
        }       
       
        //WebService.name in the impl class identifies port-component-name
        // If this is specified in impl class, then that takes precedence
        String portComponentName = ann.name();

        // As per JSR181, the serviceName is either specified in the deployment descriptor
        // or in @WebSErvice annotation in impl class; if neither service name implclass+Service
        String svcNameFromImplClass = ann.serviceName();
        String implClassName = ((Class) annElem).getSimpleName();
        String implClassFullName = ((Class)annElem).getName();

        // In case user gives targetNameSpace in the Impl class, that has to be used as
        // the namespace for service, port; typically user will do this in cases where
        // port_types reside in a different namespace than that of server/port.
        // Store the targetNameSpace, if any, in the impl class for later use
        String targetNameSpace = ann.targetNamespace();
       
        // As per JSR181, the portName is either specified in deployment desc or in @WebService
        // in impl class; if neither, it will @WebService.name+Port; if @WebService.name is not there,
        // then port name is implClass+Port
        String portNameFromImplClass = ann.portName();
        if( (portNameFromImplClass == null) ||
            (portNameFromImplClass.length() == 0) ) {
            if( (portComponentName != null) && (portComponentName.length() != 0) ) {
                portNameFromImplClass = portComponentName + "Port";
            } else {
                portNameFromImplClass = implClassName+"Port";
            }
        }

        // Store binding type specified in Impl class
        String userSpecifiedBinding = null;
        javax.xml.ws.BindingType bindingAnn = (javax.xml.ws.BindingType)
                ((Class)annElem).getAnnotation(javax.xml.ws.BindingType.class);
        if(bindingAnn != null) {
            userSpecifiedBinding = bindingAnn.value();
        }

        // Store wsdlLocation in the impl class (if any)
        String wsdlLocation = null;
        if (ann.wsdlLocation()!=null && ann.wsdlLocation().length()!=0) {
            wsdlLocation = ann.wsdlLocation();
        }

        // At this point, we need to check if the @WebService points to an SEI
        // with the endpointInterface attribute, if that is the case, the
        // remaining attributes should be extracted from the SEI instead of SIB.
        boolean sibAnnotationOverriden=false;
        if (ann.endpointInterface()!=null && ann.endpointInterface().length()>0) {           
            Class endpointIntf;
            try {
                endpointIntf = ((Class) annElem).getClassLoader().loadClass(ann.endpointInterface());
            } catch(java.lang.ClassNotFoundException cfne) {
                throw new AnnotationProcessorException(
                        localStrings.getLocalString("enterprise.deployment.annotation.handlers.classnotfound",
                            "class {0} referenced from annotation symbol cannot be loaded"), annInfo);
            }
            annElem = endpointIntf;
 
            ann = annElem.getAnnotation(javax.jws.WebService.class);
            if (ann==null) {
                throw new AnnotationProcessorException("SEI " + ((javax.jws.WebService) annInfo.getAnnotation()).endpointInterface()
                    + " referenced from the @WebService annotation on " + ((Class) annElem).getName()
                    + " does not contain a @WebService annotation");                              
            }
            sibAnnotationOverriden = true;
           
            // SEI cannot have @BindingType
            if(annElem.getAnnotation(javax.xml.ws.BindingType.class) != null) {
                throw new AnnotationProcessorException("SEI " + ((javax.jws.WebService) annInfo.getAnnotation()).endpointInterface()
                    + " cannot have @BindingType");                                              
            }
        }

        WebServicesDescriptor wsDesc = bundleDesc.getWebServices();
        //WebService.name not found; as per 109, default port-component-name
        //is the simple class name as long as the simple class name will be a
        // unique port-component-name for this module
        if(portComponentName == null || portComponentName.length() == 0) {
            portComponentName = implClassName;
        }
        // Check if this port-component-name is unique for this module
        WebServiceEndpoint wep = wsDesc.getEndpointByName(portComponentName);
        if(wep!=null) {
            //there is another port-component by this name in this module;
            //now we have to look at the SEI/impl of that port-component; if that SEI/impl
            //is the same as the current SEI/impl then it means we have to override values;
            //If the SEI/impl classes do not match, then no overriding should happen; we should
            //use fully qualified class name as port-component-name for the current endpoint
            if((wep.getServiceEndpointInterface() != null) &&
               (wep.getServiceEndpointInterface().length() != 0) &&
               (!((Class)annElem).getName().equals(wep.getServiceEndpointInterface()))) {
                portComponentName = implClassFullName;
            }
        }
       
        // Check if the same endpoint is already defined in webservices.xml
        // This has to be done again after applying the 109 rules as above
        // for port-component-name
        WebServiceEndpoint endpoint = wsDesc.getEndpointByName(portComponentName);
        WebService newWS;
        if(endpoint == null) {
            // Check if a service with the same name is already present
            // If so, add this endpoint to the existing service
            if (svcNameFromImplClass!=null && svcNameFromImplClass.length()!=0) {
                newWS = wsDesc.getWebServiceByName(svcNameFromImplClass);
            } else {
                newWS = wsDesc.getWebServiceByName(implClassName+"Service");
            }
            if(newWS==null) {
                newWS = new WebService();
                // service name from annotation
                if (svcNameFromImplClass!=null && svcNameFromImplClass.length()!=0) {
                    newWS.setName(svcNameFromImplClass);
                } else {
                    newWS.setName(implClassName+"Service");           
                }
                wsDesc.addWebService(newWS);
            }
            endpoint = new WebServiceEndpoint();
            if (portComponentName!=null && portComponentName.length()!=0) {
                endpoint.setEndpointName(portComponentName);
            } else {
                endpoint.setEndpointName(((Class) annElem).getName());
            }
            newWS.addEndpoint(endpoint);
            wsDesc.setSpecVersion(com.sun.enterprise.deployment.node.WebServicesDescriptorNode.SPEC_VERSION);           
        } else {
            newWS = endpoint.getWebService();
        }

        // If wsdl-service is specified in the descriptor, then the targetnamespace
        // in wsdl-service should match the @WebService.targetNameSpace, if any.
        // make that assertion here - and the targetnamespace in wsdl-service, if
        // present overrides everything else
        if(endpoint.getWsdlService() != null) {
            if( (targetNameSpace != null) && (targetNameSpace.length() != 0 ) &&
                (!endpoint.getWsdlService().getNamespaceURI().equals(targetNameSpace)) ) {
                AnnotationProcessorException ape = new AnnotationProcessorException(
                        "Target Namespace in wsdl-service element does not match @WebService.targetNamespace",
                        annInfo);
                annInfo.getProcessingContext().getErrorHandler().error(ape);
                return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED);                       
            }
            targetNameSpace = endpoint.getWsdlService().getNamespaceURI();
        }

        // Service and port should reside in the same namespace - assert that
        if( (endpoint.getWsdlService() != null) &&
            (endpoint.getWsdlPort() != null) ) {
            if(!endpoint.getWsdlService().getNamespaceURI().equals(
                                    endpoint.getWsdlPort().getNamespaceURI())) {
                AnnotationProcessorException ape = new AnnotationProcessorException(
                        "Target Namespace for wsdl-service and wsdl-port should be the same",
                        annInfo);
                annInfo.getProcessingContext().getErrorHandler().error(ape);
                return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED);                       
            }
        }
       
        //Use annotated values only if the deployment descriptor equivalen has not been specified

        // If wsdlLocation was not given in Impl class, see if it is present in SEI
        // Set this in DOL if there is no Depl Desc entry
        // Precedence given for wsdlLocation in impl class
        if(newWS.getWsdlFileUri() == null) {
            if(wsdlLocation != null) {
                newWS.setWsdlFileUri(wsdlLocation);
            } else {
                if (ann.wsdlLocation()!=null && ann.wsdlLocation().length()!=0) {
                    newWS.setWsdlFileUri(ann.wsdlLocation());
                }
            }
        }
       
        // Set binding id id @BindingType is specified by the user in the impl class
        if((!endpoint.hasUserSpecifiedProtocolBinding()) &&
                    (userSpecifiedBinding != null) &&
                        (userSpecifiedBinding.length() != 0)){
            endpoint.setProtocolBinding(userSpecifiedBinding);
        }       

        if(endpoint.getServiceEndpointInterface() == null) {
            // take SEI from annotation
            if (ann.endpointInterface()!=null && ann.endpointInterface().length()!=0) {
                endpoint.setServiceEndpointInterface(ann.endpointInterface());
            } else {
                endpoint.setServiceEndpointInterface(((Class)annElem).getName());
            }
        }

        // at this point the SIB has to be used no matter what @WebService was used.
        annElem = annInfo.getAnnotatedElement();

        if (ModuleType.WAR.equals(bundleDesc.getModuleType())) {
            if(endpoint.getServletImplClass() == null) {
                // Set servlet impl class here
                endpoint.setServletImplClass(((Class)annElem).getName());
            }

            // Servlet link name
            WebBundleDescriptor webBundle = (WebBundleDescriptor) bundleDesc;
            if(endpoint.getWebComponentLink() == null) {
                //<servlet-link> = <port-component-name>
                endpoint.setWebComponentLink(endpoint.getEndpointName());
            }
            if(endpoint.getWebComponentImpl() == null) {
                WebComponentDescriptor webComponent = (WebComponentDescriptor) webBundle.
                    getWebComponentByCanonicalName(endpoint.getWebComponentLink());

                // if servlet is not known, we should add it now
                if (webComponent == null) {
                    webComponent = new WebComponentDescriptor();
                    webComponent.setServlet(true);               
                    webComponent.setWebComponentImplementation(((Class) annElem).getCanonicalName());
                    webComponent.setName(endpoint.getEndpointName());
                    webComponent.addUrlPattern("/"+newWS.getName());
                    webBundle.addWebComponentDescriptor(webComponent);
                }
                endpoint.setWebComponentImpl(webComponent);
            }
        } else {

                javax.ejb.Stateless stateless = annElem.getAnnotation(javax.ejb.Stateless.class);
                String name;
                if (stateless.name()==null || stateless.name().length()>0) {
                    name = stateless.name();
                } else {
                    name = ((Class) annElem).getSimpleName();
                }

            EjbDescriptor ejb = ((EjbBundleDescriptor) bundleDesc).getEjbByName(name);
            endpoint.setEjbComponentImpl(ejb);
            ejb.setWebServiceEndpointInterfaceName(endpoint.getServiceEndpointInterface());
            if (endpoint.getEjbLink()== null)
                endpoint.setEjbLink(ejb.getName());

       }

        if(endpoint.getWsdlPort() == null) {
            // Use targetNameSpace given in wsdl-service/Impl class for port and service
            // If none, derive the namespace from package name and this will be used for
            // service and port - targetNamespace, if any, in SEI will be used for pprtType
            // during wsgen phase
            if(targetNameSpace == null || targetNameSpace.length()==0) {
                // No targerNameSpace anywhere; calculate targetNameSpace and set wsdl port
                // per jax-ws 2.0 spec, the target name is the package name in
                // the reverse order prepended with http://
                if (((Class) annElem).getPackage()!=null) {

                    StringTokenizer tokens = new StringTokenizer(
                            ((Class) annElem).getPackage().getName(), ".", false);

                    if (tokens.hasMoreElements()) {
                        while (tokens.hasMoreElements()) {
                            if(targetNameSpace == null || targetNameSpace.length()==0) {
                                targetNameSpace=tokens.nextElement().toString();
                            } else {
                                targetNameSpace=tokens.nextElement().toString()+"."+targetNameSpace;
                            }
                        }
                    } else {
                        targetNameSpace = ((Class) annElem).getPackage().getName();
                    }
                } else {
                    throw new AnnotationProcessorException("JAX-WS 2.0 paragraph 3.2. " +
                            "The javax.jws.WebService annotation "
                            + "targetNamespace MUST be used for classes or interfaces in no package");
                }
                targetNameSpace = "http://" + (targetNameSpace==null?"":targetNameSpace+"/");
            }
View Full Code Here

        AnnotatedElement annElem = annInfo.getAnnotatedElement();
        AnnotatedElement origAnnElem = annElem;
       
        // sanity check
        if (!(annElem instanceof Class)) {
            AnnotationProcessorException ape = new AnnotationProcessorException(
                    localStrings.getLocalString("enterprise.deployment.annotation.handlers.wrongannotationlocation",
                        "symbol annotation can only be specified on TYPE"),annInfo);
            annInfo.getProcessingContext().getErrorHandler().error(ape);
            return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED);                       
        }
       
       
        // Ignore @WebService annotation on an interface; process only those in an actual service impl class
        if (((Class)annElem).isInterface()) {        
            return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);           
        }       

        // let's get the main annotation of interest.
        javax.jws.WebService ann = (javax.jws.WebService) annInfo.getAnnotation();
       
        BundleDescriptor bundleDesc;
       
        // Ensure that an EJB endpoint is packaged in EJBJAR and a servlet endpoint is packaged in a WAR
        if(annCtx instanceof EjbContext &&
                (annElem.getAnnotation(javax.ejb.Stateless.class) == null)) {
            AnnotationProcessorException ape = new AnnotationProcessorException(
                    localStrings.getLocalString("enterprise.deployment.annotation.handlers.webeppkgwrong",
                        "Class {0} is annotated with @WebService and without @Stateless but is packaged in a JAR." +
                        " If it is supposed to be a servlet endpoint, it should be packaged in a WAR; Deployment will continue assuming  this " +
                        "class to be just a POJO used by other classes in the JAR being deployed",
                        new Object[] {((Class)annElem).getName()}),annInfo);
            ape.setFatal(false);
            throw ape;
        }
        if(annCtx instanceof EjbBundleContext &&
                (annElem.getAnnotation(javax.ejb.Stateless.class) == null)) {
            AnnotationProcessorException ape = new AnnotationProcessorException(
                    localStrings.getLocalString("enterprise.deployment.annotation.handlers.webeppkgwrong",
                        "Class {0} is annotated with @WebService and without @Stateless but is packaged in a JAR." +
                        " If it is supposed to be a servlet endpoint, it should be packaged in a WAR; Deployment will continue assuming this " +
                        "class to be just a POJO used by other classes in the JAR being deployed",
                        new Object[] {((Class)annElem).getName()}),annInfo);
            ape.setFatal(false);
            throw ape;
        }
        if(annCtx instanceof WebBundleContext &&
                (annElem.getAnnotation(javax.ejb.Stateless.class) != null)) {
            AnnotationProcessorException ape = new AnnotationProcessorException(
                    localStrings.getLocalString("enterprise.deployment.annotation.handlers.ejbeppkgwrong",
                        "Class {0} is annotated with @WebService and @Stateless but is packaged in a WAR." +
                        " If it is supposed to be an EJB endpoint, it should be packaged in a JAR; Deployment will continue assuming this " +
                        " class to be just a POJO used by other classes in the WAR being deployed",
                        new Object[] {((Class)annElem).getName()}),annInfo);
            ape.setFatal(false);
            throw ape;
        }
       
        // let's see the type of web service we are dealing with...
        if (annElem.getAnnotation(javax.ejb.Stateless.class)!=null) {
            // this is an ejb !
            EjbContext ctx = (EjbContext) annCtx;
            bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor();
            bundleDesc.setSpecVersion("3.0");
        } else {
            // this has to be a servlet since there is no @Servlet annotation yet
            if(annCtx instanceof WebComponentContext) {
                bundleDesc = ((WebComponentContext)annCtx).getDescriptor().getWebBundleDescriptor();
            } else {
                bundleDesc = ((WebBundleContext)annCtx).getDescriptor();
            }
            bundleDesc.setSpecVersion("2.5");           
        }       
       
        //WebService.name in the impl class identifies port-component-name
        // If this is specified in impl class, then that takes precedence
        String portComponentName = ann.name();

        // As per JSR181, the serviceName is either specified in the deployment descriptor
        // or in @WebSErvice annotation in impl class; if neither service name implclass+Service
        String svcNameFromImplClass = ann.serviceName();
        String implClassName = ((Class) annElem).getSimpleName();
        String implClassFullName = ((Class)annElem).getName();

        // In case user gives targetNameSpace in the Impl class, that has to be used as
        // the namespace for service, port; typically user will do this in cases where
        // port_types reside in a different namespace than that of server/port.
        // Store the targetNameSpace, if any, in the impl class for later use
        String targetNameSpace = ann.targetNamespace();
       
        // As per JSR181, the portName is either specified in deployment desc or in @WebService
        // in impl class; if neither, it will @WebService.name+Port; if @WebService.name is not there,
        // then port name is implClass+Port
        String portNameFromImplClass = ann.portName();
        if( (portNameFromImplClass == null) ||
            (portNameFromImplClass.length() == 0) ) {
            if( (portComponentName != null) && (portComponentName.length() != 0) ) {
                portNameFromImplClass = portComponentName + "Port";
            } else {
                portNameFromImplClass = implClassName+"Port";
            }
        }

        // Store binding type specified in Impl class
        String userSpecifiedBinding = null;
        javax.xml.ws.BindingType bindingAnn = (javax.xml.ws.BindingType)
                ((Class)annElem).getAnnotation(javax.xml.ws.BindingType.class);
        if(bindingAnn != null) {
            userSpecifiedBinding = bindingAnn.value();
        }

        // Store wsdlLocation in the impl class (if any)
        String wsdlLocation = null;
        if (ann.wsdlLocation()!=null && ann.wsdlLocation().length()!=0) {
            wsdlLocation = ann.wsdlLocation();
        }

        // At this point, we need to check if the @WebService points to an SEI
        // with the endpointInterface attribute, if that is the case, the
        // remaining attributes should be extracted from the SEI instead of SIB.
        boolean sibAnnotationOverriden=false;
        if (ann.endpointInterface()!=null && ann.endpointInterface().length()>0) {           
            Class endpointIntf;
            try {
                endpointIntf = ((Class) annElem).getClassLoader().loadClass(ann.endpointInterface());
            } catch(java.lang.ClassNotFoundException cfne) {
                throw new AnnotationProcessorException(
                        localStrings.getLocalString("enterprise.deployment.annotation.handlers.classnotfound",
                            "class {0} referenced from annotation symbol cannot be loaded"), annInfo);
            }
            annElem = endpointIntf;
 
            ann = annElem.getAnnotation(javax.jws.WebService.class);
            if (ann==null) {
                throw new AnnotationProcessorException("SEI " + ((javax.jws.WebService) annInfo.getAnnotation()).endpointInterface()
                    + " referenced from the @WebService annotation on " + ((Class) annElem).getName()
                    + " does not contain a @WebService annotation");                              
            }
            sibAnnotationOverriden = true;
           
            // SEI cannot have @BindingType
            if(annElem.getAnnotation(javax.xml.ws.BindingType.class) != null) {
                throw new AnnotationProcessorException("SEI " + ((javax.jws.WebService) annInfo.getAnnotation()).endpointInterface()
                    + " cannot have @BindingType");                                              
            }
        }

        WebServicesDescriptor wsDesc = bundleDesc.getWebServices();
        //WebService.name not found; as per 109, default port-component-name
        //is the simple class name as long as the simple class name will be a
        // unique port-component-name for this module
        if(portComponentName == null || portComponentName.length() == 0) {
            portComponentName = implClassName;
        }
        // Check if this port-component-name is unique for this module
        WebServiceEndpoint wep = wsDesc.getEndpointByName(portComponentName);
        if(wep!=null) {
            //there is another port-component by this name in this module;
            //now we have to look at the SEI/impl of that port-component; if that SEI/impl
            //is the same as the current SEI/impl then it means we have to override values;
            //If the SEI/impl classes do not match, then no overriding should happen; we should
            //use fully qualified class name as port-component-name for the current endpoint
            if((wep.getServiceEndpointInterface() != null) &&
               (wep.getServiceEndpointInterface().length() != 0) &&
               (!((Class)annElem).getName().equals(wep.getServiceEndpointInterface()))) {
                portComponentName = implClassFullName;
            }
        }
       
        // Check if the same endpoint is already defined in webservices.xml
        // This has to be done again after applying the 109 rules as above
        // for port-component-name
        WebServiceEndpoint endpoint = wsDesc.getEndpointByName(portComponentName);
        WebService newWS;
        if(endpoint == null) {
            // Check if a service with the same name is already present
            // If so, add this endpoint to the existing service
            if (svcNameFromImplClass!=null && svcNameFromImplClass.length()!=0) {
                newWS = wsDesc.getWebServiceByName(svcNameFromImplClass);
            } else {
                newWS = wsDesc.getWebServiceByName(implClassName+"Service");
            }
            if(newWS==null) {
                newWS = new WebService();
                // service name from annotation
                if (svcNameFromImplClass!=null && svcNameFromImplClass.length()!=0) {
                    newWS.setName(svcNameFromImplClass);
                } else {
                    newWS.setName(implClassName+"Service");           
                }
                wsDesc.addWebService(newWS);
            }
            endpoint = new WebServiceEndpoint();
            if (portComponentName!=null && portComponentName.length()!=0) {
                endpoint.setEndpointName(portComponentName);
            } else {
                endpoint.setEndpointName(((Class) annElem).getName());
            }
            newWS.addEndpoint(endpoint);
            wsDesc.setSpecVersion(com.sun.enterprise.deployment.node.WebServicesDescriptorNode.SPEC_VERSION);           
        } else {
            newWS = endpoint.getWebService();
        }

        // If wsdl-service is specified in the descriptor, then the targetnamespace
        // in wsdl-service should match the @WebService.targetNameSpace, if any.
        // make that assertion here - and the targetnamespace in wsdl-service, if
        // present overrides everything else
        if(endpoint.getWsdlService() != null) {
            if( (targetNameSpace != null) && (targetNameSpace.length() != 0 ) &&
                (!endpoint.getWsdlService().getNamespaceURI().equals(targetNameSpace)) ) {
                AnnotationProcessorException ape = new AnnotationProcessorException(
                        "Target Namespace in wsdl-service element does not match @WebService.targetNamespace",
                        annInfo);
                annInfo.getProcessingContext().getErrorHandler().error(ape);
                return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED);                       
            }
            targetNameSpace = endpoint.getWsdlService().getNamespaceURI();
        }

        // Service and port should reside in the same namespace - assert that
        if( (endpoint.getWsdlService() != null) &&
            (endpoint.getWsdlPort() != null) ) {
            if(!endpoint.getWsdlService().getNamespaceURI().equals(
                                    endpoint.getWsdlPort().getNamespaceURI())) {
                AnnotationProcessorException ape = new AnnotationProcessorException(
                        "Target Namespace for wsdl-service and wsdl-port should be the same",
                        annInfo);
                annInfo.getProcessingContext().getErrorHandler().error(ape);
                return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED);                       
            }
        }
       
        //Use annotated values only if the deployment descriptor equivalen has not been specified

        // If wsdlLocation was not given in Impl class, see if it is present in SEI
        // Set this in DOL if there is no Depl Desc entry
        // Precedence given for wsdlLocation in impl class
        if(newWS.getWsdlFileUri() == null) {
            if(wsdlLocation != null) {
                newWS.setWsdlFileUri(wsdlLocation);
            } else {
                if (ann.wsdlLocation()!=null && ann.wsdlLocation().length()!=0) {
                    newWS.setWsdlFileUri(ann.wsdlLocation());
                }
            }
        }
       
        // Set binding id id @BindingType is specified by the user in the impl class
        if((!endpoint.hasUserSpecifiedProtocolBinding()) &&
                    (userSpecifiedBinding != null) &&
                        (userSpecifiedBinding.length() != 0)){
            endpoint.setProtocolBinding(userSpecifiedBinding);
        }       

        if(endpoint.getServiceEndpointInterface() == null) {
            // take SEI from annotation
            if (ann.endpointInterface()!=null && ann.endpointInterface().length()!=0) {
                endpoint.setServiceEndpointInterface(ann.endpointInterface());
            } else {
                endpoint.setServiceEndpointInterface(((Class)annElem).getName());
            }
        }

        // at this point the SIB has to be used no matter what @WebService was used.
        annElem = annInfo.getAnnotatedElement();

        if (ModuleType.WAR.equals(bundleDesc.getModuleType())) {
            if(endpoint.getServletImplClass() == null) {
                // Set servlet impl class here
                endpoint.setServletImplClass(((Class)annElem).getName());
            }

            // Servlet link name
            WebBundleDescriptor webBundle = (WebBundleDescriptor) bundleDesc;
            if(endpoint.getWebComponentLink() == null) {
                //<servlet-link> = <port-component-name>
                endpoint.setWebComponentLink(endpoint.getEndpointName());
            }
            if(endpoint.getWebComponentImpl() == null) {
                WebComponentDescriptor webComponent = (WebComponentDescriptor) webBundle.
                    getWebComponentByCanonicalName(endpoint.getWebComponentLink());

                // if servlet is not known, we should add it now
                if (webComponent == null) {
                    webComponent = new WebComponentDescriptor();
                    webComponent.setServlet(true);               
                    webComponent.setWebComponentImplementation(((Class) annElem).getCanonicalName());
                    webComponent.setName(endpoint.getEndpointName());
                    webComponent.addUrlPattern("/"+newWS.getName());
                    webBundle.addWebComponentDescriptor(webComponent);
                }
                endpoint.setWebComponentImpl(webComponent);
            }
        } else {

                javax.ejb.Stateless stateless = annElem.getAnnotation(javax.ejb.Stateless.class);
                String name;
                if (stateless.name()==null || stateless.name().length()>0) {
                    name = stateless.name();
                } else {
                    name = ((Class) annElem).getSimpleName();
                }

            EjbDescriptor ejb = ((EjbBundleDescriptor) bundleDesc).getEjbByName(name);
            endpoint.setEjbComponentImpl(ejb);
            ejb.setWebServiceEndpointInterfaceName(endpoint.getServiceEndpointInterface());
            if (endpoint.getEjbLink()== null)
                endpoint.setEjbLink(ejb.getName());

       }

        if(endpoint.getWsdlPort() == null) {
            // Use targetNameSpace given in wsdl-service/Impl class for port and service
            // If none, derive the namespace from package name and this will be used for
            // service and port - targetNamespace, if any, in SEI will be used for pprtType
            // during wsgen phase
            if(targetNameSpace == null || targetNameSpace.length()==0) {
                // No targerNameSpace anywhere; calculate targetNameSpace and set wsdl port
                // per jax-ws 2.0 spec, the target name is the package name in
                // the reverse order prepended with http://
                if (((Class) annElem).getPackage()!=null) {

                    StringTokenizer tokens = new StringTokenizer(
                            ((Class) annElem).getPackage().getName(), ".", false);

                    if (tokens.hasMoreElements()) {
                        while (tokens.hasMoreElements()) {
                            if(targetNameSpace == null || targetNameSpace.length()==0) {
                                targetNameSpace=tokens.nextElement().toString();
                            } else {
                                targetNameSpace=tokens.nextElement().toString()+"."+targetNameSpace;
                            }
                        }
                    } else {
                        targetNameSpace = ((Class) annElem).getPackage().getName();
                    }
                } else {
                    throw new AnnotationProcessorException("JAX-WS 2.0 paragraph 3.2. " +
                            "The javax.jws.WebService annotation "
                            + "targetNamespace MUST be used for classes or interfaces in no package");
                }
                targetNameSpace = "http://" + (targetNameSpace==null?"":targetNameSpace+"/");
            }
View Full Code Here

        AnnotatedElementHandler annCtx = annInfo.getProcessingContext().getHandler();
        AnnotatedElement annElem = annInfo.getAnnotatedElement();
       
        // sanity check
        if (!(annElem instanceof Class)) {
            AnnotationProcessorException ape = new AnnotationProcessorException(
                    "@WebServiceProvider can only be specified on TYPE", annInfo);
            annInfo.getProcessingContext().getErrorHandler().error(ape);
            return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED);                       
        }            
        // WebServiceProvider MUST implement the provider interface, let's check this
        if (!javax.xml.ws.Provider.class.isAssignableFrom((Class) annElem)) {
            AnnotationProcessorException ape = new AnnotationProcessorException(
                    annElem.toString() + "does not implement the javax.xml.ws.Provider interface", annInfo);
            annInfo.getProcessingContext().getErrorHandler().error(ape);
            return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED);                                   
        }
   
        // let's get the main annotation of interest.
        javax.xml.ws.WebServiceProvider ann = (javax.xml.ws.WebServiceProvider) annInfo.getAnnotation();       
       
        BundleDescriptor bundleDesc;
       
        // let's see the type of web service we are dealing with...
        if (annElem.getAnnotation(javax.ejb.Stateless.class)!=null) {
            // this is an ejb !
            EjbContext ctx = (EjbContext) annCtx;
            bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor();
            bundleDesc.setSpecVersion("3.0");
        } else {
            // this has to be a servlet since there is no @Servlet annotation yet
            WebBundleContext ctx = (WebBundleContext)annCtx;
            bundleDesc = ctx.getDescriptor();
            bundleDesc.setSpecVersion("2.5");           
        }       

        // For WSProvider, portComponentName is the fully qualified class name
        String portComponentName = ((Class) annElem).getName();
       
        // As per JSR181, the serviceName is either specified in the deployment descriptor
        // or in @WebSErvice annotation in impl class; if neither service name implclass+Service
        String svcName  = ann.serviceName();
        if(svcName == null) {
            svcName = "";
        }

        // Store binding type specified in Impl class
        String userSpecifiedBinding = null;
        javax.xml.ws.BindingType bindingAnn = (javax.xml.ws.BindingType)
                ((Class)annElem).getAnnotation(javax.xml.ws.BindingType.class);
        if(bindingAnn != null) {
            userSpecifiedBinding = bindingAnn.value();
        }
       
        // In case user gives targetNameSpace in the Impl class, that has to be used as
        // the namespace for service, port; typically user will do this in cases where
        // port_types reside in a different namespace than that of server/port.
        // Store the targetNameSpace, if any, in the impl class for later use
        String targetNameSpace = ann.targetNamespace();
        if(targetNameSpace == null) {
            targetNameSpace = "";
        }

        String portName = ann.portName();
        if(portName == null) {
            portName = "";
        }
       
        // Check if the same endpoint is already defined in webservices.xml
        WebServicesDescriptor wsDesc = bundleDesc.getWebServices();
        WebServiceEndpoint endpoint = wsDesc.getEndpointByName(portComponentName);
        WebService newWS;
        if(endpoint == null) {
            // Check if a service with the same name is already present
            // If so, add this endpoint to the existing service
            if (svcName.length()!=0) {
                newWS = wsDesc.getWebServiceByName(svcName);
            } else {
                newWS = wsDesc.getWebServiceByName(((Class)annElem).getSimpleName()+"Service");
            }
            if(newWS==null) {
                newWS = new WebService();
                // service name from annotation
                if (svcName.length()!=0) {
                    newWS.setName(svcName);
                } else {
                    newWS.setName(((Class)annElem).getSimpleName()+"Service");           
                }
                wsDesc.addWebService(newWS);
            }
            endpoint = new WebServiceEndpoint();
            // port-component-name is fully qualified class name
            endpoint.setEndpointName(portComponentName);
            newWS.addEndpoint(endpoint);           
            wsDesc.setSpecVersion(com.sun.enterprise.deployment.node.WebServicesDescriptorNode.SPEC_VERSION);           
        } else {
            newWS = endpoint.getWebService();
        }

        // If wsdl-service is specified in the descriptor, then the targetnamespace
        // in wsdl-service should match the @WebService.targetNameSpace, if any.
        // make that assertion here - and the targetnamespace in wsdl-service, if
        // present overrides everything else
        if(endpoint.getWsdlService() != null) {
            if( (targetNameSpace != null) && (targetNameSpace.length() != 0 ) &&
                (!endpoint.getWsdlService().getNamespaceURI().equals(targetNameSpace)) ) {
                throw new AnnotationProcessorException(
                        "Target Namespace inwsdl-service element does not match @WebService.targetNamespace",
                        annInfo);
            }
            targetNameSpace = endpoint.getWsdlService().getNamespaceURI();
        }
       
        // Set binding id id @BindingType is specified by the user in the impl class
        if((!endpoint.hasUserSpecifiedProtocolBinding()) &&
                    (userSpecifiedBinding != null) &&
                        (userSpecifiedBinding.length() != 0)){
            endpoint.setProtocolBinding(userSpecifiedBinding);
        }       

        // Use annotated values only if the deployment descriptor equivalent has not been specified       
        if(newWS.getWsdlFileUri() == null) {
            // take wsdl location from annotation
            if (ann.wsdlLocation()!=null && ann.wsdlLocation().length()!=0) {
                newWS.setWsdlFileUri(ann.wsdlLocation());
            }
        }

        annElem = annInfo.getAnnotatedElement();
       
        // we checked that the endpoint implements the provider interface above
        Class clz = (Class) annElem;
        Class serviceEndpointIntf = null;
        for (Class intf : clz.getInterfaces()) {
            if (javax.xml.ws.Provider.class.isAssignableFrom(intf)) {
                serviceEndpointIntf = intf;
                break;
            }
        }
        if (serviceEndpointIntf==null) {
            endpoint.setServiceEndpointInterface("javax.xml.ws.Provider");
        } else {
            endpoint.setServiceEndpointInterface(serviceEndpointIntf.getName());
        }

        if (ModuleType.WAR.equals(bundleDesc.getModuleType())) {
            if(endpoint.getServletImplClass() == null) {
                // Set servlet impl class here
                endpoint.setServletImplClass(((Class)annElem).getName());
            }

            // Servlet link name
            WebBundleDescriptor webBundle = (WebBundleDescriptor) bundleDesc;
            if(endpoint.getWebComponentLink() == null) {
                endpoint.setWebComponentLink(portComponentName);
            }
            if(endpoint.getWebComponentImpl() == null) {
                WebComponentDescriptor webComponent = (WebComponentDescriptor) webBundle.
                    getWebComponentByCanonicalName(endpoint.getWebComponentLink());

                // if servlet is not known, we should add it now
                if (webComponent == null) {
                    webComponent = new WebComponentDescriptor();
                    webComponent.setServlet(true);               
                    webComponent.setWebComponentImplementation(((Class) annElem).getCanonicalName());
                    webComponent.setName(endpoint.getEndpointName());
                    webComponent.addUrlPattern("/"+newWS.getName());
                    webBundle.addWebComponentDescriptor(webComponent);
                }
                endpoint.setWebComponentImpl(webComponent);
            }
        } else {
            if(endpoint.getEjbLink() == null) {
                EjbDescriptor[] ejbDescs = ((EjbBundleDescriptor) bundleDesc).getEjbByClassName(((Class)annElem).getName());
                if(ejbDescs.length != 1) {
                    throw new AnnotationProcessorException(
                        "Unable to find matching descriptor for EJB endpoint",
                        annInfo);                   
                }
                endpoint.setEjbComponentImpl(ejbDescs[0]);
                ejbDescs[0].setWebServiceEndpointInterfaceName(endpoint.getServiceEndpointInterface());
View Full Code Here

        AnnotatedElementHandler annCtx = annInfo.getProcessingContext().getHandler();
        AnnotatedElement annElem = annInfo.getAnnotatedElement();
       
        // sanity check
        if (!(annElem instanceof Class)) {
            AnnotationProcessorException ape = new AnnotationProcessorException(
                    "@WebServiceProvider can only be specified on TYPE", annInfo);
            annInfo.getProcessingContext().getErrorHandler().error(ape);
            return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED);                       
        }            
        // WebServiceProvider MUST implement the provider interface, let's check this
        if (!javax.xml.ws.Provider.class.isAssignableFrom((Class) annElem)) {
            AnnotationProcessorException ape = new AnnotationProcessorException(
                    annElem.toString() + "does not implement the javax.xml.ws.Provider interface", annInfo);
            annInfo.getProcessingContext().getErrorHandler().error(ape);
            return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED);                                   
        }
   
        // let's get the main annotation of interest.
        javax.xml.ws.WebServiceProvider ann = (javax.xml.ws.WebServiceProvider) annInfo.getAnnotation();       
       
        BundleDescriptor bundleDesc;
       
        // let's see the type of web service we are dealing with...
        if (annElem.getAnnotation(javax.ejb.Stateless.class)!=null) {
            // this is an ejb !
            EjbContext ctx = (EjbContext) annCtx;
            bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor();
            bundleDesc.setSpecVersion("3.0");
        } else {
            // this has to be a servlet since there is no @Servlet annotation yet
            WebBundleContext ctx = (WebBundleContext)annCtx;
            bundleDesc = ctx.getDescriptor();
            bundleDesc.setSpecVersion("2.5");           
        }       

        // For WSProvider, portComponentName is the fully qualified class name
        String portComponentName = ((Class) annElem).getName();
       
        // As per JSR181, the serviceName is either specified in the deployment descriptor
        // or in @WebSErvice annotation in impl class; if neither service name implclass+Service
        String svcName  = ann.serviceName();
        if(svcName == null) {
            svcName = "";
        }

        // Store binding type specified in Impl class
        String userSpecifiedBinding = null;
        javax.xml.ws.BindingType bindingAnn = (javax.xml.ws.BindingType)
                ((Class)annElem).getAnnotation(javax.xml.ws.BindingType.class);
        if(bindingAnn != null) {
            userSpecifiedBinding = bindingAnn.value();
        }
       
        // In case user gives targetNameSpace in the Impl class, that has to be used as
        // the namespace for service, port; typically user will do this in cases where
        // port_types reside in a different namespace than that of server/port.
        // Store the targetNameSpace, if any, in the impl class for later use
        String targetNameSpace = ann.targetNamespace();
        if(targetNameSpace == null) {
            targetNameSpace = "";
        }

        String portName = ann.portName();
        if(portName == null) {
            portName = "";
        }
       
        // Check if the same endpoint is already defined in webservices.xml
        WebServicesDescriptor wsDesc = bundleDesc.getWebServices();
        WebServiceEndpoint endpoint = wsDesc.getEndpointByName(portComponentName);
        WebService newWS;
        if(endpoint == null) {
            // Check if a service with the same name is already present
            // If so, add this endpoint to the existing service
            if (svcName.length()!=0) {
                newWS = wsDesc.getWebServiceByName(svcName);
            } else {
                newWS = wsDesc.getWebServiceByName(((Class)annElem).getSimpleName()+"Service");
            }
            if(newWS==null) {
                newWS = new WebService();
                // service name from annotation
                if (svcName.length()!=0) {
                    newWS.setName(svcName);
                } else {
                    newWS.setName(((Class)annElem).getSimpleName()+"Service");           
                }
                wsDesc.addWebService(newWS);
            }
            endpoint = new WebServiceEndpoint();
            // port-component-name is fully qualified class name
            endpoint.setEndpointName(portComponentName);
            newWS.addEndpoint(endpoint);           
            wsDesc.setSpecVersion(com.sun.enterprise.deployment.node.WebServicesDescriptorNode.SPEC_VERSION);           
        } else {
            newWS = endpoint.getWebService();
        }

        // If wsdl-service is specified in the descriptor, then the targetnamespace
        // in wsdl-service should match the @WebService.targetNameSpace, if any.
        // make that assertion here - and the targetnamespace in wsdl-service, if
        // present overrides everything else
        if(endpoint.getWsdlService() != null) {
            if( (targetNameSpace != null) && (targetNameSpace.length() != 0 ) &&
                (!endpoint.getWsdlService().getNamespaceURI().equals(targetNameSpace)) ) {
                throw new AnnotationProcessorException(
                        "Target Namespace inwsdl-service element does not match @WebService.targetNamespace",
                        annInfo);
            }
            targetNameSpace = endpoint.getWsdlService().getNamespaceURI();
        }
       
        // Set binding id id @BindingType is specified by the user in the impl class
        if((!endpoint.hasUserSpecifiedProtocolBinding()) &&
                    (userSpecifiedBinding != null) &&
                        (userSpecifiedBinding.length() != 0)){
            endpoint.setProtocolBinding(userSpecifiedBinding);
        }       

        // Use annotated values only if the deployment descriptor equivalent has not been specified       
        if(newWS.getWsdlFileUri() == null) {
            // take wsdl location from annotation
            if (ann.wsdlLocation()!=null && ann.wsdlLocation().length()!=0) {
                newWS.setWsdlFileUri(ann.wsdlLocation());
            }
        }

        annElem = annInfo.getAnnotatedElement();
       
        // we checked that the endpoint implements the provider interface above
        Class clz = (Class) annElem;
        Class serviceEndpointIntf = null;
        for (Class intf : clz.getInterfaces()) {
            if (javax.xml.ws.Provider.class.isAssignableFrom(intf)) {
                serviceEndpointIntf = intf;
                break;
            }
        }
        if (serviceEndpointIntf==null) {
            endpoint.setServiceEndpointInterface("javax.xml.ws.Provider");
        } else {
            endpoint.setServiceEndpointInterface(serviceEndpointIntf.getName());
        }

        if (ModuleType.WAR.equals(bundleDesc.getModuleType())) {
            if(endpoint.getServletImplClass() == null) {
                // Set servlet impl class here
                endpoint.setServletImplClass(((Class)annElem).getName());
            }

            // Servlet link name
            WebBundleDescriptor webBundle = (WebBundleDescriptor) bundleDesc;
            if(endpoint.getWebComponentLink() == null) {
                endpoint.setWebComponentLink(portComponentName);
            }
            if(endpoint.getWebComponentImpl() == null) {
                WebComponentDescriptor webComponent = (WebComponentDescriptor) webBundle.
                    getWebComponentByCanonicalName(endpoint.getWebComponentLink());

                // if servlet is not known, we should add it now
                if (webComponent == null) {
                    webComponent = new WebComponentDescriptor();
                    webComponent.setServlet(true);               
                    webComponent.setWebComponentImplementation(((Class) annElem).getCanonicalName());
                    webComponent.setName(endpoint.getEndpointName());
                    webComponent.addUrlPattern("/"+newWS.getName());
                    webBundle.addWebComponentDescriptor(webComponent);
                }
                endpoint.setWebComponentImpl(webComponent);
            }
        } else {
            if(endpoint.getEjbLink() == null) {
                EjbDescriptor[] ejbDescs = ((EjbBundleDescriptor) bundleDesc).getEjbByClassName(((Class)annElem).getName());
                if(ejbDescs.length != 1) {
                    throw new AnnotationProcessorException(
                        "Unable to find matching descriptor for EJB endpoint",
                        annInfo);                   
                }
                endpoint.setEjbComponentImpl(ejbDescs[0]);
                ejbDescs[0].setWebServiceEndpointInterfaceName(endpoint.getServiceEndpointInterface());
View Full Code Here

            Field annotatedField = (Field) annElem;
           
            // check this is a valid field
            if (annCtx instanceof AppClientContext){
                if (!Modifier.isStatic(annotatedField.getModifiers())){
                    throw new AnnotationProcessorException(
                            localStrings.getLocalString(
                            "enterprise.deployment.annotation.handlers.injectionfieldnotstatic",
                            "Injection fields for application clients must be declared STATIC"),
                            annInfo);
                }
            }
           
            annotatedType = annotatedField.getType();
            declaringClass = annotatedField.getDeclaringClass();
            // applying with default
            if (serviceRefName.equals("")) {
                serviceRefName = declaringClass.getName()
                + "/" + annotatedField.getName();
            }
        } else if (annInfo.getElementType().equals(ElementType.METHOD)) {
           
            // this is a method injection
            Method annotatedMethod = (Method) annElem;
            validateInjectionMethod(annotatedMethod, annInfo);
           
            if (annCtx instanceof AppClientContext){
                if (!Modifier.isStatic(annotatedMethod.getModifiers())){
                    throw new AnnotationProcessorException(
                            localStrings.getLocalString(
                            "enterprise.deployment.annotation.handlers.injectionmethodnotstatic",
                            "Injection methods for application clients must be declared STATIC"),
                            annInfo);
                }
            }
           
            annotatedType = annotatedMethod.getParameterTypes()[0];
            declaringClass = annotatedMethod.getDeclaringClass();
            if (serviceRefName == null || serviceRefName.equals("")) {
                // Derive javabean property name.
                String propertyName =
                    getInjectionMethodPropertyName(annotatedMethod, annInfo);
                // prefixing with fully qualified type name
                serviceRefName = declaringClass.getName()
                    + "/" + propertyName;
            }
        } else if (annInfo.getElementType().equals(ElementType.TYPE))
        {
            // name must be specified.
            if (serviceRefName==null || serviceRefName.length()==0) {
                throw new AnnotationProcessorException(
                        localStrings.getLocalString(
                        "enterprise.deployment.annotation.handlers.nonametypelevel",
                        "TYPE-Level annotation  must specify name member."),  annInfo);               
            }
            // this is a dependency declaration, we need the service interface
            // to be specified
            annotatedType = annotation.type();
            if (annotatedType==null || annotatedType==Object.class  ) {
                throw new AnnotationProcessorException(
                        localStrings.getLocalString(
                        "enterprise.deployment.annotation.handlers.typenotfound",
                        "TYPE-level annotation symbol must specify type member.")
                         annInfo);
            }
            declaringClass = (Class) annElem;
        } else {   
                throw new AnnotationProcessorException(
                        localStrings.getLocalString(
                        "enterprise.deployment.annotation.handlers.invalidtype",
                        "annotation not allowed on this element."),  annInfo);
           
        }
       
        ServiceReferenceContainer[] containers = null;
        ServiceReferenceDescriptor aRef =null;
        if (annCtx instanceof ServiceReferenceContainerContext) {
            containers = ((ServiceReferenceContainerContext) annCtx).getServiceRefContainers();
        }

        if (containers==null || containers.length==0) {
            annInfo.getProcessingContext().getErrorHandler().warning(
                    new AnnotationProcessorException(
                    localStrings.getLocalString(
                    "enterprise.deployment.annotation.handlers.invalidannotationforthisclass",
                    "Illegal annotation symbol for this class will be ignored"),
                    annInfo));
            return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);
        }
       
        // now process the annotation for all the containers.
        for (ServiceReferenceContainer container : containers) {
            try {
                aRef =container.getServiceReferenceByName(serviceRefName);
            } catch(Throwable t) {}; // ignore
              
            if (aRef==null) {
                // time to create it...
                aRef = new ServiceReferenceDescriptor();
                aRef.setName(serviceRefName);
                container.addServiceReferenceDescriptor(aRef);
            }

            // Store mapped name that is specified
            if(aRef.getMappedName() == null) {
                if(annotation.mappedName() != null && annotation.mappedName().length() != 0) {
                    aRef.setMappedName(annotation.mappedName());
                }
            }

            aRef.setInjectResourceType("javax.jws.WebServiceRef");
           
            if (!annInfo.getElementType().equals(ElementType.TYPE)) {
                InjectionTarget target = new InjectionTarget();
                if (annInfo.getElementType().equals(ElementType.FIELD)) {
                    // this is a field injection
                    Field annotatedField = (Field) annElem;
                    target.setFieldName(annotatedField.getName());
                    target.setClassName(annotatedField.getDeclaringClass().getName());
                } else {
                    if (annInfo.getElementType().equals(ElementType.METHOD)) {
                        // this is a method injection
                        Method annotatedMethod = (Method) annElem;
                        target.setMethodName(annotatedMethod.getName());
                        target.setClassName(annotatedMethod.getDeclaringClass().getName());
                    }
                }
                aRef.addInjectionTarget(target);
            }
           
            if (!Object.class.equals(annotation.value())) {
                // a value was provided, which should be the Service
                // interface, the requested injection is therefore on the
                // port.
                if (aRef.getServiceInterface()==null) {
                    aRef.setServiceInterface(annotation.value().getName());
                }
               
                if (aRef.getPortInfoBySEI(annotatedType.getName())==null) {
                    ServiceRefPortInfo portInfo = new ServiceRefPortInfo();
                    portInfo.setServiceEndpointInterface(annotatedType.getName());
                    aRef.addPortInfo(portInfo);
                }
                // set the port type requested for injection
                if (aRef.getInjectionTargetType()==null) {
                    aRef.setInjectionTargetType(annotatedType.getName());
                }
            }
           
            // watch the override order
            if(aRef.getName()==null || aRef.getName().length()==0) {
                aRef.setName(annotation.name());
            }
            if (aRef.getWsdlFileUri()==null) {
                if (annotation.wsdlLocation()==null || annotation.wsdlLocation().length()!=0) {
                    aRef.setWsdlFileUri(annotation.wsdlLocation());
                }
            }
           
            // Read the WebServiceClient annotation for the service name space uri and wsdl (if required)
            WebServiceClient wsclientAnn;
            if (Object.class.equals(annotation.value())) {
                wsclientAnn =  (WebServiceClient) annotatedType.getAnnotation(WebServiceClient.class);
            } else {
                wsclientAnn = (WebServiceClient) annotation.value().getAnnotation(WebServiceClient.class);
            }
            if (wsclientAnn==null) {
                throw new AnnotationProcessorException(
                        localStrings.getLocalString(
                        "enterprise.deployment.annotation.handlers.classnotannotated",
                        "Class must be annotated with a {1} annotation\n symbol : {1}\n location: {0}",
                        new Object[] { annotatedType.toString(), WebServiceClient.class.toString() }));
            }
View Full Code Here

    protected void log(Level level, AnnotationInfo ainfo,
            String localizedMessage) throws AnnotationProcessorException {
        if (Level.SEVERE.equals(level)) {
            ainfo.getProcessingContext().getErrorHandler().error(
                new AnnotationProcessorException(localizedMessage, ainfo));
        } else if (Level.WARNING.equals(level)) {
            ainfo.getProcessingContext().getErrorHandler().warning(
                new AnnotationProcessorException(localizedMessage, ainfo));
        } else if (Level.FINE.equals(level)) {
            ainfo.getProcessingContext().getErrorHandler().fine(
                new AnnotationProcessorException(localizedMessage, ainfo));
        } else if (ainfo != null) {
            ainfo.getProcessingContext().getProcessor().log(
                level, ainfo, localizedMessage);
        } else {
            logger.log(level, localizedMessage);
View Full Code Here

            // Derive javabean property name.
            propertyName =
                methodName.substring(3, 4).toLowerCase() +
                methodName.substring(4);
        else {
            throw new AnnotationProcessorException(
                localStrings.getLocalString(
                "enterprise.deployment.annotation.handlers.invalidinjectionmethodname",
                "Injection method name must start with \"set\""),
                ainfo);
        }
View Full Code Here

     * @exception AnnotationProcessorException
     */
    protected void validateInjectionMethod(Method method, AnnotationInfo ainfo)
            throws AnnotationProcessorException {
        if (method.getParameterTypes().length!=1){
            throw new AnnotationProcessorException(
                localStrings.getLocalString(
                "enterprise.deployment.annotation.handlers.invalidinjectionmethod",
                "Injection on a method requires a JavaBeans setter method type with one parameter "),
                ainfo);
               
        }
        if (!void.class.equals(method.getReturnType())) {
            throw new AnnotationProcessorException(
                localStrings.getLocalString(
                "enterprise.deployment.annotation.handlers.injectionmethodmustreturnvoid",
                "Injection on a method requires a void return type"),
                ainfo);
        }
View Full Code Here

TOP

Related Classes of com.sun.enterprise.deployment.annotation.AnnotationProcessorException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.