Search in sources :

Example 1 with WebServicesDescriptor

use of com.sun.enterprise.deployment.WebServicesDescriptor in project Payara by payara.

the class WebServiceRuntimeNode method setElementValue.

/**
 * receives notiification of the value for a particular tag
 *
 * @param element the xml element
 * @param value it's associated value
 */
public void setElementValue(XMLElement element, String value) {
    if (WebServicesTagNames.WEB_SERVICE_DESCRIPTION_NAME.equals(element.getQName())) {
        BundleDescriptor parent = (BundleDescriptor) getParentNode().getDescriptor();
        WebServicesDescriptor webServices = parent.getWebServices();
        descriptor = webServices.getWebServiceByName(value);
    } else if (WebServicesTagNames.CLIENT_WSDL_PUBLISH_URL.equals(element.getQName())) {
        if (descriptor == null) {
            DOLUtils.getDefaultLogger().info("Warning : WebService descriptor is null for " + "final wsdl url=" + value);
            return;
        }
        try {
            URL url = new URL(value);
            descriptor.setClientPublishUrl(url);
        } catch (MalformedURLException mue) {
            DOLUtils.getDefaultLogger().log(Level.INFO, "Warning : Invalid final wsdl url=" + value, mue);
        }
    } else {
        super.setElementValue(element, value);
    }
}
Also used : BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WebServicesDescriptor(com.sun.enterprise.deployment.WebServicesDescriptor) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL)

Example 2 with WebServicesDescriptor

use of com.sun.enterprise.deployment.WebServicesDescriptor in project Payara by payara.

the class ServletWebServiceDelegate method postInit.

@Override
public void postInit(ServletConfig servletConfig) throws ServletException {
    String servletName = "unknown";
    try {
        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
        ComponentEnvManager compEnvManager = wscImpl.getComponentEnvManager();
        JndiNameEnvironment jndiNameEnv = compEnvManager.getCurrentJndiNameEnvironment();
        WebBundleDescriptor webBundle = null;
        if (jndiNameEnv != null && jndiNameEnv instanceof WebBundleDescriptor) {
            webBundle = ((WebBundleDescriptor) jndiNameEnv);
        } else {
            throw new WebServiceException("Cannot intialize the JAXRPCServlet for " + jndiNameEnv);
        }
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        servletName = servletConfig.getServletName();
        WebComponentDescriptor webComponent = webBundle.getWebComponentByCanonicalName(servletName);
        if (webComponent != null) {
            WebServicesDescriptor webServices = webBundle.getWebServices();
            Collection endpoints = webServices.getEndpointsImplementedBy(webComponent);
            // Only 1 endpoint per servlet is supported, even though
            // data structure implies otherwise.
            endpoint_ = (WebServiceEndpoint) endpoints.iterator().next();
            registerEndpoint(classLoader);
            // security
            if (secServ != null) {
                SystemHandlerDelegate securityHandlerDelegate = secServ.getSecurityHandler(endpoint_);
                if (securityHandlerDelegate != null) {
                    rpcDelegate_.setSystemHandlerDelegate(securityHandlerDelegate);
                    // need to invoke the endpoint lifecylcle
                    endpointImpl_ = JAXRPCEndpointImpl.class.cast(wsEngine_.createHandler(securityHandlerDelegate, endpoint_));
                    rpcDelegate_.setSystemHandlerDelegate(endpointImpl_);
                }
            }
        } else {
            throw new ServletException(servletName + " not found");
        }
    } catch (Throwable t) {
        String msg = MessageFormat.format(logger.getResourceBundle().getString(LogUtils.SERVLET_ENDPOINT_FAILURE), servletName);
        logger.log(Level.WARNING, msg, t);
        throw new ServletException(t);
    }
}
Also used : WebServicesDescriptor(com.sun.enterprise.deployment.WebServicesDescriptor) WebServiceException(javax.xml.ws.WebServiceException) ComponentEnvManager(com.sun.enterprise.container.common.spi.util.ComponentEnvManager) SystemHandlerDelegate(com.sun.xml.rpc.spi.runtime.SystemHandlerDelegate) WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) JndiNameEnvironment(com.sun.enterprise.deployment.JndiNameEnvironment) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) JAXRPCEndpointImpl(org.glassfish.webservices.monitoring.JAXRPCEndpointImpl)

