com.sun.xml.internal.ws.util.xml.XmlUtil Java Examples

The following examples show how to use com.sun.xml.internal.ws.util.xml.XmlUtil. 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: AbstractSchemaValidationTube.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private Document createDOM(SDDocument doc) {
    // Get infoset
    ByteArrayBuffer bab = new ByteArrayBuffer();
    try {
        doc.writeTo(null, resolver, bab);
    } catch (IOException ioe) {
        throw new WebServiceException(ioe);
    }

    // Convert infoset to DOM
    Transformer trans = XmlUtil.newTransformer();
    Source source = new StreamSource(bab.newInputStream(), null); //doc.getURL().toExternalForm());
    DOMResult result = new DOMResult();
    try {
        trans.transform(source, result);
    } catch(TransformerException te) {
        throw new WebServiceException(te);
    }
    return (Document)result.getNode();
}
 
Example #2
Source File: AbstractSchemaValidationTube.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private Document createDOM(SDDocument doc) {
    // Get infoset
    ByteArrayBuffer bab = new ByteArrayBuffer();
    try {
        doc.writeTo(null, resolver, bab);
    } catch (IOException ioe) {
        throw new WebServiceException(ioe);
    }

    // Convert infoset to DOM
    Transformer trans = XmlUtil.newTransformer();
    Source source = new StreamSource(bab.newInputStream(), null); //doc.getURL().toExternalForm());
    DOMResult result = new DOMResult();
    try {
        trans.transform(source, result);
    } catch(TransformerException te) {
        throw new WebServiceException(te);
    }
    return (Document)result.getNode();
}
 
Example #3
Source File: MexEntityResolver.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public MexEntityResolver(List<? extends Source> wsdls) throws IOException {
    Transformer transformer = XmlUtil.newTransformer();
    for (Source source : wsdls) {
        XMLStreamBufferResult xsbr = new XMLStreamBufferResult();
        try {
            transformer.transform(source, xsbr);
        } catch (TransformerException e) {
            throw new WebServiceException(e);
        }
        String systemId = source.getSystemId();

        //TODO: can we do anything if the given mex Source has no systemId?
        if(systemId != null){
            SDDocumentSource doc = SDDocumentSource.create(JAXWSUtils.getFileOrURL(systemId), xsbr.getXMLStreamBuffer());
            this.wsdls.put(systemId, doc);
        }
    }
}
 
Example #4
Source File: RuntimeWSDLParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns true if body has explicit parts declaration
 */
private static boolean parseSOAPBodyBinding(XMLStreamReader reader, Map<String, ParameterBinding> parts) {
    String partsString = reader.getAttributeValue(null, "parts");
    if (partsString != null) {
        List<String> partsList = XmlUtil.parseTokenList(partsString);
        if (partsList.isEmpty()) {
            parts.put(" ", ParameterBinding.BODY);
        } else {
            for (String part : partsList) {
                parts.put(part, ParameterBinding.BODY);
            }
        }
        return true;
    }
    return false;
}
 
Example #5
Source File: MexEntityResolver.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public MexEntityResolver(List<? extends Source> wsdls) throws IOException {
    Transformer transformer = XmlUtil.newTransformer();
    for (Source source : wsdls) {
        XMLStreamBufferResult xsbr = new XMLStreamBufferResult();
        try {
            transformer.transform(source, xsbr);
        } catch (TransformerException e) {
            throw new WebServiceException(e);
        }
        String systemId = source.getSystemId();

        //TODO: can we do anything if the given mex Source has no systemId?
        if(systemId != null){
            SDDocumentSource doc = SDDocumentSource.create(JAXWSUtils.getFileOrURL(systemId), xsbr.getXMLStreamBuffer());
            this.wsdls.put(systemId, doc);
        }
    }
}
 
