Search in sources :

Example 6 with PortAddressResolver

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

the class ServletConnectionImpl method getEPRAddress.

@Override
@NotNull
public String getEPRAddress(Packet p, WSEndpoint endpoint) {
    PortAddressResolver resolver = adapter.owner.createPortAddressResolver(getBaseAddress(), endpoint.getImplementationClass());
    String address = resolver.getAddressFor(endpoint.getServiceName(), endpoint.getPortName().getLocalPart());
    if (address == null)
        throw new WebServiceException(WsservletMessages.SERVLET_NO_ADDRESS_AVAILABLE(endpoint.getPortName()));
    return address;
}
Also used : PortAddressResolver(com.sun.xml.ws.api.server.PortAddressResolver) WebServiceException(jakarta.xml.ws.WebServiceException) NotNull(com.sun.istack.NotNull)

Example 7 with PortAddressResolver

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

the class WSDLGen method run.

public static int run() throws Exception {
    if (!useLocal()) {
        return 0;
    }
    String outputDir = System.getProperty("tempdir");
    if (outputDir == null) {
        System.err.println("**** Set tempdir system property ****");
        return -1;
    }
    String riFile = outputDir + "/WEB-INF/sun-jaxws.xml";
    DeploymentDescriptorParser<WSEndpoint> parser = new DeploymentDescriptorParser<WSEndpoint>(Thread.currentThread().getContextClassLoader(), new FileSystemResourceLoader(new File(outputDir)), null, new AdapterFactory<WSEndpoint>() {

        public WSEndpoint createAdapter(String name, String urlPattern, WSEndpoint<?> endpoint) {
            return endpoint;
        }
    });
    List<WSEndpoint> endpoints = parser.parse(new File(riFile));
    final String addr = new File(outputDir).toURL().toExternalForm();
    // file:// -> local://
    final String address = "local" + addr.substring(4);
    for (WSEndpoint endpoint : endpoints) {
        ServiceDefinition def = endpoint.getServiceDefinition();
        if (def == null) {
            continue;
        }
        SDDocument primary = def.getPrimary();
        File file = new File(primary.getURL().toURI());
        if (file.exists()) {
            System.out.println("**** Primary WSDL " + file + " already exists - not generating any WSDL artifacts ****");
            // Primary WSDL already exists
            continue;
        }
        for (SDDocument doc : def) {
            int index = doc.getURL().getFile().indexOf("/WEB-INF/wsdl");
            String name = "";
            if (index == -1)
                name = outputDir + "/WEB-INF/wsdl" + doc.getURL().getFile();
            else
                name = doc.getURL().getFile();
            System.out.println("Creating WSDL artifact=" + name);
            ByteArrayBuffer buffer = new ByteArrayBuffer();
            doc.writeTo(new PortAddressResolver() {

                public String getAddressFor(QName serviceName, String portName) {
                    return address;
                }
            }, new DocumentAddressResolver() {

                public String getRelativeAddressFor(SDDocument current, SDDocument referenced) {
                    String rel = referenced.getURL().toExternalForm();
                    // remove file:/
                    return rel.substring(6);
                }
            }, buffer);
            FileOutputStream fos = new FileOutputStream(name);
            buffer.writeTo(fos);
            fos.close();
        }
    }
    return 0;
}
Also used : PortAddressResolver(com.sun.xml.ws.api.server.PortAddressResolver) DeploymentDescriptorParser(com.sun.xml.ws.transport.http.DeploymentDescriptorParser) QName(javax.xml.namespace.QName) FileSystemResourceLoader(com.sun.xml.ws.transport.local.FileSystemResourceLoader) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) DocumentAddressResolver(com.sun.xml.ws.api.server.DocumentAddressResolver) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) FileOutputStream(java.io.FileOutputStream) SDDocument(com.sun.xml.ws.api.server.SDDocument) File(java.io.File) ServiceDefinition(com.sun.xml.ws.api.server.ServiceDefinition)

Example 8 with PortAddressResolver

use of com.sun.xml.ws.api.server.PortAddressResolver 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

PortAddressResolver (com.sun.xml.ws.api.server.PortAddressResolver)8 NotNull (com.sun.istack.NotNull)3 DocumentAddressResolver (com.sun.xml.ws.api.server.DocumentAddressResolver)3 SDDocument (com.sun.xml.ws.api.server.SDDocument)3 WebServiceException (jakarta.xml.ws.WebServiceException)3 WSEndpoint (com.sun.xml.ws.api.server.WSEndpoint)2 QName (javax.xml.namespace.QName)2 IndentingXMLStreamWriter (com.sun.xml.txw2.output.IndentingXMLStreamWriter)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 FileSystemResourceLoader (com.sun.xml.ws.transport.local.FileSystemResourceLoader)1 ByteArrayBuffer (com.sun.xml.ws.util.ByteArrayBuffer)1 DocumentLocationResolver (com.sun.xml.ws.wsdl.writer.DocumentLocationResolver)1 WSDLPatcher (com.sun.xml.ws.wsdl.writer.WSDLPatcher)1