Java Code Examples for com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory#create()

The following examples show how to use com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityResolverWrapper.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public Parser resolveEntity(String publicId, String systemId) throws SAXException, IOException {
    InputSource source = core.resolveEntity(publicId,systemId);
    if(source==null)
        return null;    // default

    // ideally entity resolvers should be giving us the system ID for the resource
    // (or otherwise we won't be able to resolve references within this imported WSDL correctly),
    // 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));
}
 
Example 2
Source File: EntityResolverWrapper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public Parser resolveEntity(String publicId, String systemId) throws SAXException, IOException {
    InputSource source = core.resolveEntity(publicId,systemId);
    if(source==null)
        return null;    // default

    // ideally entity resolvers should be giving us the system ID for the resource
    // (or otherwise we won't be able to resolve references within this imported WSDL correctly),
    // 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));
}
 
Example 3
Source File: WsimportOptions.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Exposing it as a public method to allow external tools such as NB to read from wsdl model and work on it.
 * TODO: WSDL model needs to be exposed - basically at tool time we need to use the runtimw wsdl model
 *
 * Binding files could be jaxws or jaxb. This method identifies jaxws and jaxb binding files and keeps them separately. jaxb binding files are given separately
 * to JAXB in {@link com.sun.tools.internal.ws.processor.modeler.wsdl.JAXBModelBuilder}
 *
 * @param receiver {@link ErrorReceiver}
 */
public final void parseBindings(ErrorReceiver receiver){
    for (InputSource is : bindingFiles) {
        XMLStreamReader reader =
                XMLStreamReaderFactory.create(is,true);
        XMLStreamReaderUtil.nextElementContent(reader);
        if (reader.getName().equals(JAXWSBindingsConstants.JAXWS_BINDINGS)) {
            jaxwsCustomBindings.add(new RereadInputSource(is));
        } else if (reader.getName().equals(JAXWSBindingsConstants.JAXB_BINDINGS) ||
                reader.getName().equals(new QName(SchemaConstants.NS_XSD, "schema"))) {
            jaxbCustomBindings.add(new RereadInputSource(is));
        } else {
            LocatorImpl locator = new LocatorImpl();
            locator.setSystemId(reader.getLocation().getSystemId());
            locator.setPublicId(reader.getLocation().getPublicId());
            locator.setLineNumber(reader.getLocation().getLineNumber());
            locator.setColumnNumber(reader.getLocation().getColumnNumber());
            receiver.warning(locator, ConfigurationMessages.CONFIGURATION_NOT_BINDING_FILE(is.getSystemId()));
        }
    }
}
 
Example 4
Source File: EntityResolverWrapper.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public Parser resolveEntity(String publicId, String systemId) throws SAXException, IOException {
    InputSource source = core.resolveEntity(publicId,systemId);
    if(source==null)
        return null;    // default

    // ideally entity resolvers should be giving us the system ID for the resource
    // (or otherwise we won't be able to resolve references within this imported WSDL correctly),
    // 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));
}
 
Example 5
Source File: WsimportOptions.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Exposing it as a public method to allow external tools such as NB to read from wsdl model and work on it.
 * TODO: WSDL model needs to be exposed - basically at tool time we need to use the runtimw wsdl model
 *
 * Binding files could be jaxws or jaxb. This method identifies jaxws and jaxb binding files and keeps them separately. jaxb binding files are given separately
 * to JAXB in {@link com.sun.tools.internal.ws.processor.modeler.wsdl.JAXBModelBuilder}
 *
 * @param receiver {@link ErrorReceiver}
 */
public final void parseBindings(ErrorReceiver receiver){
    for (InputSource is : bindingFiles) {
        XMLStreamReader reader =
                XMLStreamReaderFactory.create(is,true);
        XMLStreamReaderUtil.nextElementContent(reader);
        if (reader.getName().equals(JAXWSBindingsConstants.JAXWS_BINDINGS)) {
            jaxwsCustomBindings.add(new RereadInputSource(is));
        } else if (reader.getName().equals(JAXWSBindingsConstants.JAXB_BINDINGS) ||
                reader.getName().equals(new QName(SchemaConstants.NS_XSD, "schema"))) {
            jaxbCustomBindings.add(new RereadInputSource(is));
        } else {
            LocatorImpl locator = new LocatorImpl();
            locator.setSystemId(reader.getLocation().getSystemId());
            locator.setPublicId(reader.getLocation().getPublicId());
            locator.setLineNumber(reader.getLocation().getLineNumber());
            locator.setColumnNumber(reader.getLocation().getColumnNumber());
            receiver.warning(locator, ConfigurationMessages.CONFIGURATION_NOT_BINDING_FILE(is.getSystemId()));
        }
    }
}
 
