Search in sources :

Example 1 with WSBinding

use of com.sun.xml.ws.api.WSBinding 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 2 with WSBinding

use of com.sun.xml.ws.api.WSBinding in project Payara by payara.

the class V3Module method createServiceChannelEndpoint.

@Override
public WSEndpoint<ServiceChannelWSImpl> createServiceChannelEndpoint() {
    Class<ServiceChannelWSImpl> serviceEndpointClass = ServiceChannelWSImpl.class;
    final QName serviceName = WSEndpoint.getDefaultServiceName(ServiceChannelWSImpl.class);
    final QName portName = WSEndpoint.getDefaultPortName(serviceName, ServiceChannelWSImpl.class);
    final BindingID bindingId = BindingID.parse(ServiceChannelWSImpl.class);
    final WSBinding binding = bindingId.createBinding();
    return WSEndpoint.create(serviceEndpointClass, false, null, serviceName, portName, Container.NONE, binding, null, null, (EntityResolver) null, true);
}
Also used : WSBinding(com.sun.xml.ws.api.WSBinding) ServiceChannelWSImpl(com.sun.xml.ws.transport.tcp.servicechannel.ServiceChannelWSImpl) QName(javax.xml.namespace.QName) BindingID(com.sun.xml.ws.api.BindingID)

Example 3 with WSBinding

use of com.sun.xml.ws.api.WSBinding in project Payara by payara.

the class EjbRuntimeEndpointInfo method prepareInvocation.

