Search in sources :

Example 1 with MetadataReader

use of com.sun.xml.ws.api.databinding.MetadataReader in project metro-jax-ws by eclipse-ee4j.

the class EndpointFactory method create.

public <T> WSEndpoint<T> create(Class<T> implType, boolean processHandlerAnnotation, @Nullable Invoker invoker, @Nullable QName serviceName, @Nullable QName portName, @Nullable Container container, @Nullable WSBinding binding, @Nullable SDDocumentSource primaryWsdl, @Nullable Collection<? extends SDDocumentSource> metadata, EntityResolver resolver, boolean isTransportSynchronous, boolean isStandard) {
    if (implType == null)
        throw new IllegalArgumentException();
    MetadataReader metadataReader = getExternalMetadatReader(implType, binding);
    if (isStandard) {
        verifyImplementorClass(implType, metadataReader);
    }
    if (invoker == null) {
        invoker = InstanceResolver.createDefault(implType).createInvoker();
    }
    // Performance analysis indicates that reading and parsing imported schemas is
    // a major component of Endpoint creation time.  Therefore, modify SDDocumentSource
    // handling to delay iterating collection as long as possible.
    Collection<SDDocumentSource> md = new CollectionCollection<>();
    if (primaryWsdl != null) {
        if (metadata != null) {
            Iterator<? extends SDDocumentSource> it = metadata.iterator();
            if (it.hasNext() && primaryWsdl.equals(it.next()))
                md.addAll(metadata);
            else {
                md.add(primaryWsdl);
                md.addAll(metadata);
            }
        } else
            md.add(primaryWsdl);
    } else if (metadata != null)
        md.addAll(metadata);
    if (container == null)
        container = ContainerResolver.getInstance().getContainer();
    if (serviceName == null)
        serviceName = getDefaultServiceName(implType, metadataReader);
    if (portName == null)
        portName = getDefaultPortName(serviceName, implType, metadataReader);
    {
        // error check
        String serviceNS = serviceName.getNamespaceURI();
        String portNS = portName.getNamespaceURI();
        if (!serviceNS.equals(portNS)) {
            throw new ServerRtException("wrong.tns.for.port", portNS, serviceNS);
        }
    }
    // setting a default binding
    if (binding == null)
        binding = BindingImpl.create(BindingID.parse(implType));
    if (isStandard && primaryWsdl != null) {
        verifyPrimaryWSDL(primaryWsdl, serviceName);
    }
    QName portTypeName = null;
    if (isStandard && implType.getAnnotation(WebServiceProvider.class) == null) {
        portTypeName = RuntimeModeler.getPortTypeName(implType, metadataReader);
    }
    // Categorises the documents as WSDL, Schema etc
    Collection<SDDocumentImpl> docList = categoriseMetadata(md.iterator(), serviceName, portTypeName);
    // Finds the primary WSDL and makes sure that metadata doesn't have
    // two concrete or abstract WSDLs
    SDDocumentImpl primaryDoc = primaryWsdl != null ? SDDocumentImpl.create(primaryWsdl, serviceName, portTypeName) : findPrimary(docList);
    EndpointAwareTube terminal;
    WSDLPort wsdlPort = null;
    AbstractSEIModelImpl seiModel = null;
    // create WSDL model
    if (primaryDoc != null) {
        wsdlPort = getWSDLPort(primaryDoc, docList, serviceName, portName, container, resolver);
    }
    WebServiceFeatureList features = ((BindingImpl) binding).getFeatures();
    if (isStandard) {
        features.parseAnnotations(implType);
    }
    PolicyMap policyMap = null;
    // create terminal pipe that invokes the application
    if (isUseProviderTube(implType, isStandard)) {
        // TODO incase of Provider, provide a way to User for complete control of the message processing by giving
        // ability to turn off the WSDL/Policy based features and its associated tubes.
        // Even in case of Provider, merge all features configured via WSDL/Policy or deployment configuration
        Iterable<WebServiceFeature> configFtrs;
        if (wsdlPort != null) {
            policyMap = wsdlPort.getOwner().getParent().getPolicyMap();
            // Merge features from WSDL and other policy configuration
            configFtrs = wsdlPort.getFeatures();
        } else {
            // No WSDL, so try to merge features from Policy configuration
            policyMap = PolicyResolverFactory.create().resolve(new PolicyResolver.ServerContext(null, container, implType, false));
            configFtrs = PolicyUtil.getPortScopedFeatures(policyMap, serviceName, portName);
        }
        features.mergeFeatures(configFtrs, true);
        terminal = createProviderInvokerTube(implType, binding, invoker, container);
    } else {
        // Create runtime model for non Provider endpoints
        seiModel = createSEIModel(wsdlPort, implType, serviceName, portName, binding, primaryDoc);
        if (binding instanceof SOAPBindingImpl) {
            // set portKnownHeaders on Binding, so that they can be used for MU processing
            ((SOAPBindingImpl) binding).setPortKnownHeaders(((SOAPSEIModel) seiModel).getKnownHeaders());
        }
        // Generate WSDL for SEI endpoints(not for Provider endpoints)
        if (primaryDoc == null) {
            primaryDoc = generateWSDL(binding, seiModel, docList, container, implType);
            // create WSDL model
            wsdlPort = getWSDLPort(primaryDoc, docList, serviceName, portName, container, resolver);
            seiModel.freeze(wsdlPort);
        }
        policyMap = wsdlPort.getOwner().getParent().getPolicyMap();
        // New Features might have been added in WSDL through Policy.
        // Merge features from WSDL and other policy configuration
        // This sets only the wsdl features that are not already set(enabled/disabled)
        features.mergeFeatures(wsdlPort.getFeatures(), true);
        terminal = createSEIInvokerTube(seiModel, invoker, binding);
    }
    // Process @HandlerChain, if handler-chain is not set via Deployment Descriptor
    if (processHandlerAnnotation) {
        processHandlerAnnotation(binding, implType, serviceName, portName);
    }
    // Selects only required metadata for this endpoint from the passed-in metadata
    if (primaryDoc != null) {
        docList = findMetadataClosure(primaryDoc, docList, resolver);
    }
    ServiceDefinitionImpl serviceDefiniton = (primaryDoc != null) ? new ServiceDefinitionImpl(docList, primaryDoc) : null;
    return create(serviceName, portName, binding, container, seiModel, wsdlPort, implType, serviceDefiniton, terminal, isTransportSynchronous, policyMap);
}
Also used : BindingImpl(com.sun.xml.ws.binding.BindingImpl) SOAPBindingImpl(com.sun.xml.ws.binding.SOAPBindingImpl) AbstractSEIModelImpl(com.sun.xml.ws.model.AbstractSEIModelImpl) QName(javax.xml.namespace.QName) MetadataReader(com.sun.xml.ws.api.databinding.MetadataReader) WebServiceFeatureList(com.sun.xml.ws.binding.WebServiceFeatureList) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort) SDDocumentSource(com.sun.xml.ws.api.server.SDDocumentSource) PolicyMap(com.sun.xml.ws.policy.PolicyMap) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) SOAPBindingImpl(com.sun.xml.ws.binding.SOAPBindingImpl)

