Search in sources :

Example 1 with TidyXMLStreamReader

use of com.sun.xml.ws.streaming.TidyXMLStreamReader in project metro-jax-ws by eclipse-ee4j.

the class SDDocumentSource method create.

/**
 * Creates {@link SDDocumentSource} from resource path using resolvingClass to read the resource.
 * Required for Jigsaw runtime.
 *
 * @param resolvingClass class used to read resource
 * @param path resource path
 */
private static SDDocumentSource create(final String path, final Class<?> resolvingClass) {
    return new SDDocumentSource() {

        @Override
        public XMLStreamReader read(XMLInputFactory xif) throws IOException, XMLStreamException {
            InputStream is = inputStream();
            return new TidyXMLStreamReader(xif.createXMLStreamReader(path, is), is);
        }

        @Override
        public XMLStreamReader read() throws IOException, XMLStreamException {
            InputStream is = inputStream();
            return new TidyXMLStreamReader(XMLStreamReaderFactory.create(path, is, false), is);
        }

        @Override
        public URL getSystemId() {
            try {
                return new URL("file://" + path);
            } catch (MalformedURLException e) {
                return null;
            }
        }

        private InputStream inputStream() throws IOException {
            java.lang.Module module = resolvingClass.getModule();
            InputStream stream = module.getResourceAsStream(path);
            if (stream != null) {
                return stream;
            }
            throw new ServerRtException("cannot.load.wsdl", path);
        }
    };
}
Also used : MalformedURLException(java.net.MalformedURLException) TidyXMLStreamReader(com.sun.xml.ws.streaming.TidyXMLStreamReader) InputStream(java.io.InputStream) ServerRtException(com.sun.xml.ws.server.ServerRtException) XMLInputFactory(javax.xml.stream.XMLInputFactory) URL(java.net.URL)

Example 2 with TidyXMLStreamReader

use of com.sun.xml.ws.streaming.TidyXMLStreamReader in project metro-jax-ws by eclipse-ee4j.

the class StreamDecoderImpl method decode.

@Override
public Message decode(InputStream in, String charset, AttachmentSet att, SOAPVersion soapVersion) throws IOException {
    XMLStreamReader reader = XMLStreamReaderFactory.create(null, in, charset, true);
    reader = new TidyXMLStreamReader(reader, in);
    return StreamSOAPCodec.decode(soapVersion, reader, att);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) TidyXMLStreamReader(com.sun.xml.ws.streaming.TidyXMLStreamReader) TidyXMLStreamReader(com.sun.xml.ws.streaming.TidyXMLStreamReader)

Example 3 with TidyXMLStreamReader

use of com.sun.xml.ws.streaming.TidyXMLStreamReader in project metro-jax-ws by eclipse-ee4j.

the class DeploymentDescriptorParser method parse.

/**
 * Parses the {@code sun-jaxws.xml} file and configures
 * a set of {@link HttpAdapter}s.
 */
@NotNull
public List<A> parse(String systemId, InputStream is) {
    XMLStreamReader reader = null;
    try {
        reader = new TidyXMLStreamReader(XMLStreamReaderFactory.create(systemId, is, true), is);
        XMLStreamReaderUtil.nextElementContent(reader);
        return parseAdapters(reader);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (XMLStreamException e) {
                throw new ServerRtException("runtime.parser.xmlReader", e);
            }
        }
        try {
            is.close();
        } catch (IOException e) {
        // ignore
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) TidyXMLStreamReader(com.sun.xml.ws.streaming.TidyXMLStreamReader) TidyXMLStreamReader(com.sun.xml.ws.streaming.TidyXMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ServerRtException(com.sun.xml.ws.server.ServerRtException) NotNull(com.sun.istack.NotNull)

Example 4 with TidyXMLStreamReader

use of com.sun.xml.ws.streaming.TidyXMLStreamReader 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)

Example 5 with TidyXMLStreamReader

use of com.sun.xml.ws.streaming.TidyXMLStreamReader in project metro-jax-ws by eclipse-ee4j.

the class EntityResolverWrapper method resolveEntity.

public Parser resolveEntity(String publicId, String systemId) throws SAXException, IOException {
    InputSource source = core.resolveEntity(publicId, systemId);
    if (source == null)
        // default
        return null;
    // but if none is given, the system ID before the entity resolution is better than nothing.
    if (source.getSystemId() != null)
        systemId = source.getSystemId();
    URL url = new URL(systemId);
    InputStream stream;
    if (useStreamFromEntityResolver) {
        stream = source.getByteStream();
    } else {
        stream = url.openStream();
    }
    return new Parser(url, new TidyXMLStreamReader(XMLStreamReaderFactory.create(url.toExternalForm(), stream, true), stream));
}
Also used : InputSource(org.xml.sax.InputSource) TidyXMLStreamReader(com.sun.xml.ws.streaming.TidyXMLStreamReader) InputStream(java.io.InputStream) URL(java.net.URL)

Aggregations

TidyXMLStreamReader (com.sun.xml.ws.streaming.TidyXMLStreamReader)5 InputStream (java.io.InputStream)3 URL (java.net.URL)3 ServerRtException (com.sun.xml.ws.server.ServerRtException)2 IOException (java.io.IOException)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 NotNull (com.sun.istack.NotNull)1 WSDLLocator (com.sun.xml.ws.api.WSDLLocator)1 FilterInputStream (java.io.FilterInputStream)1 MalformedURLException (java.net.MalformedURLException)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 InputSource (org.xml.sax.InputSource)1