Search in sources :

Example 1 with SDDocument

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

the class HttpAdapter method handleGet.

public boolean handleGet(@NotNull WSHTTPConnection connection) throws IOException {
    if (connection.getRequestMethod().equals("GET")) {
        // metadata query. let the interceptor run
        for (Component c : endpoint.getComponents()) {
            HttpMetadataPublisher spi = c.getSPI(HttpMetadataPublisher.class);
            if (spi != null && spi.handleMetadataRequest(this, connection)) {
                return true;
            }
        // handled
        }
        if (isMetadataQuery(connection.getQueryString())) {
            // Sends published WSDL and schema documents as the default action.
            publishWSDL(connection);
            return true;
        }
        Binding binding = getEndpoint().getBinding();
        if (!(binding instanceof HTTPBinding)) {
            // Writes HTML page with all the endpoint descriptions
            writeWebServicesHtmlPage(connection);
            return true;
        }
    } else if (connection.getRequestMethod().equals("HEAD")) {
        connection.getInput().close();
        Binding binding = getEndpoint().getBinding();
        if (isMetadataQuery(connection.getQueryString())) {
            SDDocument doc = wsdls.get(connection.getQueryString());
            connection.setStatus(doc != null ? HttpURLConnection.HTTP_OK : HttpURLConnection.HTTP_NOT_FOUND);
            connection.getOutput().close();
            connection.close();
            return true;
        } else if (!(binding instanceof HTTPBinding)) {
            connection.setStatus(HttpURLConnection.HTTP_NOT_FOUND);
            connection.getOutput().close();
            connection.close();
            return true;
        }
    // Let the endpoint handle for HTTPBinding
    }
    return false;
}
Also used : Binding(jakarta.xml.ws.Binding) HTTPBinding(jakarta.xml.ws.http.HTTPBinding) SDDocument(com.sun.xml.ws.api.server.SDDocument) Component(com.sun.xml.ws.api.Component) HTTPBinding(jakarta.xml.ws.http.HTTPBinding)

Example 2 with SDDocument

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

the class HttpAdapter method publishWSDL.

/**
 * Sends out the WSDL (and other referenced documents)
 * in response to the GET requests to URLs like "?wsdl" or "?xsd=2".
 *
 * @param con
 *      The connection to which the data will be sent.
 *
 * @throws java.io.IOException when I/O errors happen
 */
public void publishWSDL(@NotNull WSHTTPConnection con) throws IOException {
    con.getInput().close();
    SDDocument doc = wsdls.get(con.getQueryString());
    if (doc == null) {
        writeNotFoundErrorPage(con, "Invalid Request");
        return;
    }
    con.setStatus(HttpURLConnection.HTTP_OK);
    con.setContentTypeResponseHeader("text/xml;charset=utf-8");
    OutputStream os = con.getProtocol().contains("1.1") ? con.getOutput() : new Http10OutputStream(con);
    PortAddressResolver portAddressResolver = getPortAddressResolver(con.getBaseAddress());
    DocumentAddressResolver resolver = getDocumentAddressResolver(portAddressResolver);
    doc.writeTo(portAddressResolver, resolver, os);
    os.close();
}
Also used : PortAddressResolver(com.sun.xml.ws.api.server.PortAddressResolver) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) SDDocument(com.sun.xml.ws.api.server.SDDocument) DocumentAddressResolver(com.sun.xml.ws.api.server.DocumentAddressResolver)

Example 3 with SDDocument

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

the class AbstractSchemaValidationTube method getSchemaSources.

/*
     * Using the following algorithm described in the xerces discussion thread:
     *
     * "If you're synthesizing schema documents to glue together the ones in
     * the WSDL then you may not even need to use "honour-all-schemaLocations".
     * Create a schema document for each namespace with <xs:include>s
     * (for each schema document in the WSDL with that target namespace)
     * and then combine those together with <xs:import>s for each of those
     * namespaces in a "master" schema document.
     *
     * That should work with any schema processor, not just those which
     * honour multiple imports for the same namespace."
     */