Example 2 with MetadataReader

use of com.sun.xml.ws.api.databinding.MetadataReader in project metro-jax-ws by eclipse-ee4j.

the class DeploymentDescriptorParser method parseAdapters.

private List<A> parseAdapters(XMLStreamReader reader) {
    if (!reader.getName().equals(QNAME_ENDPOINTS)) {
        failWithFullName("runtime.parser.invalidElement", reader);
    }
    List<A> adapters = new ArrayList<>();
    Attributes attrs = XMLStreamReaderUtil.getAttributes(reader);
    String version = getMandatoryNonEmptyAttribute(reader, attrs, ATTR_VERSION);
    if (!ATTRVALUE_SUPPORTED_VERSIONS.contains(version)) {
        failWithLocalName("runtime.parser.invalidVersionNumber", reader, version);
    }
    while (XMLStreamReaderUtil.nextElementContent(reader) != XMLStreamConstants.END_ELEMENT) {
        if (reader.getName().equals(QNAME_ENDPOINT)) {
            attrs = XMLStreamReaderUtil.getAttributes(reader);
            String name = getMandatoryNonEmptyAttribute(reader, attrs, ATTR_NAME);
            if (!names.add(name)) {
                logger.warning(WsservletMessages.SERVLET_WARNING_DUPLICATE_ENDPOINT_NAME());
            }
            String implementationName = getMandatoryNonEmptyAttribute(reader, attrs, ATTR_IMPLEMENTATION);
            Class<?> implementorClass = getImplementorClass(implementationName, reader);
            MetadataReader metadataReader = null;
            ExternalMetadataFeature externalMetadataFeature = null;
            // parse subelements to instantiate externalMetadataReader, if necessary ...
            XMLStreamReaderUtil.nextElementContent(reader);
            if (reader.getEventType() != XMLStreamConstants.END_ELEMENT) {
                externalMetadataFeature = configureExternalMetadataReader(reader);
                if (externalMetadataFeature != null) {
                    metadataReader = externalMetadataFeature.getMetadataReader(implementorClass.getClassLoader(), false);
                }
            }
            QName serviceName = getQNameAttribute(attrs, ATTR_SERVICE);
            if (serviceName == null) {
                serviceName = EndpointFactory.getDefaultServiceName(implementorClass, metadataReader);
            }
            QName portName = getQNameAttribute(attrs, ATTR_PORT);
            if (portName == null) {
                portName = EndpointFactory.getDefaultPortName(serviceName, implementorClass, metadataReader);
            }
            // get enable-mtom attribute value
            String enable_mtom = getAttribute(attrs, ATTR_ENABLE_MTOM);
            String mtomThreshold = getAttribute(attrs, ATTR_MTOM_THRESHOLD_VALUE);
            String dbMode = getAttribute(attrs, ATTR_DATABINDING);
            String bindingId = getAttribute(attrs, ATTR_BINDING);
            if (bindingId != null) {
                // Convert short-form tokens to API's binding ids
                bindingId = getBindingIdForToken(bindingId);
            }
            WSBinding binding = createBinding(bindingId, implementorClass, enable_mtom, mtomThreshold, dbMode);
            if (externalMetadataFeature != null) {
                binding.getFeatures().mergeFeatures(new WebServiceFeature[] { externalMetadataFeature }, true);
            }
            String urlPattern = getMandatoryNonEmptyAttribute(reader, attrs, ATTR_URL_PATTERN);
            // TODO use 'docs' as the metadata. If wsdl is non-null it's the primary.
            boolean handlersSetInDD = setHandlersAndRoles(binding, reader, serviceName, portName);
            EndpointFactory.verifyImplementorClass(implementorClass, metadataReader);
            SDDocumentSource primaryWSDL = getPrimaryWSDL(reader, attrs, implementorClass, metadataReader);
            WSEndpoint<?> endpoint = WSEndpoint.create(implementorClass, !handlersSetInDD, null, serviceName, portName, container, binding, primaryWSDL, docs.values(), createEntityResolver(), false);
            adapters.add(adapterFactory.createAdapter(name, urlPattern, endpoint));
        } else {
            failWithLocalName("runtime.parser.invalidElement", reader);
        }
    }
    return adapters;
}
Also used : WSBinding(com.sun.xml.ws.api.WSBinding) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Attributes(com.sun.xml.ws.streaming.Attributes) MetadataReader(com.sun.xml.ws.api.databinding.MetadataReader) ExternalMetadataFeature(com.oracle.webservices.api.databinding.ExternalMetadataFeature) SDDocumentSource(com.sun.xml.ws.api.server.SDDocumentSource)