Example 6
Source File: WsimportOptions.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Exposing it as a public method to allow external tools such as NB to read from wsdl model and work on it.
 * TODO: WSDL model needs to be exposed - basically at tool time we need to use the runtimw wsdl model
 *
 * Binding files could be jaxws or jaxb. This method identifies jaxws and jaxb binding files and keeps them separately. jaxb binding files are given separately
 * to JAXB in {@link com.sun.tools.internal.ws.processor.modeler.wsdl.JAXBModelBuilder}
 *
 * @param receiver {@link ErrorReceiver}
 */
public final void parseBindings(ErrorReceiver receiver){
    for (InputSource is : bindingFiles) {
        XMLStreamReader reader =
                XMLStreamReaderFactory.create(is,true);
        XMLStreamReaderUtil.nextElementContent(reader);
        if (reader.getName().equals(JAXWSBindingsConstants.JAXWS_BINDINGS)) {
            jaxwsCustomBindings.add(new RereadInputSource(is));
        } else if (reader.getName().equals(JAXWSBindingsConstants.JAXB_BINDINGS) ||
                reader.getName().equals(new QName(SchemaConstants.NS_XSD, "schema"))) {
            jaxbCustomBindings.add(new RereadInputSource(is));
        } else {
            LocatorImpl locator = new LocatorImpl();
            locator.setSystemId(reader.getLocation().getSystemId());
            locator.setPublicId(reader.getLocation().getPublicId());
            locator.setLineNumber(reader.getLocation().getLineNumber());
            locator.setColumnNumber(reader.getLocation().getColumnNumber());
            receiver.warning(locator, ConfigurationMessages.CONFIGURATION_NOT_BINDING_FILE(is.getSystemId()));
        }
    }
}
 
Example 7
Source File: EndpointFactory.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public Parser resolveEntity (String publicId, String systemId) throws IOException, XMLStreamException {
    if (systemId != null) {
        SDDocumentSource doc = metadata.get(systemId);
        if (doc != null)
            return new Parser(doc);
    }
    if (resolver != null) {
        try {
            InputSource source = resolver.resolveEntity(publicId, systemId);
            if (source != null) {
                Parser p = new Parser(null, XMLStreamReaderFactory.create(source, true));
                return p;
            }
        } catch (SAXException e) {
            throw new XMLStreamException(e);
        }
    }
    return null;
}
 
Example 8
Source File: WsimportOptions.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Exposing it as a public method to allow external tools such as NB to read from wsdl model and work on it.
 * TODO: WSDL model needs to be exposed - basically at tool time we need to use the runtimw wsdl model
 *
 * Binding files could be jaxws or jaxb. This method identifies jaxws and jaxb binding files and keeps them separately. jaxb binding files are given separately
 * to JAXB in {@link com.sun.tools.internal.ws.processor.modeler.wsdl.JAXBModelBuilder}
 *
 * @param receiver {@link ErrorReceiver}
 */
public final void parseBindings(ErrorReceiver receiver){
    for (InputSource is : bindingFiles) {
        XMLStreamReader reader =
                XMLStreamReaderFactory.create(is,true);
        XMLStreamReaderUtil.nextElementContent(reader);
        if (reader.getName().equals(JAXWSBindingsConstants.JAXWS_BINDINGS)) {
            jaxwsCustomBindings.add(new RereadInputSource(is));
        } else if (reader.getName().equals(JAXWSBindingsConstants.JAXB_BINDINGS) ||
                reader.getName().equals(new QName(SchemaConstants.NS_XSD, "schema"))) {
            jaxbCustomBindings.add(new RereadInputSource(is));
        } else {
            LocatorImpl locator = new LocatorImpl();
            locator.setSystemId(reader.getLocation().getSystemId());
            locator.setPublicId(reader.getLocation().getPublicId());
            locator.setLineNumber(reader.getLocation().getLineNumber());
            locator.setColumnNumber(reader.getLocation().getColumnNumber());
            receiver.warning(locator, ConfigurationMessages.CONFIGURATION_NOT_BINDING_FILE(is.getSystemId()));
        }
    }
}
 
Example 9
Source File: EntityResolverWrapper.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public Parser resolveEntity(String publicId, String systemId) throws SAXException, IOException {
    InputSource source = core.resolveEntity(publicId,systemId);
    if(source==null)
        return null;    // default

    // ideally entity resolvers should be giving us the system ID for the resource
    // (or otherwise we won't be able to resolve references within this imported WSDL correctly),
    // 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));
}
 
