Search in sources :

Example 1 with ServletAdapter

use of com.sun.xml.ws.transport.http.servlet.ServletAdapter in project Payara by payara.

the class WSServletContextListener method contextDestroyed.

@Override
public void contextDestroyed(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();
    synchronized (this) {
        ServletAdapterList list = (ServletAdapterList) servletContext.getAttribute("ADAPTER_LIST");
        if (list != null) {
            for (ServletAdapter x : list) {
                x.getEndpoint().dispose();
                for (Handler handler : x.getEndpoint().getBinding().getHandlerChain()) {
                    try {
                        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
                        InjectionManager injManager = wscImpl.getInjectionManager();
                        injManager.destroyManagedObject(handler);
                    } catch (InjectionException e) {
                        logger.log(Level.WARNING, LogUtils.DESTORY_ON_HANDLER_FAILED, new Object[] { handler.getClass(), x.getEndpoint().getServiceName(), e.getMessage() });
                        continue;
                    }
                }
            }
            servletContext.removeAttribute("ADAPTER_LIST");
        }
        JAXWSAdapterRegistry.getInstance().removeAdapter(contextRoot);
    /*
                 Fix for bug 3932/4052 since the x.getEndpoint().dispose is being
                 called above we do not need to call this explicitly
                 try {
                 (new WsUtil()).doPreDestroy(endpoint, classLoader);
                 } catch (Throwable t) {
                 logger.log(Level.WARNING, "@PreDestroy lifecycle call failed for service"
                 + endpoint.getName(), t);
                 }*/
    }
    JAXWSServletModule.destroy(contextRoot);
}
Also used : InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) ServletAdapter(com.sun.xml.ws.transport.http.servlet.ServletAdapter) ServletContext(javax.servlet.ServletContext) Handler(javax.xml.ws.handler.Handler) ServletAdapterList(com.sun.xml.ws.transport.http.servlet.ServletAdapterList) InjectionManager(com.sun.enterprise.container.common.spi.util.InjectionManager)

Example 2 with ServletAdapter

use of com.sun.xml.ws.transport.http.servlet.ServletAdapter in project Payara by payara.

the class WSServletContextListener method registerEndpoint.