Example #6
Source File: PolicyWSDLParserExtension.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private boolean readExternalFile(final String fileUrl) {
    InputStream ios = null;
    XMLStreamReader reader = null;
    try {
        final URL xmlURL = new URL(fileUrl);
        ios = xmlURL.openStream();
        reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(ios);
        while (reader.hasNext()) {
            if (reader.isStartElement() && NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {
                readSinglePolicy(policyReader.readPolicyElement(reader, fileUrl), false);
            }
            reader.next();
        }
        return true;
    } catch (IOException ioe) {
        return false;
    } catch (XMLStreamException xmlse) {
        return false;
    } finally {
        PolicyUtils.IO.closeResource(reader);
        PolicyUtils.IO.closeResource(ios);
    }
}
 
Example #7
Source File: TWSDLParserContextImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void registerNamespaces(Element e) {
    for (Iterator iter = XmlUtil.getAllAttributes(e); iter.hasNext();) {
        Attr a = (Attr) iter.next();
        if (a.getName().equals(PREFIX_XMLNS)) {
            // default namespace declaration
            _nsSupport.declarePrefix("", a.getValue());
        } else {
            String prefix = XmlUtil.getPrefix(a.getName());
            if (prefix != null && prefix.equals(PREFIX_XMLNS)) {
                String nsPrefix = XmlUtil.getLocalPart(a.getName());
                String uri = a.getValue();
                _nsSupport.declarePrefix(nsPrefix, uri);
            }
        }
    }
}
 
Example #8
Source File: TWSDLParserContextImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public QName translateQualifiedName(Locator locator, String s) {
    if (s == null)
        return null;

    String prefix = XmlUtil.getPrefix(s);
    String uri = null;

    if (prefix == null) {
        uri = getDefaultNamespaceURI();
    } else {
        uri = getNamespaceURI(prefix);
        if (uri == null) {
            errorReceiver.error(locator, WsdlMessages.PARSING_UNKNOWN_NAMESPACE_PREFIX(prefix));
        }
    }

    return new QName(uri, XmlUtil.getLocalPart(s));
}
 
Example #9
Source File: AbstractSchemaValidationTube.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private Document createDOM(SDDocument doc) {
    // Get infoset
    ByteArrayBuffer bab = new ByteArrayBuffer();
    try {
        doc.writeTo(null, resolver, bab);
    } catch (IOException ioe) {
        throw new WebServiceException(ioe);
    }

    // Convert infoset to DOM
    Transformer trans = XmlUtil.newTransformer();
    Source source = new StreamSource(bab.newInputStream(), null); //doc.getURL().toExternalForm());
    DOMResult result = new DOMResult();
    try {
        trans.transform(source, result);
    } catch(TransformerException te) {
        throw new WebServiceException(te);
    }
    return (Document)result.getNode();
}
 
Example #10
Source File: StreamHeader.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void writeTo(SOAPMessage saaj) throws SOAPException {
    try {
        // TODO what about in-scope namespaces
        // Not very efficient consider implementing a stream buffer
        // processor that produces a DOM node from the buffer.
        TransformerFactory tf = XmlUtil.newTransformerFactory();
        Transformer t = tf.newTransformer();
        XMLStreamBufferSource source = new XMLStreamBufferSource(_mark);
        DOMResult result = new DOMResult();
        t.transform(source, result);
        Node d = result.getNode();
        if(d.getNodeType() == Node.DOCUMENT_NODE)
            d = d.getFirstChild();
        SOAPHeader header = saaj.getSOAPHeader();
        if(header == null)
            header = saaj.getSOAPPart().getEnvelope().addHeader();
        Node node = header.getOwnerDocument().importNode(d, true);
        header.appendChild(node);
    } catch (Exception e) {
        throw new SOAPException(e);
    }
}
 
Example #11
Source File: TWSDLParserContextImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public QName translateQualifiedName(Locator locator, String s) {
    if (s == null)
        return null;

    String prefix = XmlUtil.getPrefix(s);
    String uri = null;

    if (prefix == null) {
        uri = getDefaultNamespaceURI();
    } else {
        uri = getNamespaceURI(prefix);
        if (uri == null) {
            errorReceiver.error(locator, WsdlMessages.PARSING_UNKNOWN_NAMESPACE_PREFIX(prefix));
        }
    }

    return new QName(uri, XmlUtil.getLocalPart(s));
}
 
Example #12
Source File: EPRHeader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void writeTo(SOAPMessage saaj) throws SOAPException {
        try {
            // TODO what about in-scope namespaces
            // Not very efficient consider implementing a stream buffer
            // processor that produces a DOM node from the buffer.
            Transformer t = XmlUtil.newTransformer();
            SOAPHeader header = saaj.getSOAPHeader();
            if (header == null)
                header = saaj.getSOAPPart().getEnvelope().addHeader();
// TODO workaround for oracle xdk bug 16555545, when this bug is fixed the line below can be
// uncommented and all lines below, except the catch block, can be removed.
//            t.transform(epr.asSource(localName), new DOMResult(header));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XMLStreamWriter w = XMLOutputFactory.newFactory().createXMLStreamWriter(baos);
            epr.writeTo(localName, w);
            w.flush();
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
            fac.setNamespaceAware(true);
            Node eprNode = fac.newDocumentBuilder().parse(bais).getDocumentElement();
            Node eprNodeToAdd = header.getOwnerDocument().importNode(eprNode, true);
            header.appendChild(eprNodeToAdd);
        } catch (Exception e) {
            throw new SOAPException(e);
        }
    }
 
Example #13
Source File: TWSDLParserContextImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public QName translateQualifiedName(Locator locator, String s) {
    if (s == null)
        return null;

    String prefix = XmlUtil.getPrefix(s);
    String uri = null;

    if (prefix == null) {
        uri = getDefaultNamespaceURI();
    } else {
        uri = getNamespaceURI(prefix);
        if (uri == null) {
            errorReceiver.error(locator, WsdlMessages.PARSING_UNKNOWN_NAMESPACE_PREFIX(prefix));
        }
    }

    return new QName(uri, XmlUtil.getLocalPart(s));
}
 
Example #14
Source File: MexEntityResolver.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public MexEntityResolver(List<? extends Source> wsdls) throws IOException {
    Transformer transformer = XmlUtil.newTransformer();
    for (Source source : wsdls) {
        XMLStreamBufferResult xsbr = new XMLStreamBufferResult();
        try {
            transformer.transform(source, xsbr);
        } catch (TransformerException e) {
            throw new WebServiceException(e);
        }
        String systemId = source.getSystemId();

        //TODO: can we do anything if the given mex Source has no systemId?
        if(systemId != null){
            SDDocumentSource doc = SDDocumentSource.create(JAXWSUtils.getFileOrURL(systemId), xsbr.getXMLStreamBuffer());
            this.wsdls.put(systemId, doc);
        }
    }
}
 
Example #15
Source File: TWSDLParserContextImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void registerNamespaces(Element e) {
    for (Iterator iter = XmlUtil.getAllAttributes(e); iter.hasNext();) {
        Attr a = (Attr) iter.next();
        if (a.getName().equals(PREFIX_XMLNS)) {
            // default namespace declaration
            _nsSupport.declarePrefix("", a.getValue());
        } else {
            String prefix = XmlUtil.getPrefix(a.getName());
            if (prefix != null && prefix.equals(PREFIX_XMLNS)) {
                String nsPrefix = XmlUtil.getLocalPart(a.getName());
                String uri = a.getValue();
                _nsSupport.declarePrefix(nsPrefix, uri);
            }
        }
    }
}
 
Example #16
Source File: TWSDLParserContextImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public QName translateQualifiedName(Locator locator, String s) {
    if (s == null)
        return null;

    String prefix = XmlUtil.getPrefix(s);
    String uri = null;

    if (prefix == null) {
        uri = getDefaultNamespaceURI();
    } else {
        uri = getNamespaceURI(prefix);
        if (uri == null) {
            errorReceiver.error(locator, WsdlMessages.PARSING_UNKNOWN_NAMESPACE_PREFIX(prefix));
        }
    }

    return new QName(uri, XmlUtil.getLocalPart(s));
}
 
Example #17
Source File: WSEndpoint.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The same as
 * {@link #create(Class, boolean, Invoker, QName, QName, Container, WSBinding, SDDocumentSource, Collection, EntityResolver)}
 * except that this version takes an url of the <tt>jax-ws-catalog.xml</tt>.
 *
 * @param catalogUrl
 *      if not null, an {@link EntityResolver} is created from it and used.
 *      otherwise no resolution will be performed.
 */
public static <T> WSEndpoint<T> create(
    @NotNull Class<T> implType,
    boolean processHandlerAnnotation,
    @Nullable Invoker invoker,
    @Nullable QName serviceName,
    @Nullable QName portName,
    @Nullable Container container,
    @Nullable WSBinding binding,
    @Nullable SDDocumentSource primaryWsdl,
    @Nullable Collection<? extends SDDocumentSource> metadata,
    @Nullable URL catalogUrl) {
    return create(
        implType,processHandlerAnnotation,invoker,serviceName,portName,container,binding,primaryWsdl,metadata,
        XmlUtil.createEntityResolver(catalogUrl),false);
}
 
Example #18
Source File: StreamHeader.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void writeTo(SOAPMessage saaj) throws SOAPException {
    try {
        // TODO what about in-scope namespaces
        // Not very efficient consider implementing a stream buffer
        // processor that produces a DOM node from the buffer.
        TransformerFactory tf = XmlUtil.newTransformerFactory();
        Transformer t = tf.newTransformer();
        XMLStreamBufferSource source = new XMLStreamBufferSource(_mark);
        DOMResult result = new DOMResult();
        t.transform(source, result);
        Node d = result.getNode();
        if(d.getNodeType() == Node.DOCUMENT_NODE)
            d = d.getFirstChild();
        SOAPHeader header = saaj.getSOAPHeader();
        if(header == null)
            header = saaj.getSOAPPart().getEnvelope().addHeader();
        Node node = header.getOwnerDocument().importNode(d, true);
        header.appendChild(node);
    } catch (Exception e) {
        throw new SOAPException(e);
    }
}
 
Example #19
Source File: EndpointImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convert metadata sources using identity transform. So that we can
 * reuse the Source object multiple times.
 */
private List<SDDocumentSource> buildDocList() {
    List<SDDocumentSource> r = new ArrayList<>();

    if (metadata != null) {
        for (Source source : metadata) {
            try {
                XMLStreamBufferResult xsbr = XmlUtil.identityTransform(source, new XMLStreamBufferResult());
                String systemId = source.getSystemId();

                r.add(SDDocumentSource.create(new URL(systemId), xsbr.getXMLStreamBuffer()));
            } catch (TransformerException | IOException | SAXException | ParserConfigurationException te) {
                throw new ServerRtException("server.rt.err", te);
            }
        }
    }

    return r;
}
 
Example #20
Source File: WSEndpoint.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The same as
 * {@link #create(Class, boolean, Invoker, QName, QName, Container, WSBinding, SDDocumentSource, Collection, EntityResolver)}
 * except that this version takes an url of the <tt>jax-ws-catalog.xml</tt>.
 *
 * @param catalogUrl
 *      if not null, an {@link EntityResolver} is created from it and used.
 *      otherwise no resolution will be performed.
 */
public static <T> WSEndpoint<T> create(
    @NotNull Class<T> implType,
    boolean processHandlerAnnotation,
    @Nullable Invoker invoker,
    @Nullable QName serviceName,
    @Nullable QName portName,
    @Nullable Container container,
    @Nullable WSBinding binding,
    @Nullable SDDocumentSource primaryWsdl,
    @Nullable Collection<? extends SDDocumentSource> metadata,
    @Nullable URL catalogUrl) {
    return create(
        implType,processHandlerAnnotation,invoker,serviceName,portName,container,binding,primaryWsdl,metadata,
        XmlUtil.createEntityResolver(catalogUrl),false);
}
 
Example #21
Source File: WSEndpointReference.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private QName getElementTextAsQName(StreamReaderBufferProcessor xsr) throws XMLStreamException {
    String text = xsr.getElementText().trim();
    String prefix = XmlUtil.getPrefix(text);
    String name = XmlUtil.getLocalPart(text);
    if (name != null) {
        if (prefix != null) {
            String ns = xsr.getNamespaceURI(prefix);
            if (ns != null) {
                return new QName(ns, name, prefix);
            }
        } else {
            return new QName(null, name);
        }
    }
    return null;
}
 
Example #22
Source File: WSEndpoint.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The same as
 * {@link #create(Class, boolean, Invoker, QName, QName, Container, WSBinding, SDDocumentSource, Collection, EntityResolver)}
 * except that this version takes an url of the <tt>jax-ws-catalog.xml</tt>.
 *
 * @param catalogUrl
 *      if not null, an {@link EntityResolver} is created from it and used.
 *      otherwise no resolution will be performed.
 */
public static <T> WSEndpoint<T> create(
    @NotNull Class<T> implType,
    boolean processHandlerAnnotation,
    @Nullable Invoker invoker,
    @Nullable QName serviceName,
    @Nullable QName portName,
    @Nullable Container container,
    @Nullable WSBinding binding,
    @Nullable SDDocumentSource primaryWsdl,
    @Nullable Collection<? extends SDDocumentSource> metadata,
    @Nullable URL catalogUrl) {
    return create(
        implType,processHandlerAnnotation,invoker,serviceName,portName,container,binding,primaryWsdl,metadata,
        XmlUtil.createEntityResolver(catalogUrl),false);
}
 
Example #23
Source File: WSEndpoint.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The same as
 * {@link #create(Class, boolean, Invoker, QName, QName, Container, WSBinding, SDDocumentSource, Collection, EntityResolver)}
 * except that this version takes an url of the <tt>jax-ws-catalog.xml</tt>.
 *
 * @param catalogUrl
 *      if not null, an {@link EntityResolver} is created from it and used.
 *      otherwise no resolution will be performed.
 */
public static <T> WSEndpoint<T> create(
    @NotNull Class<T> implType,
    boolean processHandlerAnnotation,
    @Nullable Invoker invoker,
    @Nullable QName serviceName,
    @Nullable QName portName,
    @Nullable Container container,
    @Nullable WSBinding binding,
    @Nullable SDDocumentSource primaryWsdl,
    @Nullable Collection<? extends SDDocumentSource> metadata,
    @Nullable URL catalogUrl) {
    return create(
        implType,processHandlerAnnotation,invoker,serviceName,portName,container,binding,primaryWsdl,metadata,
        XmlUtil.createEntityResolver(catalogUrl),false);
}
 
Example #24
Source File: PolicyWSDLParserExtension.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private boolean readExternalFile(final String fileUrl) {
    InputStream ios = null;
    XMLStreamReader reader = null;
    try {
        final URL xmlURL = new URL(fileUrl);
        ios = xmlURL.openStream();
        reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(ios);
        while (reader.hasNext()) {
            if (reader.isStartElement() && NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {
                readSinglePolicy(policyReader.readPolicyElement(reader, fileUrl), false);
            }
            reader.next();
        }
        return true;
    } catch (IOException ioe) {
        return false;
    } catch (XMLStreamException xmlse) {
        return false;
    } finally {
        PolicyUtils.IO.closeResource(reader);
        PolicyUtils.IO.closeResource(ios);
    }
}
 
Example #25
Source File: WSEndpointReference.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private QName getElementTextAsQName(StreamReaderBufferProcessor xsr) throws XMLStreamException {
    String text = xsr.getElementText().trim();
    String prefix = XmlUtil.getPrefix(text);
    String name = XmlUtil.getLocalPart(text);
    if (name != null) {
        if (prefix != null) {
            String ns = xsr.getNamespaceURI(prefix);
            if (ns != null) {
                return new QName(ns, name, prefix);
            }
        } else {
            return new QName(null, name);
        }
    }
    return null;
}
 
Example #26
Source File: EPRHeader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void writeTo(SOAPMessage saaj) throws SOAPException {
        try {
            // TODO what about in-scope namespaces
            // Not very efficient consider implementing a stream buffer
            // processor that produces a DOM node from the buffer.
            Transformer t = XmlUtil.newTransformer();
            SOAPHeader header = saaj.getSOAPHeader();
            if (header == null)
                header = saaj.getSOAPPart().getEnvelope().addHeader();
// TODO workaround for oracle xdk bug 16555545, when this bug is fixed the line below can be
// uncommented and all lines below, except the catch block, can be removed.
//            t.transform(epr.asSource(localName), new DOMResult(header));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XMLStreamWriter w = XMLOutputFactory.newFactory().createXMLStreamWriter(baos);
            epr.writeTo(localName, w);
            w.flush();
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
            fac.setNamespaceAware(true);
            Node eprNode = fac.newDocumentBuilder().parse(bais).getDocumentElement();
            Node eprNodeToAdd = header.getOwnerDocument().importNode(eprNode, true);
            header.appendChild(eprNodeToAdd);
        } catch (Exception e) {
            throw new SOAPException(e);
        }
    }
 
Example #27
Source File: MexEntityResolver.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public MexEntityResolver(List<? extends Source> wsdls) throws IOException {
    Transformer transformer = XmlUtil.newTransformer();
    for (Source source : wsdls) {
        XMLStreamBufferResult xsbr = new XMLStreamBufferResult();
        try {
            transformer.transform(source, xsbr);
        } catch (TransformerException e) {
            throw new WebServiceException(e);
        }
        String systemId = source.getSystemId();

        //TODO: can we do anything if the given mex Source has no systemId?
        if(systemId != null){
            SDDocumentSource doc = SDDocumentSource.create(JAXWSUtils.getFileOrURL(systemId), xsbr.getXMLStreamBuffer());
            this.wsdls.put(systemId, doc);
        }
    }
}
 
Example #28
Source File: RuntimeWSDLParser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns true if body has explicit parts declaration
 */
private static boolean parseSOAPBodyBinding(XMLStreamReader reader, Map<String, ParameterBinding> parts) {
    String partsString = reader.getAttributeValue(null, "parts");
    if (partsString != null) {
        List<String> partsList = XmlUtil.parseTokenList(partsString);
        if (partsList.isEmpty()) {
            parts.put(" ", ParameterBinding.BODY);
        } else {
            for (String part : partsList) {
                parts.put(part, ParameterBinding.BODY);
            }
        }
        return true;
    }
    return false;
}
 
Example #29
Source File: StreamHeader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void writeTo(SOAPMessage saaj) throws SOAPException {
    try {
        // TODO what about in-scope namespaces
        // Not very efficient consider implementing a stream buffer
        // processor that produces a DOM node from the buffer.
        TransformerFactory tf = XmlUtil.newTransformerFactory();
        Transformer t = tf.newTransformer();
        XMLStreamBufferSource source = new XMLStreamBufferSource(_mark);
        DOMResult result = new DOMResult();
        t.transform(source, result);
        Node d = result.getNode();
        if(d.getNodeType() == Node.DOCUMENT_NODE)
            d = d.getFirstChild();
        SOAPHeader header = saaj.getSOAPHeader();
        if(header == null)
            header = saaj.getSOAPPart().getEnvelope().addHeader();
        Node node = header.getOwnerDocument().importNode(d, true);
        header.appendChild(node);
    } catch (Exception e) {
        throw new SOAPException(e);
    }
}
 
Example #30
Source File: PolicyWSDLParserExtension.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private boolean readExternalFile(final String fileUrl) {
    InputStream ios = null;
    XMLStreamReader reader = null;
    try {
        final URL xmlURL = new URL(fileUrl);
        ios = xmlURL.openStream();
        reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(ios);
        while (reader.hasNext()) {
            if (reader.isStartElement() && NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {
                readSinglePolicy(policyReader.readPolicyElement(reader, fileUrl), false);
            }
            reader.next();
        }
        return true;
    } catch (IOException ioe) {
        return false;
    } catch (XMLStreamException xmlse) {
        return false;
    } finally {
        PolicyUtils.IO.closeResource(reader);
        PolicyUtils.IO.closeResource(ios);
    }
}