Example 10
Source File: EntityResolverWrapper.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public Parser resolveEntity(String publicId, String systemId) throws SAXException, IOException {
    InputSource source = core.resolveEntity(publicId,systemId);
    if(source==null)
        return null;    // default

    // ideally entity resolvers should be giving us the system ID for the resource
    // (or otherwise we won't be able to resolve references within this imported WSDL correctly),
    // 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));
}
 
Example 11
Source File: EntityResolverWrapper.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public Parser resolveEntity(String publicId, String systemId) throws SAXException, IOException {
    InputSource source = core.resolveEntity(publicId,systemId);
    if(source==null)
        return null;    // default

    // ideally entity resolvers should be giving us the system ID for the resource
    // (or otherwise we won't be able to resolve references within this imported WSDL correctly),
    // 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));
}
 
Example 12
Source File: MtomCodec.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void decode(MimeMultipartParser mpp, Packet packet) throws IOException {
    //TODO shouldn't we check for SOAP1.1/SOAP1.2 and throw
    //TODO UnsupportedMediaException like StreamSOAPCodec
    String charset = null;
    String ct = mpp.getRootPart().getContentType();
    if (ct != null) {
        charset = new ContentTypeImpl(ct).getCharSet();
    }
    if (charset != null && !Charset.isSupported(charset)) {
        throw new UnsupportedMediaException(charset);
    }

    if (charset != null) {
        packet.invocationProperties.put(DECODED_MESSAGE_CHARSET, charset);
    } else {
        packet.invocationProperties.remove(DECODED_MESSAGE_CHARSET);
    }

    // we'd like to reuse those reader objects but unfortunately decoder may be reused
    // before the decoded message is completely used.
    XMLStreamReader mtomReader = new MtomXMLStreamReaderEx( mpp,
        XMLStreamReaderFactory.create(null, mpp.getRootPart().asInputStream(), charset, true)
    );

    packet.setMessage(codec.decode(mtomReader, new MimeAttachmentSet(mpp)));
    packet.setMtomFeature(mtomFeature);
    packet.setContentType(mpp.getContentType());
}
 
Example 13
Source File: MtomCodec.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void decode(MimeMultipartParser mpp, Packet packet) throws IOException {
    //TODO shouldn't we check for SOAP1.1/SOAP1.2 and throw
    //TODO UnsupportedMediaException like StreamSOAPCodec
    String charset = null;
    String ct = mpp.getRootPart().getContentType();
    if (ct != null) {
        charset = new ContentTypeImpl(ct).getCharSet();
    }
    if (charset != null && !Charset.isSupported(charset)) {
        throw new UnsupportedMediaException(charset);
    }

    if (charset != null) {
        packet.invocationProperties.put(DECODED_MESSAGE_CHARSET, charset);
    } else {
        packet.invocationProperties.remove(DECODED_MESSAGE_CHARSET);
    }

    // we'd like to reuse those reader objects but unfortunately decoder may be reused
    // before the decoded message is completely used.
    XMLStreamReader mtomReader = new MtomXMLStreamReaderEx( mpp,
        XMLStreamReaderFactory.create(null, mpp.getRootPart().asInputStream(), charset, true)
    );

    packet.setMessage(codec.decode(mtomReader, new MimeAttachmentSet(mpp)));
    packet.setMtomFeature(mtomFeature);
    packet.setContentType(mpp.getContentType());
}
 
Example 14
Source File: EndpointFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Parser resolveEntity (String publicId, String systemId) throws IOException, XMLStreamException {
    if (systemId != null) {
        SDDocumentSource doc = metadata.get(systemId);
        if (doc != null)
            return new Parser(doc);
        synchronized(this) {
            while(origMetadata.hasNext()) {
                doc = origMetadata.next();
                String extForm = doc.getSystemId().toExternalForm();
                this.metadata.put(extForm,doc);
                if (systemId.equals(extForm))
                    return new Parser(doc);
            }
        }
    }
    if (resolver != null) {
        try {
            InputSource source = resolver.resolveEntity(publicId, systemId);
            if (source != null) {
                Parser p = new Parser(null, XMLStreamReaderFactory.create(source, true));
                return p;
            }
        } catch (SAXException e) {
            throw new XMLStreamException(e);
        }
    }
    return null;
}
 