private void registerEndpoint(WebServiceEndpoint endpoint, ServletContext servletContext) throws Exception {
    ClassLoader classLoader = servletContext.getClassLoader();
    WsUtil wsu = new WsUtil();
    // Complete all the injections that are required
    Class serviceEndpointClass = Class.forName(endpoint.getServletImplClass(), true, classLoader);
    // Get the proper binding using BindingID
    String givenBinding = endpoint.getProtocolBinding();
    // TODO Rama
    // if(endpoint.getWsdlExposed() != null) {
    // wsdlExposed = Boolean.parseBoolean(endpoint.getWsdlExposed());
    // }
    // Get list of all wsdls and schema
    SDDocumentSource primaryWsdl = null;
    Collection docs = null;
    if (endpoint.getWebService().hasWsdlFile()) {
        URL pkgedWsdl = null;
        try {
            pkgedWsdl = servletContext.getResource('/' + endpoint.getWebService().getWsdlFileUri());
        } catch (MalformedURLException e) {
            logger.log(Level.SEVERE, LogUtils.CANNOT_LOAD_WSDL_FROM_APPLICATION, e.getMessage());
        }
        if (pkgedWsdl == null) {
            pkgedWsdl = endpoint.getWebService().getWsdlFileUrl();
        }
        if (pkgedWsdl != null) {
            primaryWsdl = SDDocumentSource.create(pkgedWsdl);
            docs = wsu.getWsdlsAndSchemas(pkgedWsdl);
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, LogUtils.CREATING_ENDPOINT_FROM_PACKAGED_WSDL, primaryWsdl.getSystemId().toString());
                logger.log(Level.FINE, LogUtils.METADATA_DOCS);
                for (Object source : docs) {
                    logger.log(Level.FINE, ((SDDocumentSource) source).getSystemId().toString());
                }
            }
        }
    }
    // Create a Container to pass ServletContext and also inserting the pipe
    JAXWSContainer container = new JAXWSContainer(servletContext, endpoint);
    // Get catalog info
    java.net.URL catalogURL = servletContext.getResource('/' + endpoint.getBundleDescriptor().getDeploymentDescriptorDir() + File.separator + "jax-ws-catalog.xml");
    // Create Binding and set service side handlers on this binding
    boolean mtomEnabled = wsu.getMtom(endpoint);
    WSBinding binding = null;
    // Only if MTOm is enabled create the Binding with the MTOMFeature
    ArrayList<WebServiceFeature> wsFeatures = new ArrayList<WebServiceFeature>();
    // Only if MTOm is enabled create the Binding with the MTOMFeature
    if (mtomEnabled) {
        int mtomThreshold = endpoint.getMtomThreshold() != null ? Integer.parseInt(endpoint.getMtomThreshold()) : 0;
        MTOMFeature mtom = new MTOMFeature(true, mtomThreshold);
        wsFeatures.add(mtom);
    }
    Addressing addressing = endpoint.getAddressing();
    if (addressing != null) {
        AddressingFeature addressingFeature = new AddressingFeature(addressing.isEnabled(), addressing.isRequired(), getResponse(addressing.getResponses()));
        wsFeatures.add(addressingFeature);
    }
    RespectBinding rb = endpoint.getRespectBinding();
    if (rb != null) {
        RespectBindingFeature rbFeature = new RespectBindingFeature(rb.isEnabled());
        wsFeatures.add(rbFeature);
    }
    if (endpoint.getValidateRequest() != null && Boolean.parseBoolean(endpoint.getValidateRequest())) {
        // enable SchemaValidationFeature
        wsFeatures.add(new SchemaValidationFeature());
    }
    if (endpoint.getStreamAttachments() != null && Boolean.parseBoolean(endpoint.getStreamAttachments())) {
        // enable StreamingAttachmentsFeature
        wsFeatures.add(new StreamingAttachmentFeature());
    }
    if (endpoint.getReliabilityConfig() != null) {
        // TODO Revisit later after Metro provides generic method to pass partial configuration to Metro runtime.
        // Only partial configuration is specified in webservices DD, but the information for creating complete RM feature should be gathered
        // from wsdl policy, annotation or metro configuration file. For ex: RmProtocolVersion would be decided by  policy assertion.
        // For now, the feature would be constructed from default values, overriding any configuration specified in wsdl or metro configuration file..
        ReliabilityConfig rxConfig = endpoint.getReliabilityConfig();
        ReliableMessagingFeatureBuilder rmbuilder = new ReliableMessagingFeatureBuilder(RmProtocolVersion.getDefault());
        if (rxConfig.getInactivityTimeout() != null) {
            rmbuilder.sequenceInactivityTimeout(Long.parseLong(rxConfig.getInactivityTimeout().trim()));
        }
        if (endpoint.getHttpResponseBufferSize() != null) {
            rmbuilder.destinationBufferQuota(Long.parseLong(endpoint.getHttpResponseBufferSize().trim()));
        }
        if (rxConfig.getBaseRetransmissionInterval() != null) {
            rmbuilder.messageRetransmissionInterval(Long.parseLong(rxConfig.getBaseRetransmissionInterval().trim()));
        }
        if (rxConfig.getRetransmissionExponentialBackoff() != null) {
            rmbuilder.retransmissionBackoffAlgorithm(Boolean.parseBoolean(rxConfig.getRetransmissionExponentialBackoff()) ? ReliableMessagingFeature.BackoffAlgorithm.EXPONENTIAL : ReliableMessagingFeature.BackoffAlgorithm.getDefault());
        }
        if (rxConfig.getAcknowledgementInterval() != null) {
            rmbuilder.acknowledgementTransmissionInterval(Long.parseLong(rxConfig.getAcknowledgementInterval().trim()));
        }
        if (rxConfig.getSequenceExpiration() != null) {
            logger.log(Level.INFO, LogUtils.CONFIGURATION_IGNORE_IN_WLSWS, new Object[] { endpoint.getEndpointName(), "<sequence-expiration>" });
        }
        if (rxConfig.getBufferRetryCount() != null) {
            rmbuilder.maxMessageRetransmissionCount(Long.parseLong(rxConfig.getBufferRetryCount().trim()));
        }
        if (rxConfig.getBufferRetryDelay() != null) {
            logger.log(Level.INFO, LogUtils.CONFIGURATION_IGNORE_IN_WLSWS, new Object[] { endpoint.getEndpointName(), "<buffer-retry-delay>" });
        }
        wsFeatures.add(rmbuilder.build());
    } else {
        if (endpoint.getHttpResponseBufferSize() != null) {
            logger.log(Level.WARNING, LogUtils.CONFIGURATION_UNSUPPORTED_IN_WLSWS, new Object[] { endpoint.getEndpointName(), "<http-response-buffersize>" });
        }
    }
    if (wsFeatures.size() > 0) {
        binding = BindingID.parse(givenBinding).createBinding(wsFeatures.toArray(new WebServiceFeature[wsFeatures.size()]));
    } else {
        binding = BindingID.parse(givenBinding).createBinding();
    }
    wsu.configureJAXWSServiceHandlers(endpoint, givenBinding, binding);
    // See if it is configured with JAX-WS extension InstanceResolver annotation like
    // @com.sun.xml.ws.developer.servlet.HttpSessionScope or @com.sun.xml.ws.developer.Stateful
    InstanceResolver ir = InstanceResolver.createFromInstanceResolverAnnotation(serviceEndpointClass);
    // TODO - Implement 109 StatefulInstanceResolver ??
    if (ir == null) {
        // use our own InstanceResolver that does not call @PostConstuct method before
        // @Resource injections have happened.
        ir = new InstanceResolverImpl(serviceEndpointClass);
    }
    Invoker inv = ir.createInvoker();
    WSEndpoint wsep = WSEndpoint.create(// The endpoint class
    serviceEndpointClass, // we do not want JAXWS to process @HandlerChain
    false, inv, // the service QName
    endpoint.getServiceName(), // the port
    endpoint.getWsdlPort(), // Our container with info on security/monitoring pipe
    container, // Derive binding
    binding, // primary WSDL
    primaryWsdl, // Collection of imported WSDLs and schema
    docs, catalogURL);
    // Fix for 6852 Add the ServletAdapter which implements the BoundEndpoint
    // container.addEndpoint(wsep);
    // For web components, this will be relative to the web app
    // context root.  Make sure there is a leading slash.
    String uri = endpoint.getEndpointAddressUri();
    String urlPattern = uri.startsWith("/") ? uri : "/" + uri;
    // The whole web app should have a single adapter list
    // This is to enable JAXWS publish WSDLs with proper addresses
    ServletAdapter adapter;
    synchronized (this) {
        ServletAdapterList list = (ServletAdapterList) servletContext.getAttribute("ADAPTER_LIST");
        if (list == null) {
            list = new ServletAdapterList();
            servletContext.setAttribute("ADAPTER_LIST", list);
        }
        adapter = ServletAdapter.class.cast(list.createAdapter(endpoint.getName(), urlPattern, wsep));
        container.addEndpoint(adapter);
    }
    registerEndpointUrlPattern(urlPattern, adapter);
}
Also used : WSBinding(com.sun.xml.ws.api.WSBinding) MalformedURLException(java.net.MalformedURLException) ReliabilityConfig(com.sun.enterprise.deployment.runtime.ws.ReliabilityConfig) AddressingFeature(javax.xml.ws.soap.AddressingFeature) URL(java.net.URL) ArrayList(java.util.ArrayList) URL(java.net.URL) RespectBindingFeature(javax.xml.ws.RespectBindingFeature) ServletAdapterList(com.sun.xml.ws.transport.http.servlet.ServletAdapterList) ServletAdapter(com.sun.xml.ws.transport.http.servlet.ServletAdapter) MTOMFeature(javax.xml.ws.soap.MTOMFeature) StreamingAttachmentFeature(com.sun.xml.ws.developer.StreamingAttachmentFeature) WebServiceFeature(javax.xml.ws.WebServiceFeature) Collection(java.util.Collection) ReliableMessagingFeatureBuilder(com.sun.xml.ws.rx.rm.api.ReliableMessagingFeatureBuilder) SchemaValidationFeature(com.sun.xml.ws.developer.SchemaValidationFeature)

