Search in sources :

Example 1 with WSDLLocator

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

the class RuntimeWSDLParser method createReader.

/**
 * Make sure to return a "fresh" reader each time it is called because
 * more than one active reader may be needed within a single thread
 * to parse a WSDL file.
 */
private static XMLStreamReader createReader(URL wsdlLoc, Class<Service> serviceClass) throws IOException, XMLStreamException {
    InputStream stream;
    try {
        stream = wsdlLoc.openStream();
    } catch (IOException io) {
        out: do {
            if (serviceClass != null) {
                WSDLLocator locator = ContainerResolver.getInstance().getContainer().getSPI(WSDLLocator.class);
                if (locator != null) {
                    String exForm = wsdlLoc.toExternalForm();
                    URL ru = serviceClass.getResource(".");
                    String loc = wsdlLoc.getPath();
                    if (ru != null) {
                        String ruExForm = ru.toExternalForm();
                        if (exForm.startsWith(ruExForm)) {
                            loc = exForm.substring(ruExForm.length());
                        }
                    }
                    wsdlLoc = locator.locateWSDL(serviceClass, loc);
                    if (wsdlLoc != null) {
                        stream = new FilterInputStream(wsdlLoc.openStream()) {

                            boolean closed;

                            @Override
                            public void close() throws IOException {
                                if (!closed) {
                                    closed = true;
                                    byte[] buf = new byte[8192];
                                    while (read(buf) != -1) ;
                                    super.close();
                                }
                            }
                        };
                        break out;
                    }
                }
            }
            throw io;
        } while (true);
    }
    return new TidyXMLStreamReader(XMLStreamReaderFactory.create(wsdlLoc.toExternalForm(), stream, false), stream);
}
Also used : WSDLLocator(com.sun.xml.ws.api.WSDLLocator) FilterInputStream(java.io.FilterInputStream) TidyXMLStreamReader(com.sun.xml.ws.streaming.TidyXMLStreamReader) FilterInputStream(java.io.FilterInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

WSDLLocator (com.sun.xml.ws.api.WSDLLocator)1 TidyXMLStreamReader (com.sun.xml.ws.streaming.TidyXMLStreamReader)1 FilterInputStream (java.io.FilterInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1