Example 15
Source File: SourceReaderFactory.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static XMLStreamReader createSourceReader(Source source, boolean rejectDTDs, String charsetName) {
    try {
        if (source instanceof StreamSource) {
            StreamSource streamSource = (StreamSource) source;
            InputStream is = streamSource.getInputStream();

            if (is != null) {
                // Wrap input stream in Reader if charset is specified
                if (charsetName != null) {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), new InputStreamReader(is, charsetName), rejectDTDs);
                }
                else {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), is, rejectDTDs);
                }
            }
            else {
                Reader reader = streamSource.getReader();
                if (reader != null) {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), reader, rejectDTDs);
                }
                else {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), new URL(source.getSystemId()).openStream(), rejectDTDs );
                }
            }
        }
        else if (source.getClass() == fastInfosetSourceClass) {
            return FastInfosetUtil.createFIStreamReader((InputStream)
                fastInfosetSource_getInputStream.invoke(source));
        }
        else if (source instanceof DOMSource) {
            DOMStreamReader dsr =  new DOMStreamReader();
            dsr.setCurrentNode(((DOMSource) source).getNode());
            return dsr;
        }
        else if (source instanceof SAXSource) {
            // TODO: need SAX to StAX adapter here -- Use transformer for now
            Transformer tx =  XmlUtil.newTransformer();
            DOMResult domResult = new DOMResult();
            tx.transform(source, domResult);
            return createSourceReader(
                new DOMSource(domResult.getNode()),
                rejectDTDs);
        }
        else {
            throw new XMLReaderException("sourceReader.invalidSource",
                    source.getClass().getName());
        }
    }
    catch (Exception e) {
        throw new XMLReaderException(e);
    }
}
 
Example 16
Source File: WSEndpointReference.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a {@link WSEndpointReference} by parsing an infoset.
 */
public WSEndpointReference(InputStream infoset, AddressingVersion version) throws XMLStreamException {
    this(XMLStreamReaderFactory.create(null,infoset,false),version);
}
 
Example 17
Source File: WSEndpointReference.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a {@link WSEndpointReference} by parsing an infoset.
 */
public WSEndpointReference(InputStream infoset, AddressingVersion version) throws XMLStreamException {
    this(XMLStreamReaderFactory.create(null,infoset,false),version);
}
 
Example 18
Source File: WSEndpointReference.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a {@link WSEndpointReference} by parsing an infoset.
 */
public WSEndpointReference(InputStream infoset, AddressingVersion version) throws XMLStreamException {
    this(XMLStreamReaderFactory.create(null,infoset,false),version);
}
 
Example 19
Source File: SourceReaderFactory.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static XMLStreamReader createSourceReader(Source source, boolean rejectDTDs, String charsetName) {
    try {
        if (source instanceof StreamSource) {
            StreamSource streamSource = (StreamSource) source;
            InputStream is = streamSource.getInputStream();

            if (is != null) {
                // Wrap input stream in Reader if charset is specified
                if (charsetName != null) {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), new InputStreamReader(is, charsetName), rejectDTDs);
                }
                else {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), is, rejectDTDs);
                }
            }
            else {
                Reader reader = streamSource.getReader();
                if (reader != null) {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), reader, rejectDTDs);
                }
                else {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), new URL(source.getSystemId()).openStream(), rejectDTDs );
                }
            }
        }
        else if (source.getClass() == fastInfosetSourceClass) {
            return FastInfosetUtil.createFIStreamReader((InputStream)
                fastInfosetSource_getInputStream.invoke(source));
        }
        else if (source instanceof DOMSource) {
            DOMStreamReader dsr =  new DOMStreamReader();
            dsr.setCurrentNode(((DOMSource) source).getNode());
            return dsr;
        }
        else if (source instanceof SAXSource) {
            // TODO: need SAX to StAX adapter here -- Use transformer for now
            Transformer tx =  XmlUtil.newTransformer();
            DOMResult domResult = new DOMResult();
            tx.transform(source, domResult);
            return createSourceReader(
                new DOMSource(domResult.getNode()),
                rejectDTDs);
        }
        else {
            throw new XMLReaderException("sourceReader.invalidSource",
                    source.getClass().getName());
        }
    }
    catch (Exception e) {
        throw new XMLReaderException(e);
    }
}
 
Example 20
Source File: WSEndpointReference.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a {@link WSEndpointReference} by parsing an infoset.
 */
public WSEndpointReference(InputStream infoset, AddressingVersion version) throws XMLStreamException {
    this(XMLStreamReaderFactory.create(null,infoset,false),version);
}