Search in sources :

Example 6 with MutableXMLStreamBuffer

use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.

the class FaultDetailHeader method readHeader.

public XMLStreamReader readHeader() throws XMLStreamException {
    MutableXMLStreamBuffer buf = new MutableXMLStreamBuffer();
    XMLStreamWriter w = buf.createFromXMLStreamWriter();
    writeTo(w);
    return buf.readAsXMLStreamReader();
}
Also used : MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 7 with MutableXMLStreamBuffer

use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.

the class EndpointFactory method findMetadataClosure.

/**
 * Goes through the original metadata documents and collects the required ones.
 * This done traversing from primary WSDL and its imports until it builds a
 * complete set of documents(transitive closure) for the endpoint.
 *
 * @param primaryDoc primary WSDL doc
 * @param docList complete metadata
 * @return new metadata that doesn't contain extraneous documents.
 */
private static Collection<SDDocumentImpl> findMetadataClosure(final SDDocumentImpl primaryDoc, final Collection<SDDocumentImpl> docList, final EntityResolver resolver) {
    return new AbstractCollection<>() {

        @Override
        public Iterator<SDDocumentImpl> iterator() {
            // create a map for old metadata
            Map<String, SDDocumentImpl> oldMap = new HashMap<>();
            Iterator<SDDocumentImpl> oldDocs = docList.iterator();
            // create a map for new metadata
            Map<String, SDDocumentImpl> newMap = new HashMap<>();
            newMap.put(primaryDoc.getSystemId().toString(), primaryDoc);
            List<String> remaining = new ArrayList<String>(primaryDoc.getImports());
            while (!remaining.isEmpty()) {
                String url = remaining.remove(0);
                SDDocumentImpl doc = oldMap.get(url);
                if (doc == null) {
                    while (oldDocs.hasNext()) {
                        SDDocumentImpl old = oldDocs.next();
                        String id = old.getSystemId().toString();
                        oldMap.put(id, old);
                        if (id.equals(url)) {
                            doc = old;
                            break;
                        }
                    }
                    if (doc == null) {
                        // old metadata doesn't have this imported doc, may be external
                        if (resolver != null) {
                            try {
                                InputSource source = resolver.resolveEntity(null, url);
                                if (source != null) {
                                    MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
                                    XMLStreamReader reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(source.getByteStream());
                                    xsb.createFromXMLStreamReader(reader);
                                    SDDocumentSource sdocSource = SDDocumentImpl.create(new URL(url), xsb);
                                    doc = SDDocumentImpl.create(sdocSource, null, null);
                                }
                            } catch (Exception ex) {
                                ex.printStackTrace();
                            }
                        }
                    }
                }
                // Check if new metadata already contains this doc
                if (doc != null && !newMap.containsKey(url)) {
                    newMap.put(url, doc);
                    remaining.addAll(doc.getImports());
                }
            }
            return newMap.values().iterator();
        }

        @Override
        public int size() {
            int size = 0;
            Iterator<SDDocumentImpl> it = iterator();
            while (it.hasNext()) {
                it.next();
                size++;
            }
            return size;
        }

        @Override
        public void clear() {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean isEmpty() {
            return docList.isEmpty();
        }
    };
}
Also used : InputSource(org.xml.sax.InputSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AbstractCollection(java.util.AbstractCollection) ArrayList(java.util.ArrayList) URL(java.net.URL) XMLStreamException(javax.xml.stream.XMLStreamException) WebServiceException(jakarta.xml.ws.WebServiceException) SAXException(org.xml.sax.SAXException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) SDDocumentSource(com.sun.xml.ws.api.server.SDDocumentSource)

Example 8 with MutableXMLStreamBuffer

use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.

the class WSDLGenResolver method getWSDL.

/**
 * Generates the concrete WSDL that contains service element.
 *
 * @return Result the generated concrete WSDL
 */
public Result getWSDL(String filename) {
    URL url = createURL(filename);
    MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
    xsb.setSystemId(url.toExternalForm());
    concreteWsdlSource = SDDocumentSource.create(url, xsb);
    newDocs.add(concreteWsdlSource);
    XMLStreamBufferResult r = new XMLStreamBufferResult(xsb);
    r.setSystemId(filename);
    return r;
}
Also used : MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLStreamBufferResult(com.sun.xml.stream.buffer.XMLStreamBufferResult) URL(java.net.URL)

Example 9 with MutableXMLStreamBuffer

use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.

the class WSDLGenResolver method getSchemaOutput.

/**
 * Updates filename if the suggested filename need to be changed in
 * xsd:import. If there is already a schema document for the namespace
 * in the metadata, then it is not generated.
 *
 * return null if schema need not be generated
 *        Result the generated schema document
 */
public Result getSchemaOutput(String namespace, Holder<String> filename) {
    List<SDDocumentImpl> schemas = nsMapping.get(namespace);
    if (schemas != null) {
        if (schemas.size() > 1) {
            throw new ServerRtException("server.rt.err", "More than one schema for the target namespace " + namespace);
        }
        filename.value = schemas.get(0).getURL().toExternalForm();
        // Don't generate schema
        return null;
    }
    URL url = createURL(filename.value);
    MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
    xsb.setSystemId(url.toExternalForm());
    SDDocumentSource sd = SDDocumentSource.create(url, xsb);
    newDocs.add(sd);
    XMLStreamBufferResult r = new XMLStreamBufferResult(xsb);
    r.setSystemId(filename.value);
    return r;
}
Also used : MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) SDDocumentSource(com.sun.xml.ws.api.server.SDDocumentSource) XMLStreamBufferResult(com.sun.xml.stream.buffer.XMLStreamBufferResult) URL(java.net.URL)

Example 10 with MutableXMLStreamBuffer

use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.

the class JAXBMessage method readPayload.

@Override
public XMLStreamReader readPayload() throws XMLStreamException {
    try {
        if (infoset == null) {
            if (rawContext != null) {
                XMLStreamBufferResult sbr = new XMLStreamBufferResult();
                Marshaller m = rawContext.createMarshaller();
                m.setProperty("jaxb.fragment", Boolean.TRUE);
                m.marshal(jaxbObject, sbr);
                infoset = sbr.getXMLStreamBuffer();
            } else {
                MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
                writePayloadTo(buffer.createFromXMLStreamWriter());
                infoset = buffer;
            }
        }
        XMLStreamReader reader = infoset.readAsXMLStreamReader();
        if (reader.getEventType() == XMLStreamConstants.START_DOCUMENT)
            XMLStreamReaderUtil.nextElementContent(reader);
        return reader;
    } catch (JAXBException e) {
        // bug 6449684, spec 4.3.4
        throw new WebServiceException(e);
    }
}
Also used : Marshaller(jakarta.xml.bind.Marshaller) AttachmentMarshaller(jakarta.xml.bind.attachment.AttachmentMarshaller) MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLStreamReader(javax.xml.stream.XMLStreamReader) WebServiceException(jakarta.xml.ws.WebServiceException) JAXBException(jakarta.xml.bind.JAXBException) XMLStreamBufferResult(com.sun.xml.stream.buffer.XMLStreamBufferResult)

Aggregations

MutableXMLStreamBuffer (com.sun.xml.stream.buffer.MutableXMLStreamBuffer)17 WebServiceException (jakarta.xml.ws.WebServiceException)6 XMLStreamBufferResult (com.sun.xml.stream.buffer.XMLStreamBufferResult)4 URL (java.net.URL)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)4 StreamReaderBufferCreator (com.sun.xml.stream.buffer.stax.StreamReaderBufferCreator)3 SDDocumentSource (com.sun.xml.ws.api.server.SDDocumentSource)3 JAXBException (jakarta.xml.bind.JAXBException)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 XMLStreamBuffer (com.sun.xml.stream.buffer.XMLStreamBuffer)2 XMLStreamBufferMark (com.sun.xml.stream.buffer.XMLStreamBufferMark)2 StreamMessage (com.sun.xml.ws.message.stream.StreamMessage)2 Marshaller (jakarta.xml.bind.Marshaller)2 AttachmentMarshaller (jakarta.xml.bind.attachment.AttachmentMarshaller)2 NotNull (com.sun.istack.NotNull)1 StreamWriterBufferCreator (com.sun.xml.stream.buffer.stax.StreamWriterBufferCreator)1 EndpointAddress (com.sun.xml.ws.api.EndpointAddress)1 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)1 EditableWSDLPort (com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLPort)1