Example 3 with WebServicesDescriptor

use of com.sun.enterprise.deployment.WebServicesDescriptor in project Payara by payara.

the class DynamicWebServletRegistrationImpl method configureWebServices.

/*
     * Configures this web module with its web services, based on its
     * "hasWebServices" and "endpointAddresses" properties
     */
void configureWebServices(WebBundleDescriptor wbd) {
    if (wbd.hasWebServices()) {
        setHasWebServices(true);
        // creates the list of endpoint addresses
        String[] endpointAddresses;
        WebServicesDescriptor webService = wbd.getWebServices();
        Vector<String> endpointList = new Vector<String>();
        for (WebServiceEndpoint wse : webService.getEndpoints()) {
            if (wbd.getContextRoot() != null) {
                endpointList.add(wbd.getContextRoot() + "/" + wse.getEndpointAddressUri());
            } else {
                endpointList.add(wse.getEndpointAddressUri());
            }
        }
        endpointAddresses = new String[endpointList.size()];
        endpointList.copyInto(endpointAddresses);
        setEndpointAddresses(endpointAddresses);
    } else {
        setHasWebServices(false);
    }
}
Also used : WebServicesDescriptor(com.sun.enterprise.deployment.WebServicesDescriptor) WebServiceEndpoint(com.sun.enterprise.deployment.WebServiceEndpoint) Vector(java.util.Vector)

Example 4 with WebServicesDescriptor

use of com.sun.enterprise.deployment.WebServicesDescriptor in project Payara by payara.

the class WebServiceProviderHandler method processAnnotation.

@Override
public HandlerProcessingResult processAnnotation(AnnotationInfo annInfo) throws AnnotationProcessorException {
    AnnotatedElementHandler annCtx = annInfo.getProcessingContext().getHandler();
    AnnotatedElement annElem = annInfo.getAnnotatedElement();
    boolean ejbInWar = ignoreWebserviceAnnotations(annElem, annCtx);
    // and add webservices to that BundleDescriptor
    if (ejbInWar) {
        return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);
    }
    // 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);
    }
    if (isJaxwsRIDeployment(annInfo)) {
        // Looks like JAX-WS RI specific deployment, do not process Web Service annotations otherwise would end up as two web service endpoints
        conLogger.log(Level.INFO, LogUtils.DEPLOYMENT_DISABLED, new Object[] { annInfo.getProcessingContext().getArchive().getName(), "WEB-INF/sun-jaxws.xml" });
        return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);
    }
    // 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 = null;
    try {
        // let's see the type of web service we are dealing with...
        if (ejbProvider != null && ejbProvider.getType("javax.ejb.Stateless") != null) {
            // this is an ejb !
            if (annCtx instanceof EjbContext) {
                EjbContext ctx = (EjbContext) annCtx;
                bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor();
                bundleDesc.setSpecVersion("3.0");
            } else if (annCtx instanceof EjbsContext) {
                String name = getEjbName(annElem);
                for (EjbContext ejbCtx : ((EjbsContext) annCtx).getEjbContexts()) {
                    EjbDescriptor descriptor = ejbCtx.getDescriptor();
                    if (name.equals(descriptor.getName())) {
                        bundleDesc = descriptor.getEjbBundleDescriptor();
                        bundleDesc.setSpecVersion("3.0");
                        break;
                    }
                }
            }
        }
        if (bundleDesc == null) {
            // this has to be a servlet
            if (annCtx instanceof WebComponentContext) {
                bundleDesc = ((WebComponentContext) annCtx).getDescriptor().getWebBundleDescriptor();
            } else if (!(annCtx instanceof WebBundleContext)) {
                return getInvalidAnnotatedElementHandlerResult(annInfo.getProcessingContext().getHandler(), annInfo);
            }
            bundleDesc = ((WebBundleContext) annCtx).getDescriptor();
            bundleDesc.setSpecVersion("2.5");
        }
    } catch (Exception e) {
        throw new AnnotationProcessorException(wsLocalStrings.getLocalString("webservice.annotation.exception", "WS00023: Exception in processing @Webservice : {0}", e.getMessage()));
    }
    // 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) {
        // If so, add this endpoint to the existing service
        if (svcName.length() != 0) {
            newWS = wsDesc.getWebServiceByName(svcName);
        } else {
            newWS = wsDesc.getWebServiceByName(((Class) annElem).getSimpleName());
        }
        if (newWS == null) {
            newWS = new WebService();
            // service name from annotation
            if (svcName.length() != 0) {
                newWS.setName(svcName);
            } else {
                newWS.setName(((Class) annElem).getSimpleName());
            }
            wsDesc.addWebService(newWS);
        }
        endpoint = new WebServiceEndpoint();
        // port-component-name is fully qualified class name
        endpoint.setEndpointName(portComponentName);
        newWS.addEndpoint(endpoint);
        wsDesc.setSpecVersion(WebServicesDescriptorNode.SPEC_VERSION);
    } else {
        newWS = endpoint.getWebService();
    }
    // present overrides everything else
    if (endpoint.getWsdlService() != null) {
        if ((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 (DOLUtils.warType().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 (webComponent == null) {
                // GLASSFISH-3297
                WebComponentDescriptor[] wcs = webBundle.getWebComponentByImplName(((Class) annElem).getCanonicalName());
                if (wcs.length > 0) {
                    webComponent = wcs[0];
                }
            }
            // if servlet is not known, we should add it now
            if (webComponent == null) {
                webComponent = new WebComponentDescriptorImpl();
                webComponent.setServlet(true);
                webComponent.setWebComponentImplementation(((Class) annElem).getCanonicalName());
                webComponent.setName(endpoint.getEndpointName());
                webComponent.addUrlPattern("/" + newWS.getName());
                webBundle.addWebComponentDescriptor(webComponent);
            }
            endpoint.setWebComponentImpl(webComponent);
        }
    } else {
        String name = getEjbName(annElem);
        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) {
        endpoint.setWsdlPort(new QName(targetNameSpace, portName, "ns1"));
    }
    if (endpoint.getWsdlService() == null) {
        endpoint.setWsdlService(new QName(targetNameSpace, svcName, "ns1"));
    }
    return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);
}
Also used : WebService(com.sun.enterprise.deployment.WebService) AnnotatedElement(java.lang.reflect.AnnotatedElement) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) WebServicesDescriptor(com.sun.enterprise.deployment.WebServicesDescriptor) WebBundleContext(com.sun.enterprise.deployment.annotation.context.WebBundleContext) WebComponentDescriptorImpl(org.glassfish.web.deployment.descriptor.WebComponentDescriptorImpl) QName(javax.xml.namespace.QName) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) EjbsContext(com.sun.enterprise.deployment.annotation.context.EjbsContext) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) WebComponentContext(com.sun.enterprise.deployment.annotation.context.WebComponentContext) WebServiceEndpoint(com.sun.enterprise.deployment.WebServiceEndpoint) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext)