Example 3 with MetadataReader

use of com.sun.xml.ws.api.databinding.MetadataReader in project metro-jax-ws by eclipse-ee4j.

the class EndpointImpl method createEndpoint.

/*
    * Checks the permission of "publishEndpoint" before accessing HTTP classes.
    * Also it checks if there is an available HTTP server implementation.
    */
private void createEndpoint(String urlPattern) {
    // Checks permission for "publishEndpoint"
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(ENDPOINT_PUBLISH_PERMISSION);
    }
    // See if HttpServer implementation is available
    try {
        Class.forName("com.sun.net.httpserver.HttpServer");
    } catch (Exception e) {
        throw new UnsupportedOperationException("Couldn't load light weight http server", e);
    }
    container = getContainer();
    MetadataReader metadataReader = EndpointFactory.getExternalMetadatReader(implClass, binding);
    WSEndpoint wse = WSEndpoint.create(implClass, true, invoker, getProperty(QName.class, Endpoint.WSDL_SERVICE), getProperty(QName.class, Endpoint.WSDL_PORT), container, binding, getPrimaryWsdl(metadataReader), buildDocList(), null, false);
    // Don't load HttpEndpoint class before as it may load HttpServer classes
    actualEndpoint = new HttpEndpoint(executor, getAdapter(wse, urlPattern));
}
Also used : QName(javax.xml.namespace.QName) MetadataReader(com.sun.xml.ws.api.databinding.MetadataReader) TransformerException(javax.xml.transform.TransformerException) ServerRtException(com.sun.xml.ws.server.ServerRtException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 4 with MetadataReader

use of com.sun.xml.ws.api.databinding.MetadataReader in project metro-jax-ws by eclipse-ee4j.

the class HandlerAnnotationProcessor method buildHandlerInfo.

/**
 * <p>This method is called by
 * {@link EndpointFactory} when
 * they have an annotated class.
 *
 * <p>If there is no handler chain annotation on the class,
 * this method will return null. Otherwise it will load the
 * class and call the parseHandlerFile method to read the
 * information.
 *
 * @return A HandlerAnnotationInfo object that stores the
 * handlers and roles. Will return null if the class passed
 * in has no handler chain annotation.
 */
public static HandlerAnnotationInfo buildHandlerInfo(@NotNull Class<?> clazz, QName serviceName, QName portName, WSBinding binding) {
    MetadataReader metadataReader = EndpointFactory.getExternalMetadatReader(clazz, binding);
    if (metadataReader == null) {
        metadataReader = new ReflectAnnotationReader();
    }
    // clazz = checkClass(clazz);
    HandlerChain handlerChain = metadataReader.getAnnotation(HandlerChain.class, clazz);
    if (handlerChain == null) {
        clazz = getSEI(clazz, metadataReader);
        if (clazz != null)
            handlerChain = metadataReader.getAnnotation(HandlerChain.class, clazz);
        if (handlerChain == null)
            return null;
    }
    if (clazz.getAnnotation(SOAPMessageHandlers.class) != null) {
        throw new UtilException("util.handler.cannot.combine.soapmessagehandlers");
    }
    InputStream iStream = getFileAsStream(clazz, handlerChain);
    XMLStreamReader reader = XMLStreamReaderFactory.create(null, iStream, true);
    XMLStreamReaderUtil.nextElementContent(reader);
    HandlerAnnotationInfo handlerAnnInfo = HandlerChainsModel.parseHandlerFile(reader, clazz.getClassLoader(), serviceName, portName, binding);
    try {
        reader.close();
        iStream.close();
    } catch (XMLStreamException | IOException e) {
        e.printStackTrace();
        throw new UtilException(e.getMessage());
    }
    return handlerAnnInfo;
}
Also used : HandlerChain(jakarta.jws.HandlerChain) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) MetadataReader(com.sun.xml.ws.api.databinding.MetadataReader) SOAPMessageHandlers(jakarta.jws.soap.SOAPMessageHandlers) IOException(java.io.IOException) ReflectAnnotationReader(com.sun.xml.ws.model.ReflectAnnotationReader)