Example 3 with ServletAdapter

use of com.sun.xml.ws.transport.http.servlet.ServletAdapter in project Payara by payara.

the class WebServiceEjbEndpointRegistry method unregisterEndpoint.

@Override
public void unregisterEndpoint(String endpointAddressUri) {
    EjbRuntimeEndpointInfo endpoint = null;
    synchronized (webServiceEjbEndpoints) {
        String uriRaw = endpointAddressUri;
        String uri = (uriRaw.charAt(0) == '/') ? uriRaw.substring(1) : uriRaw;
        ServletAdapterList list = adapterListMap.get(uri);
        if (list != null) {
            // since we are using the uri in the adapterListMap
            for (ServletAdapter x : list) {
                x.getEndpoint().dispose();
                for (Handler handler : x.getEndpoint().getBinding().getHandlerChain()) {
                    try {
                        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
                        if (wscImpl.getInvocationManager().getCurrentInvocation() != null) {
                            InjectionManager injManager = wscImpl.getInjectionManager();
                            injManager.destroyManagedObject(handler);
                        }
                    } catch (InjectionException e) {
                        logger.log(Level.WARNING, LogUtils.DESTORY_ON_HANDLER_FAILED, new Object[] { handler.getClass(), x.getEndpoint().getServiceName(), e.getMessage() });
                        continue;
                    }
                }
            }
            // Fix for issue 9523
            adapterListMap.remove(uri);
        }
        endpoint = (EjbRuntimeEndpointInfo) webServiceEjbEndpoints.remove(uri);
        regenerateEjbContextRoots();
    }
    if (endpoint == null) {
        return;
    }
    // notify the monitoring layers that an endpoint is destroyed
    WebServiceEngineImpl engine = WebServiceEngineImpl.getInstance();
    engine.removeHandler(endpoint.getEndpoint());
}
Also used : InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) ServletAdapter(com.sun.xml.ws.transport.http.servlet.ServletAdapter) Handler(javax.xml.ws.handler.Handler) ServletAdapterList(com.sun.xml.ws.transport.http.servlet.ServletAdapterList) WebServiceEngineImpl(org.glassfish.webservices.monitoring.WebServiceEngineImpl) InjectionManager(com.sun.enterprise.container.common.spi.util.InjectionManager)

