Search in sources :

Example 1 with DocumentLocationResolver

use of com.sun.xml.ws.wsdl.writer.DocumentLocationResolver in project metro-jax-ws by eclipse-ee4j.

the class WSDLFetcher method createDocResolver.

private DocumentLocationResolver createDocResolver(final String baseWsdl, final DOMForest forest, final Map<String, String> documentMap) {
    return new DocumentLocationResolver() {

        @Override
        public String getLocationFor(String namespaceURI, String systemId) {
            try {
                URL reference = new URL(new URL(baseWsdl), systemId);
                systemId = reference.toExternalForm();
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
            if (documentMap.get(systemId) != null) {
                return documentMap.get(systemId);
            } else {
                String parsedEntity = forest.getReferencedEntityMap().get(systemId);
                return documentMap.get(parsedEntity);
            }
        }
    };
}
Also used : MalformedURLException(java.net.MalformedURLException) DocumentLocationResolver(com.sun.xml.ws.wsdl.writer.DocumentLocationResolver) URL(java.net.URL)

Example 2 with DocumentLocationResolver

use of com.sun.xml.ws.wsdl.writer.DocumentLocationResolver in project metro-jax-ws by eclipse-ee4j.

the class WSDLFetcher method fetchFile.

private String fetchFile(final String doc, DOMForest forest, final Map<String, String> documentMap, File destDir) throws IOException, XMLStreamException {
    DocumentLocationResolver docLocator = createDocResolver(doc, forest, documentMap);
    WSDLPatcher wsdlPatcher = new WSDLPatcher(new PortAddressResolver() {

        @Override
        public String getAddressFor(@NotNull QName serviceName, @NotNull String portName) {
            return null;
        }
    }, docLocator);
    XMLStreamReader xsr = null;
    XMLStreamWriter xsw = null;
    OutputStream os = null;
    String resolvedRootWsdl = null;
    try {
        XMLOutputFactory writerfactory;
        xsr = SourceReaderFactory.createSourceReader(new DOMSource(forest.get(doc)), false);
        writerfactory = XMLOutputFactory.newInstance();
        resolvedRootWsdl = docLocator.getLocationFor(null, doc);
        File outFile = new File(destDir, resolvedRootWsdl);
        os = new FileOutputStream(outFile);
        if (options.verbose) {
            listener.message(WscompileMessages.WSIMPORT_DOCUMENT_DOWNLOAD(doc, outFile));
        }
        xsw = writerfactory.createXMLStreamWriter(os);
        // DOMForest eats away the whitespace loosing all the indentation, so write it through
        // indenting writer for better readability of fetched documents
        IndentingXMLStreamWriter indentingWriter = new IndentingXMLStreamWriter(xsw);
        wsdlPatcher.bridge(xsr, indentingWriter);
        options.addGeneratedFile(outFile);
    } finally {
        try {
            if (xsr != null) {
                xsr.close();
            }
            if (xsw != null) {
                xsw.close();
            }
        } finally {
            if (os != null) {
                os.close();
            }
        }
    }
    return resolvedRootWsdl;
}
Also used : PortAddressResolver(com.sun.xml.ws.api.server.PortAddressResolver) IndentingXMLStreamWriter(com.sun.xml.txw2.output.IndentingXMLStreamWriter) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) DOMSource(javax.xml.transform.dom.DOMSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) WSDLPatcher(com.sun.xml.ws.wsdl.writer.WSDLPatcher) DocumentLocationResolver(com.sun.xml.ws.wsdl.writer.DocumentLocationResolver) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) IndentingXMLStreamWriter(com.sun.xml.txw2.output.IndentingXMLStreamWriter)

Aggregations

DocumentLocationResolver (com.sun.xml.ws.wsdl.writer.DocumentLocationResolver)2 IndentingXMLStreamWriter (com.sun.xml.txw2.output.IndentingXMLStreamWriter)1 PortAddressResolver (com.sun.xml.ws.api.server.PortAddressResolver)1 WSDLPatcher (com.sun.xml.ws.wsdl.writer.WSDLPatcher)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 QName (javax.xml.namespace.QName)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 DOMSource (javax.xml.transform.dom.DOMSource)1