protected Source[] getSchemaSources(Iterable<SDDocument> docs, MetadataResolverImpl mdresolver) {
    // All schema fragments in WSDLs are put inlinedSchemas
    // systemID --> DOMSource
    Map<String, DOMSource> inlinedSchemas = new HashMap<>();
    // Consolidates all the schemas(inlined and external) for a tns
    // tns --> list of systemId
    Map<String, List<String>> multiSchemaForTns = new HashMap<>();
    for (SDDocument sdoc : docs) {
        if (sdoc.isWSDL()) {
            Document dom = createDOM(sdoc);
            // Get xsd:schema node from WSDL's DOM
            addSchemaFragmentSource(dom, sdoc.getURL().toExternalForm(), inlinedSchemas);
        } else if (sdoc.isSchema()) {
            updateMultiSchemaForTns(((SDDocument.Schema) sdoc).getTargetNamespace(), sdoc.getURL().toExternalForm(), multiSchemaForTns);
        }
    }
    if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(Level.FINE, "WSDL inlined schema fragment documents(these are used to create a pseudo schema) = {0}", inlinedSchemas.keySet());
    }
    for (DOMSource src : inlinedSchemas.values()) {
        String tns = getTargetNamespace(src);
        updateMultiSchemaForTns(tns, src.getSystemId(), multiSchemaForTns);
    }
    if (multiSchemaForTns.isEmpty()) {
        // WSDL doesn't have any schema fragments
        return new Source[0];
    } else if (multiSchemaForTns.size() == 1 && multiSchemaForTns.values().iterator().next().size() == 1) {
        // It must be a inlined schema, otherwise there would be at least two schemas
        String systemId = multiSchemaForTns.values().iterator().next().get(0);
        return new Source[] { inlinedSchemas.get(systemId) };
    }
    // need to resolve these inlined schema fragments
    mdresolver.addSchemas(inlinedSchemas.values());
    // If there are multiple schema fragments for the same tns, create a
    // pseudo schema for that tns by using <xsd:include> of those.
    // tns --> systemId of a pseudo schema document (consolidated for that tns)
    Map<String, String> oneSchemaForTns = new HashMap<>();
    int i = 0;
    for (Map.Entry<String, List<String>> e : multiSchemaForTns.entrySet()) {
        String systemId;
        List<String> sameTnsSchemas = e.getValue();
        if (sameTnsSchemas.size() > 1) {
            // SDDocumentSource should be changed to take String systemId
            // String pseudoSystemId = "urn:x-jax-ws-include-"+i++;
            systemId = "file:x-jax-ws-include-" + i++;
            Source src = createSameTnsPseudoSchema(e.getKey(), sameTnsSchemas, systemId);
            mdresolver.addSchema(src);
        } else {
            systemId = sameTnsSchemas.get(0);
        }
        oneSchemaForTns.put(e.getKey(), systemId);
    }
    // create a master pseudo schema with all the different tns
    Source pseudoSchema = createMasterPseudoSchema(oneSchemaForTns);
    return new Source[] { pseudoSchema };
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) HashMap(java.util.HashMap) Document(org.w3c.dom.Document) SDDocument(com.sun.xml.ws.api.server.SDDocument) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SDDocumentSource(com.sun.xml.ws.api.server.SDDocumentSource) SDDocument(com.sun.xml.ws.api.server.SDDocument) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 4 with SDDocument

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

the class AbstractSchemaValidationTube method createDOM.