Example 5 with WebServicesDescriptor

use of com.sun.enterprise.deployment.WebServicesDescriptor in project Payara by payara.

the class WebBundleDescriptorImpl method addCommonWebBundleDescriptor.

/**
 * This method combines all except welcome file set for two webBundleDescriptors.
 */
private void addCommonWebBundleDescriptor(WebBundleDescriptor wbd, boolean defaultDescriptor) {
    super.addBundleDescriptor(wbd);
    WebBundleDescriptorImpl webBundleDescriptor = (WebBundleDescriptorImpl) wbd;
    for (WebComponentDescriptor webComponentDesc : webBundleDescriptor.getWebComponentDescriptors()) {
        // don't modify the original one
        WebComponentDescriptorImpl webComponentDescriptor = new WebComponentDescriptorImpl(webComponentDesc);
        // set web bundle to null so that the urlPattern2ServletName
        // of the others will not be changed,
        // see WebComponentDescriptor.getUrlPatternsSet()
        webComponentDescriptor.setWebBundleDescriptor(null);
        List<String> removeUrlPatterns = null;
        for (String urlPattern : webComponentDescriptor.getUrlPatternsSet()) {
            String servletName = null;
            if (urlPattern2ServletName != null) {
                servletName = urlPattern2ServletName.get(urlPattern);
            }
            if (servletName != null && (!servletName.equals(webComponentDescriptor.getCanonicalName()))) {
                // need to remove the url pattern in current bundle servlet
                if (removeUrlPatterns == null) {
                    removeUrlPatterns = new ArrayList<String>();
                }
                removeUrlPatterns.add(urlPattern);
            }
        }
        if (removeUrlPatterns != null) {
            webComponentDescriptor.getUrlPatternsSet().removeAll(removeUrlPatterns);
        }
        addWebComponentDescriptor(webComponentDescriptor);
    }
    getContextParametersSet().addAll(webBundleDescriptor.getContextParametersSet());
    if (conflictedMimeMappingExtensions == null) {
        conflictedMimeMappingExtensions = webBundleDescriptor.getConflictedMimeMappingExtensions();
    } else {
        conflictedMimeMappingExtensions.addAll(webBundleDescriptor.getConflictedMimeMappingExtensions());
    }
    combineMimeMappings(webBundleDescriptor.getMimeMappingsSet());
    // do not call getErrorPageDescriptorsSet.addAll() as there is special overriding rule
    for (ErrorPageDescriptor errPageDesc : webBundleDescriptor.getErrorPageDescriptorsSet()) {
        addErrorPageDescriptor(errPageDesc);
    }
    getAppListeners().addAll(webBundleDescriptor.getAppListeners());
    if (webBundleDescriptor.isDenyUncoveredHttpMethods()) {
        setDenyUncoveredHttpMethods(true);
    }
    combineSecurityConstraints(getSecurityConstraintsSet(), webBundleDescriptor.getSecurityConstraintsSet());
    // ServletFilters
    combineServletFilters(webBundleDescriptor);
    combineServletFilterMappings(webBundleDescriptor);
    if (getLocaleEncodingMappingListDescriptor() == null) {
        setLocaleEncodingMappingListDescriptor(webBundleDescriptor.getLocaleEncodingMappingListDescriptor());
    }
    if (webBundleDescriptor.getJspConfigDescriptor() != null) {
        JspConfigDescriptorImpl jspConfigDesc = getJspConfigDescriptor();
        if (jspConfigDesc == null) {
            jspConfigDesc = new JspConfigDescriptorImpl();
            setJspConfigDescriptor(jspConfigDesc);
        }
        jspConfigDescriptor.add(webBundleDescriptor.getJspConfigDescriptor());
    }
    // WebServices
    WebServicesDescriptor thisWebServices = this.getWebServices();
    WebServicesDescriptor otherWebServices = webBundleDescriptor.getWebServices();
    for (WebService ws : otherWebServices.getWebServices()) {
        thisWebServices.addWebService(new WebService(ws));
    }
    if (getSessionConfig() == null) {
        setSessionConfig(webBundleDescriptor.getSessionConfig());
    }
    // combine login config with conflict resolution check
    combineLoginConfiguration(webBundleDescriptor);
    if (!defaultDescriptor && webBundleDescriptor.isExists()) {
        // ignore non-fragment (plain archive) files
        boolean otherDistributable = webBundleDescriptor.isDistributable();
        // the only way distributable is true is when
        // all of it's web fragments are true
        // The Servlet spec (section 8.2.3):
        setDistributable(distributable && otherDistributable);
    }
    combinePostConstructDescriptors(webBundleDescriptor);
    combinePreDestroyDescriptors(webBundleDescriptor);
    addJndiNameEnvironment(webBundleDescriptor);
}
Also used : WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) WebServicesDescriptor(com.sun.enterprise.deployment.WebServicesDescriptor) WebService(com.sun.enterprise.deployment.WebService)

Aggregations

WebServicesDescriptor (com.sun.enterprise.deployment.WebServicesDescriptor)6 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)3 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)2 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)2 WebService (com.sun.enterprise.deployment.WebService)2 WebServiceEndpoint (com.sun.enterprise.deployment.WebServiceEndpoint)2 ComponentEnvManager (com.sun.enterprise.container.common.spi.util.ComponentEnvManager)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)1 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)1 EjbsContext (com.sun.enterprise.deployment.annotation.context.EjbsContext)1 WebBundleContext (com.sun.enterprise.deployment.annotation.context.WebBundleContext)1 WebComponentContext (com.sun.enterprise.deployment.annotation.context.WebComponentContext)1 DeploymentDescriptorNode (com.sun.enterprise.deployment.node.DeploymentDescriptorNode)1 WebServiceEndpointRuntimeNode (com.sun.enterprise.deployment.node.runtime.WebServiceEndpointRuntimeNode)1 SystemHandlerDelegate (com.sun.xml.rpc.spi.runtime.SystemHandlerDelegate)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1