Example 4 with ServletAdapter

use of com.sun.xml.ws.transport.http.servlet.ServletAdapter in project Payara by payara.

the class WebServiceReferenceManagerImpl method getServletAdapterBasedOnWsdlUrl.

/**
 * This method basically is a fall back mechanism to fetch required
 * parameters from wsdl url stored in ServiceReferenceDescriptor. The flow reaches
 * here only in case where required parameters could not be fetched
 * from WebBundleDescriptor.
 *
 * @param desc ServiceReferenceDescriptor
 * @return ServletAdapter instance having wsdl contents.
 */
private ServletAdapter getServletAdapterBasedOnWsdlUrl(ServiceReferenceDescriptor desc) {
    if (logger.isLoggable(Level.INFO)) {
        logger.log(Level.INFO, LogUtils.SERVLET_ADAPTER_BASED_ON_WSDL_URL, new Object[] { desc.getServiceLocalPart(), desc.getWsdlFileUrl() });
    }
    URL wsdl = desc.getWsdlFileUrl();
    String wsdlPath = wsdl.getPath().trim();
    if (!wsdlPath.contains(WebServiceEndpoint.PUBLISHING_SUBCONTEXT))
        return null;
    /*
          * WsdlPath indeed contains the WebServiceEndpoint.PUBLISHING_SUBCONTEXT,
          * e.g.assuming that context root is test and Service name is Translator
          * then wsdl url must be in the following format :
          * /test/Translator/__container$publishing$subctx/null?wsdl
          */
    String contextRootAndPath = wsdlPath.substring(1, // test/Translator
    wsdlPath.indexOf(WebServiceEndpoint.PUBLISHING_SUBCONTEXT) - 1);
    if (!(contextRootAndPath.length() > 0))
        return null;
    // {test, Translator}
    String[] contextRootAndPathArray = contextRootAndPath.split("/");
    if (contextRootAndPathArray.length != 2)
        return null;
    if (contextRootAndPathArray[0] == null)
        return null;
    // /test
    String contextRoot = "/" + contextRootAndPathArray[0];
    if (contextRootAndPathArray[1] == null)
        return null;
    // /Translator
    String webSevicePath = "/" + contextRootAndPathArray[1];
    String urlPattern = wsdlPath.substring(contextRoot.length());
    Adapter adapter = JAXWSAdapterRegistry.getInstance().getAdapter(contextRoot, webSevicePath, urlPattern);
    return adapter instanceof ServletAdapter ? (ServletAdapter) adapter : null;
}
Also used : ServletAdapter(com.sun.xml.ws.transport.http.servlet.ServletAdapter) ServletAdapter(com.sun.xml.ws.transport.http.servlet.ServletAdapter) URL(java.net.URL)

