Search in sources :

Example 16 with MutableXMLStreamBuffer

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

the class MtomTest method XtestNamespaceAsLastItem1.

public void XtestNamespaceAsLastItem1() throws Exception {
    MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
    // new StreamWriterBufferCreator(xsb);
    XMLStreamWriter w = xsb.createFromXMLStreamWriter();
    w.writeStartElement("p1", "tag", "ns1");
    w.writeAttribute("a", "x");
    w.writeNamespace("p", "ns");
    w.writeEndElement();
    XMLStreamReader xr = xsb.readAsXMLStreamReader();
    boolean tested = false;
    while (xr.hasNext()) {
        int i = xr.next();
    // if (xr.isStartElement() && xr.getLocalName().equals("tag")) {
    // assertEquals(1,xr.getAttributeCount());
    // assertEquals("ns",xr.getNamespaceURI("p"));
    // tested = true;
    // }
    }
// assertTrue(tested);
}
Also used : MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 17 with MutableXMLStreamBuffer

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

the class RuntimeWSDLParser method parsePort.

private void parsePort(XMLStreamReader reader, EditableWSDLService service) {
    port_nsdecl.putAll(service_nsdecl);
    readNSDecl(port_nsdecl, reader);
    String portName = ParserUtil.getMandatoryNonEmptyAttribute(reader, WSDLConstants.ATTR_NAME);
    String binding = ParserUtil.getMandatoryNonEmptyAttribute(reader, "binding");
    QName bindingName = ParserUtil.getQName(reader, binding);
    QName portQName = new QName(service.getName().getNamespaceURI(), portName);
    EditableWSDLPort port = new WSDLPortImpl(reader, service, portQName, bindingName);
    extensionFacade.portAttributes(port, reader);
    String location;
    while (XMLStreamReaderUtil.nextElementContent(reader) != XMLStreamConstants.END_ELEMENT) {
        QName name = reader.getName();
        if (SOAPConstants.QNAME_ADDRESS.equals(name) || SOAPConstants.QNAME_SOAP12ADDRESS.equals(name)) {
            location = ParserUtil.getMandatoryNonEmptyAttribute(reader, WSDLConstants.ATTR_LOCATION);
            if (location != null) {
                try {
                    port.setAddress(new EndpointAddress(location));
                } catch (URISyntaxException e) {
                // Lets not throw any exception, latter on it should be thrown when invocation happens. At this
                // time user has option to set the endopint address using request contexxt property.
                }
            }
            XMLStreamReaderUtil.next(reader);
        } else if (AddressingVersion.W3C.nsUri.equals(name.getNamespaceURI()) && "EndpointReference".equals(name.getLocalPart())) {
            try {
                StreamReaderBufferCreator creator = new StreamReaderBufferCreator(new MutableXMLStreamBuffer());
                XMLStreamBuffer eprbuffer = new XMLStreamBufferMark(port_nsdecl, creator);
                creator.createElementFragment(reader, false);
                WSEndpointReference wsepr = new WSEndpointReference(eprbuffer, AddressingVersion.W3C);
                // wsepr.toSpec().writeTo(new StreamResult(System.out));
                port.setEPR(wsepr);
                /* XMLStreamBuffer.createNewBufferFromXMLStreamReader(reader) called from inside WSEndpointReference()
                       consumes the complete EPR infoset and moves to the next element. This breaks the normal wsdl parser
                       processing where it expects anyone reading the infoset to move to the end of the element that its reading
                       and not to the next element.
                     */
                if (reader.getEventType() == XMLStreamConstants.END_ELEMENT && reader.getName().equals(WSDLConstants.QNAME_PORT))
                    break;
            } catch (XMLStreamException e) {
                throw new WebServiceException(e);
            }
        } else {
            extensionFacade.portElements(port, reader);
        }
    }
    if (port.getAddress() == null) {
        try {
            port.setAddress(new EndpointAddress(""));
        } catch (URISyntaxException e) {
        // Lets not throw any exception, latter on it should be thrown when invocation happens. At this
        // time user has option to set the endopint address using request contexxt property.
        }
    }
    service.put(portQName, port);
    port_nsdecl = new HashMap<>();
}
Also used : StreamReaderBufferCreator(com.sun.xml.stream.buffer.stax.StreamReaderBufferCreator) WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) URISyntaxException(java.net.URISyntaxException) XMLStreamBufferMark(com.sun.xml.stream.buffer.XMLStreamBufferMark) MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) EditableWSDLPort(com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLPort) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLStreamBuffer(com.sun.xml.stream.buffer.XMLStreamBuffer) EndpointAddress(com.sun.xml.ws.api.EndpointAddress)

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