Aggregations

MetadataReader (com.sun.xml.ws.api.databinding.MetadataReader)4 QName (javax.xml.namespace.QName)3 SDDocumentSource (com.sun.xml.ws.api.server.SDDocumentSource)2 IOException (java.io.IOException)2 ExternalMetadataFeature (com.oracle.webservices.api.databinding.ExternalMetadataFeature)1 WSBinding (com.sun.xml.ws.api.WSBinding)1 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)1 BindingImpl (com.sun.xml.ws.binding.BindingImpl)1 SOAPBindingImpl (com.sun.xml.ws.binding.SOAPBindingImpl)1 WebServiceFeatureList (com.sun.xml.ws.binding.WebServiceFeatureList)1 AbstractSEIModelImpl (com.sun.xml.ws.model.AbstractSEIModelImpl)1 ReflectAnnotationReader (com.sun.xml.ws.model.ReflectAnnotationReader)1 PolicyMap (com.sun.xml.ws.policy.PolicyMap)1 ServerRtException (com.sun.xml.ws.server.ServerRtException)1 Attributes (com.sun.xml.ws.streaming.Attributes)1 HandlerChain (jakarta.jws.HandlerChain)1 SOAPMessageHandlers (jakarta.jws.soap.SOAPMessageHandlers)1 WebServiceFeature (jakarta.xml.ws.WebServiceFeature)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1