Example 5 with ServletAdapter

use of com.sun.xml.ws.transport.http.servlet.ServletAdapter in project Payara by payara.

the class WebServiceReferenceManagerImpl method getServletAdapter.

/**
 * Returns ServletAdapter instance holding wsdl for the WebService being referred
 * in WebServiceRef annotation.
 *
 * @param desc ServiceReferenceDescriptor
 * @return ServletAdapter instance having wsdl contents.
 */
private ServletAdapter getServletAdapter(ServiceReferenceDescriptor desc) {
    WebBundleDescriptor webBundle = null;
    WebServicesDescriptor webServicesDescriptor = null;
    if (desc.getBundleDescriptor() instanceof WebBundleDescriptor) {
        webBundle = ((WebBundleDescriptor) desc.getBundleDescriptor());
    } else {
        return getServletAdapterBasedOnWsdlUrl(desc);
    }
    /*
         * Get WebServicesDescriptor from WebBundleDescriptorImpl, Since we are
         * dealing with WebServiceRef annotation here, WebServicesDescriptor ought to have
         * reference to WebService in question. WebServicesDescriptor is never null as it
         * is being initialized at class level in BundleDescriptor.
         */
    WebServicesDescriptor wsDesc = webBundle.getWebServices();
    assert wsDesc != null;
    assert desc.getServiceLocalPart() != null;
    WebService webService = wsDesc.getWebServiceByName(desc.getServiceLocalPart());
    /*
         * If an unlikely event when there is no associated webService or desc.getServiceLocalPart()
         * itself is null, then fall back on fetching ServletAdapter based on wsdl url.
         */
    if (webService == null)
        return getServletAdapterBasedOnWsdlUrl(desc);
    String contextRoot = webBundle.getContextRoot();
    String webSevicePath = null;
    String publishingContext = null;
    for (WebServiceEndpoint endpoint : webService.getEndpoints()) {
        if (desc.getServiceName().equals(endpoint.getServiceName()) && desc.getServiceNamespaceUri().equals(endpoint.getWsdlService().getNamespaceURI())) {
            String endPointAddressURI = endpoint.getEndpointAddressUri();
            if (endPointAddressURI == null || endPointAddressURI.length() == 0)
                return null;
            webSevicePath = endPointAddressURI.startsWith("/") ? endPointAddressURI : ("/" + endPointAddressURI);
            publishingContext = "/" + endpoint.getPublishingUri() + "/" + webService.getWsdlFileUri();
            Adapter adapter = JAXWSAdapterRegistry.getInstance().getAdapter(contextRoot, webSevicePath, publishingContext);
            return adapter instanceof ServletAdapter ? (ServletAdapter) adapter : null;
        }
    }
    return null;
}
Also used : ServletAdapter(com.sun.xml.ws.transport.http.servlet.ServletAdapter) ServletAdapter(com.sun.xml.ws.transport.http.servlet.ServletAdapter)

Aggregations

ServletAdapter (com.sun.xml.ws.transport.http.servlet.ServletAdapter)10 ServletAdapterList (com.sun.xml.ws.transport.http.servlet.ServletAdapterList)3 InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)2 InjectionManager (com.sun.enterprise.container.common.spi.util.InjectionManager)2 URL (java.net.URL)2 ServletException (javax.servlet.ServletException)2 Handler (javax.xml.ws.handler.Handler)2 Endpoint (org.glassfish.webservices.monitoring.Endpoint)2 ReliabilityConfig (com.sun.enterprise.deployment.runtime.ws.ReliabilityConfig)1 WSBinding (com.sun.xml.ws.api.WSBinding)1 SchemaValidationFeature (com.sun.xml.ws.developer.SchemaValidationFeature)1 StreamingAttachmentFeature (com.sun.xml.ws.developer.StreamingAttachmentFeature)1 ReliableMessagingFeatureBuilder (com.sun.xml.ws.rx.rm.api.ReliableMessagingFeatureBuilder)1 RequestTraceSpan (fish.payara.notification.requesttracing.RequestTraceSpan)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 ServletContext (javax.servlet.ServletContext)1 RespectBindingFeature (javax.xml.ws.RespectBindingFeature)1