private Document createDOM(SDDocument doc) {
    // Get infoset
    ByteArrayBuffer bab = new ByteArrayBuffer();
    try {
        doc.writeTo(null, resolver, bab);
    } catch (IOException ioe) {
        throw new WebServiceException(ioe);
    }
    // Convert infoset to DOM
    Transformer trans = XmlUtil.newTransformer();
    // doc.getURL().toExternalForm());
    Source source = new StreamSource(bab.newInputStream(), null);
    DOMResult result = new DOMResult();
    try {
        trans.transform(source, result);
    } catch (TransformerException te) {
        throw new WebServiceException(te);
    }
    return (Document) result.getNode();
}
Also used : Transformer(javax.xml.transform.Transformer) DOMResult(javax.xml.transform.dom.DOMResult) WebServiceException(jakarta.xml.ws.WebServiceException) StreamSource(javax.xml.transform.stream.StreamSource) IOException(java.io.IOException) Document(org.w3c.dom.Document) SDDocument(com.sun.xml.ws.api.server.SDDocument) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SDDocumentSource(com.sun.xml.ws.api.server.SDDocumentSource) TransformerException(javax.xml.transform.TransformerException) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 5 with SDDocument

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

the class MetadataUtil method getMetadataClosure.

/**
 * Gets closure of all the referenced documents from the primary document(typically
 * the service WSDL). It traverses the WSDL and schema imports and builds a closure
 * set of documents.
 *
 * @param systemId primary wsdl or the any root document
 * @param resolver used to get SDDocumentImpl for a document
 * @param onlyTopLevelSchemas if true, the imported schemas from a schema would be ignored
 * @return all the documents
 */
public static Map<String, SDDocument> getMetadataClosure(@NotNull String systemId, @NotNull SDDocumentResolver resolver, boolean onlyTopLevelSchemas) {
    Map<String, SDDocument> closureDocs = new HashMap<>();
    Set<String> remaining = new HashSet<>();
    remaining.add(systemId);
    while (!remaining.isEmpty()) {
        Iterator<String> it = remaining.iterator();
        String current = it.next();
        remaining.remove(current);
        SDDocument currentDoc = resolver.resolve(current);
        SDDocument old = closureDocs.put(currentDoc.getURL().toExternalForm(), currentDoc);
        assert old == null;
        Set<String> imports = currentDoc.getImports();
        if (!currentDoc.isSchema() || !onlyTopLevelSchemas) {
            for (String importedDoc : imports) {
                if (closureDocs.get(importedDoc) == null) {
                    remaining.add(importedDoc);
                }
            }
        }
    }
    return closureDocs;
}
Also used : SDDocument(com.sun.xml.ws.api.server.SDDocument)

Aggregations

SDDocument (com.sun.xml.ws.api.server.SDDocument)7 DocumentAddressResolver (com.sun.xml.ws.api.server.DocumentAddressResolver)3 PortAddressResolver (com.sun.xml.ws.api.server.PortAddressResolver)3 SDDocumentSource (com.sun.xml.ws.api.server.SDDocumentSource)2 WSEndpoint (com.sun.xml.ws.api.server.WSEndpoint)2 ByteArrayBuffer (com.sun.xml.ws.util.ByteArrayBuffer)2 IOException (java.io.IOException)2 Source (javax.xml.transform.Source)2 DOMSource (javax.xml.transform.dom.DOMSource)2 StreamSource (javax.xml.transform.stream.StreamSource)2 Document (org.w3c.dom.Document)2 Component (com.sun.xml.ws.api.Component)1 Packet (com.sun.xml.ws.api.message.Packet)1 BoundEndpoint (com.sun.xml.ws.api.server.BoundEndpoint)1 ServiceDefinition (com.sun.xml.ws.api.server.ServiceDefinition)1 WebModule (com.sun.xml.ws.api.server.WebModule)1 DeploymentDescriptorParser (com.sun.xml.ws.transport.http.DeploymentDescriptorParser)1 HttpAdapter (com.sun.xml.ws.transport.http.HttpAdapter)1 HttpAdapterList (com.sun.xml.ws.transport.http.HttpAdapterList)1 WSHTTPConnection (com.sun.xml.ws.transport.http.WSHTTPConnection)1