Package com.sun.enterprise.deployment

Examples of com.sun.enterprise.deployment.WebService


        endpointInfo.setRemoteInterface(serviceEndpointInterfaceClass);
        endpointInfo.setImplementationClass(implementationClass);

        endpointInfo.setName(endpoint_.getEndpointName());

        WebService webService = endpoint_.getWebService();


        // No need to set model file name or wsdl file, since we override
        // the code that serves up the final WSDL.
        //endpointInfo.setModelFileName()
View Full Code Here


        archive.open(RelativePathResolver.resolvePath(
                        getGeneratedAppLocation(request)));

        for (Iterator it = app.getWebServiceDescriptors().iterator();
                it.hasNext();) {
            WebService webService = (WebService) it.next();
            // No work needed if webservice is configured for URL publishing
            if (!webService.hasFilePublishing()) {
                continue;
            }

            // For file publishing, URL is a file URL for a directory
            String clientPublishURL =
                    webService.getClientPublishUrl().toExternalForm();
            if (app.isVirtual()) { //standalone module
                keyPrefix = moduleID;
                moduleArchive = archive;
            else {
                ModuleDescriptor md =
                        webService.getBundleDescriptor().getModuleDescriptor();
                keyPrefix = moduleID + "#" + md.getArchiveUri();
                moduleArchive = archive.getEmbeddedArchive(md.getArchiveUri());
            }

            key = keyPrefix + sep + DeploymentStatus.WSDL_PUBLISH_URL;
            status.addProperty(key, clientPublishURL);

            // Collect the names of all entries in or below the
            // dedicated wsdl directory.
            BundleDescriptor bundle = webService.getBundleDescriptor();
            Enumeration entries = moduleArchive.entries(bundle.getWsdlDir());

            // Strictly speaking, we only need to write the files needed by
            // imports of this web service's wsdl file.  However, it's not
            // worth actual parsing the whole chain just to figure this
View Full Code Here

        String requestUriRaw = request.getRequestURI();
        String requestUri    = (requestUriRaw.charAt(0) == '/') ?
            requestUriRaw.substring(1) : requestUriRaw;
        String queryString = request.getQueryString();

        WebService webService = endpoint.getWebService();

        if( queryString == null ) {

            // Get portion of request uri representing location within a module
            String wsdlPath = endpoint.getWsdlContentPath(requestUri);

            if( wsdlPath != null) {
                ModuleDescriptor module =
                    webService.getBundleDescriptor().getModuleDescriptor();

                if( wsdlPath.equals(webService.getWsdlFileUri())){
                    // If the request is for the main wsdl document, return
                    // the final wsdl instead of the wsdl from the module.
                    wsdlUrl = webService.getWsdlFileUrl();
                } else if( isWsdlContent(wsdlPath,
                                         webService.getBundleDescriptor()) ) {
                    // For relative document imports. These documents do not
                    // require modification during deployment, so serve them
                    // up directly from the packaged module.  isWsdlContent()
                    // check ensures we don't serve up arbitrary content from
                    // the module.
                    URL finalWsdlUrl = webService.getWsdlFileUrl();
                    String finalWsdlPath = finalWsdlUrl.getPath();
                    // remove the final wsdl uri from the above path
                    String wsdlDirPath = finalWsdlPath.substring(0, finalWsdlPath.length()-webService.getWsdlFileUri().length());
                    File wsdlDir = new File(wsdlDirPath);
                    File wsdlFile = new File(wsdlDir, wsdlPath.replace('/', File.separatorChar));
                    try {
                        wsdlUrl = wsdlFile.toURL();
                    } catch(MalformedURLException mue) {
                        logger.log(Level.INFO, "Failure serving WSDL for " +
                                   webService.getName(), mue);
                    }
                       
                }
            }

        } else if( queryString.equalsIgnoreCase("WSDL") ) {
            wsdlUrl = webService.getWsdlFileUrl();
        }

        boolean success = false;
        if( wsdlUrl != null ) {
           
            InputStream is = null;
            try {
                response.setContentType("text/xml");
                response.setStatus(HttpServletResponse.SC_OK);
                // if the requested file is the main wsdl document, we are going
                // to reprocess it through the XML transformer to change the final
                // endpoint URL correct for this particular web server instance.
                // This is necessary in the case of SE/EE installations where
                // the application can be running on different machines and ports
                // than the one they were deployed on (DAS).
                if (wsdlUrl.toURI().equals(webService.getWsdlFileUrl().toURI())) {
                    // get the application module ID
                    try {
                        String moduleID = endpoint.getBundleDescriptor().getApplication().getRegistrationName();
                        WebServerInfo wsi = getWebServerInfo(moduleID, request);
                        URL url = webService.getWsdlFileUrl();
                        File originalWsdlFile = new File(url.getPath()+"__orig");
                        if(!originalWsdlFile.exists()) {
                            originalWsdlFile = new File(url.getPath());
                        }
                        generateFinalWsdl(originalWsdlFile.toURL(), webService, wsi, response.getOutputStream());
                    } catch(Exception e) {
                        // if this fail, we revert to service the untouched
                        // repository item.
                        URLConnection urlCon = wsdlUrl.openConnection();
                        urlCon.setUseCaches(false);
                        is = urlCon.getInputStream();                   
                        ArchivistUtils.copy(is, response.getOutputStream());                       
                    }
                } else {
                    // Copy bytes into output. Disable caches to avoid jar URL
                    // caching problem.
                    URLConnection urlCon = wsdlUrl.openConnection();
                    urlCon.setUseCaches(false);
                    is = urlCon.getInputStream();                   
                    ArchivistUtils.copy(is, response.getOutputStream());
                }
                success = true;
                if( logger.isLoggable(Level.FINE) ) {
                    logger.fine("Serving up final wsdl " + wsdlUrl + " for " +
                                request.getRequestURL() +
                                (queryString != null ? ("?"+queryString) : ""));
                }
            } catch(Exception e) {
                logger.log(Level.INFO, "Failure serving WSDL for web service " +
                           webService.getName(), e);
            } finally {
                if(is != null) {
                    try {
                        is.close();
                    } catch(IOException ex) {}
                }
            }
        }

        if( !success ) {
            String message =
                "Invalid wsdl request " +  request.getRequestURL() +
                (queryString != null ? ("?"+queryString) : "") +
                " for web service "+ webService.getName();
               
            logger.info(message);

            writeInvalidMethodType(response, message);
        }
View Full Code Here

        BundleDescriptor bundle = webService.getBundleDescriptor();
        WebServicesDescriptor wsd = bundle.getWebServices();
        Collection webServices = wsd.getWebServices();
        if (webServices.size()>1) {
            for (Iterator wsIter = webServices.iterator();wsIter.hasNext();) {
                WebService aWS = (WebService) wsIter.next();
                if (webService.getName().equals(aWS.getName())) {
                    continue;
                }
                // this is another web service defined in the same bundle.
                // let's check if it points to the same WSDL file
                if ((webService.getWsdlFileUri() != null) &&
                     (aWS.getWsdlFileUri() != null) &&
                     (webService.getWsdlFileUri().equals(aWS.getWsdlFileUri()))) {
                    endpointsCopy.addAll(aWS.getEndpoints());
                } else if ((webService.getWsdlFileUrl() != null) &&
                     (aWS.getWsdlFileUrl() != null) &&
                     ((webService.getWsdlFileUrl().toString())
                        .equals(aWS.getWsdlFileUrl().toString()))) {
                    endpointsCopy.addAll(aWS.getEndpoints());
                }
            }
        }

       
View Full Code Here

     *
     * @param descriptor the new descriptor
     */
    public void addDescriptor(Object descriptor) {   
        WebServiceEndpoint endpoint = (WebServiceEndpoint) descriptor;
        WebService webService = (WebService) getDescriptor();
        webService.addEndpoint(endpoint);
    }
View Full Code Here

     * @param descriptor the new descriptor
     */
    public void addDescriptor(Object descriptor) {   
        WebServicesDescriptor webServicesDesc =
            bundleDescriptor.getWebServices();
        WebService webService = (WebService) descriptor;
        webServicesDesc.addWebService(webService);
       
        for(Iterator iter = webService.getEndpoints().iterator();
            iter.hasNext();) {
            WebServiceEndpoint next = (WebServiceEndpoint) iter.next();
            if( !next.resolveComponentLink() ) {
                DOLUtils.getDefaultLogger().info("Warning: Web service endpoint " + next.getEndpointName() + " component link " + next.getLinkName() + " is not valid");               
            }
View Full Code Here

       
        // 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+"/");
            }
            // WebService.portName = wsdl-port
            endpoint.setWsdlPort(new QName(targetNameSpace, portNameFromImplClass, "ns1"));
        }

        if(endpoint.getWsdlService() == null) {
            // Set wsdl-service properly; namespace is the same as that of wsdl port;
            // service name derived from deployment desc / annotation / default
            String serviceNameSpace = endpoint.getWsdlPort().getNamespaceURI();
            String serviceName = null;
            if ( (svcNameFromImplClass != null) &&
                  (svcNameFromImplClass.length()!= 0)) {
                // Use the serviceName annotation if available
                serviceName= svcNameFromImplClass;
            } else {
              serviceName = newWS.getName();
            }
            endpoint.setWsdlService(new QName(serviceNameSpace, serviceName, "ns1"));
        }

        // Now force a HandlerChain annotation processing
View Full Code Here

                                           BundleDescriptor bundle) {
        WebServicesDescriptor webServices = bundle.getWebServices();
        if( webServices != null ) {
            for(Iterator iter = webServices.getWebServices().iterator();
                iter.hasNext();) {
                WebService next = (WebService) iter.next();
                if( next.hasClientPublishUrl() ) {
                    writeDescriptor
                        (parent, WebServicesTagNames.WEB_SERVICE, next);
                }
            }
        }
View Full Code Here

        }
       
        // 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 {
View Full Code Here

  Set webServices = app.getWebServiceDescriptors();
  if (webServices.size()>0) {
      hasWebServices = true;
      Vector endpointList = new Vector();
      for (Iterator itr = webServices.iterator();itr.hasNext();) {
    WebService webService = (WebService) itr.next();
    for (Iterator endpoints = webService.getWebServicesDescriptor().getEndpoints().iterator();
      endpoints.hasNext();) {
        WebServiceEndpoint wse = (WebServiceEndpoint) endpoints.next();
        endpointList.add(wse.getEndpointAddressUri());
    }
      }
View Full Code Here

TOP

Related Classes of com.sun.enterprise.deployment.WebService

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.