public Object prepareInvocation(boolean doPreInvoke) throws Exception {
    ComponentInvocation inv = null;
    AdapterInvocationInfo adapterInvInfo = new AdapterInvocationInfo();
    // init'ing jaxws is done here - this sequence is important
    if (adapter == null) {
        synchronized (this) {
            if (adapter == null) {
                try {
                    // Set webservice context here
                    // If the endpoint has a WebServiceContext with @Resource then
                    // that has to be used
                    EjbDescriptor ejbDesc = endpoint.getEjbComponentImpl();
                    Iterator<ResourceReferenceDescriptor> it = ejbDesc.getResourceReferenceDescriptors().iterator();
                    while (it.hasNext()) {
                        ResourceReferenceDescriptor r = it.next();
                        if (r.isWebServiceContext()) {
                            Iterator<InjectionTarget> iter = r.getInjectionTargets().iterator();
                            boolean matchingClassFound = false;
                            while (iter.hasNext()) {
                                InjectionTarget target = iter.next();
                                if (ejbDesc.getEjbClassName().equals(target.getClassName())) {
                                    matchingClassFound = true;
                                    break;
                                }
                            }
                            if (!matchingClassFound) {
                                continue;
                            }
                            try {
                                javax.naming.InitialContext ic = new javax.naming.InitialContext();
                                wsCtxt = (WebServiceContextImpl) ic.lookup("java:comp/env/" + r.getName());
                            } catch (Throwable t) {
                                if (logger.isLoggable(Level.FINE)) {
                                    logger.log(Level.FINE, LogUtils.ERROR_EREI, t.getCause());
                                }
                            }
                        }
                    }
                    if (wsCtxt == null) {
                        wsCtxt = new WebServiceContextImpl();
                    }
                } catch (Throwable t) {
                    LogHelper.log(logger, Level.SEVERE, LogUtils.CANNOT_INITIALIZE, t, endpoint.getName());
                    return null;
                }
            }
        }
    }
    if (doPreInvoke) {
        inv = container.startInvocation();
        adapterInvInfo.setInv(inv);
    }
    // Now process handlers and init jaxws RI
    synchronized (this) {
        if (!handlersConfigured && doPreInvoke) {
            try {
                WsUtil wsu = new WsUtil();
                String implClassName = endpoint.getEjbComponentImpl().getEjbClassName();
                Class clazz = container.getEndpointClassLoader().loadClass(implClassName);
                // Get the proper binding using BindingID
                String givenBinding = endpoint.getProtocolBinding();
                // Get list of all wsdls and schema
                SDDocumentSource primaryWsdl = null;
                Collection docs = null;
                if (endpoint.getWebService().hasWsdlFile()) {
                    WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
                    ApplicationRegistry appRegistry = wscImpl.getApplicationRegistry();
                    ApplicationInfo appInfo = appRegistry.get(endpoint.getBundleDescriptor().getApplication().getRegistrationName());
                    URI deployedDir = appInfo.getSource().getURI();
                    URL pkgedWsdl;
                    if (deployedDir != null) {
                        if (endpoint.getBundleDescriptor().getApplication().isVirtual()) {
                            pkgedWsdl = deployedDir.resolve(endpoint.getWebService().getWsdlFileUri()).toURL();
                        } else {
                            String moduleUri1 = endpoint.getBundleDescriptor().getModuleDescriptor().getArchiveUri();
                            // Fix for issue 7024099
                            // Only replace the last "." with "_" for moduleDescriptor's archive uri
                            String moduleUri = FileUtils.makeFriendlyFilenameExtension(moduleUri1);
                            pkgedWsdl = deployedDir.resolve(moduleUri + "/" + endpoint.getWebService().getWsdlFileUri()).toURL();
                        }
                    } else {
                        pkgedWsdl = endpoint.getWebService().getWsdlFileUrl();
                    }
                    if (pkgedWsdl != null) {
                        primaryWsdl = SDDocumentSource.create(pkgedWsdl);
                        docs = wsu.getWsdlsAndSchemas(pkgedWsdl);
                    }
                }
                // Create a Container to pass ServletContext and also inserting the pipe
                JAXWSContainer container = new JAXWSContainer(null, endpoint);
                // Get catalog info
                java.net.URL catalogURL = clazz.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;
                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 (endpoint.getAddressing() != null) {
                    AddressingFeature addressingFeature = new AddressingFeature(addressing.isEnabled(), addressing.isRequired(), getResponse(addressing.getResponses()));
                    wsFeatures.add(addressingFeature);
                }
                if (wsFeatures.size() > 0) {
                    binding = BindingID.parse(givenBinding).createBinding(wsFeatures.toArray(new WebServiceFeature[wsFeatures.size()]));
                } else {
                    binding = BindingID.parse(givenBinding).createBinding();
                }
                wsu.configureJAXWSServiceHandlers(endpoint, endpoint.getProtocolBinding(), 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
                // #GLASSFISH-21081
                InstanceResolver ir = InstanceResolver.createFromInstanceResolverAnnotation(clazz);
                // 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(clazz);
                }
                // Create the jaxws2.1 invoker and use this
                Invoker invoker = ir.createInvoker();
                WSEndpoint wsep = WSEndpoint.create(// The endpoint class
                clazz, // we do not want JAXWS to process @HandlerChain
                false, // the invoker
                new EjbInvokerImpl(clazz, invoker, webServiceEndpointServant, wsCtxt), // the service QName
                endpoint.getServiceName(), // the port
                endpoint.getWsdlPort(), container, // Derive binding
                binding, // primary WSDL
                primaryWsdl, // Collection of imported WSDLs and schema
                docs, catalogURL);
                String uri = endpoint.getEndpointAddressUri();
                String urlPattern = uri.startsWith("/") ? uri : "/" + uri;
                // All set; Create the adapter
                if (adapterList == null) {
                    adapterList = new ServletAdapterList();
                }
                adapter = adapterList.createAdapter(endpoint.getName(), urlPattern, wsep);
                handlersConfigured = true;
            } catch (Throwable t) {
                LogHelper.log(logger, Level.SEVERE, LogUtils.CANNOT_INITIALIZE, t, endpoint.getName());
                adapter = null;
            }
        }
    }
    // set it using this method
    synchronized (this) {
        addWSContextInfo(wsCtxt);
        if (inv != null && inv instanceof EJBInvocation) {
            EJBInvocation ejbInv = (EJBInvocation) inv;
            ejbInv.setWebServiceContext(wsCtxt);
        }
    }
    adapterInvInfo.setAdapter(adapter);
    return adapterInvInfo;
}
Also used : WSBinding(com.sun.xml.ws.api.WSBinding) AddressingFeature(javax.xml.ws.soap.AddressingFeature) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) URL(java.net.URL) InstanceResolver(com.sun.xml.ws.api.server.InstanceResolver) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ArrayList(java.util.ArrayList) URI(java.net.URI) URL(java.net.URL) ApplicationRegistry(org.glassfish.internal.data.ApplicationRegistry) SDDocumentSource(com.sun.xml.ws.api.server.SDDocumentSource) Invoker(com.sun.xml.ws.api.server.Invoker) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) ServletAdapterList(com.sun.xml.ws.transport.http.servlet.ServletAdapterList) MTOMFeature(javax.xml.ws.soap.MTOMFeature) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) WebServiceFeature(javax.xml.ws.WebServiceFeature) Collection(java.util.Collection) EJBInvocation(org.glassfish.ejb.api.EJBInvocation)

Aggregations

WSBinding (com.sun.xml.ws.api.WSBinding)3 ServletAdapterList (com.sun.xml.ws.transport.http.servlet.ServletAdapterList)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 WebServiceFeature (javax.xml.ws.WebServiceFeature)2 AddressingFeature (javax.xml.ws.soap.AddressingFeature)2 MTOMFeature (javax.xml.ws.soap.MTOMFeature)2 ReliabilityConfig (com.sun.enterprise.deployment.runtime.ws.ReliabilityConfig)1 BindingID (com.sun.xml.ws.api.BindingID)1 InstanceResolver (com.sun.xml.ws.api.server.InstanceResolver)1 Invoker (com.sun.xml.ws.api.server.Invoker)1 SDDocumentSource (com.sun.xml.ws.api.server.SDDocumentSource)1 WSEndpoint (com.sun.xml.ws.api.server.WSEndpoint)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 ServletAdapter (com.sun.xml.ws.transport.http.servlet.ServletAdapter)1 ServiceChannelWSImpl (com.sun.xml.ws.transport.tcp.servicechannel.ServiceChannelWSImpl)1 MalformedURLException (java.net.MalformedURLException)1