use of com.sun.xml.ws.encoding.TagInfoset in project metro-jax-ws by eclipse-ee4j.
the class StreamMessage method writeTo.
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
if (envelopeReader != null)
readEnvelope(this);
contentHandler.setDocumentLocator(NULL_LOCATOR);
contentHandler.startDocument();
envelopeTag.writeStart(contentHandler);
if (hasHeaders() && headerTag == null)
headerTag = new TagInfoset(envelopeTag.nsUri, "Header", envelopeTag.prefix, EMPTY_ATTS);
if (headerTag != null) {
headerTag.writeStart(contentHandler);
if (hasHeaders()) {
MessageHeaders headers = getHeaders();
for (Header h : headers.asList()) {
// shouldn't JDK be smart enough to use array-style indexing for this foreach!?
h.writeTo(contentHandler, errorHandler);
}
}
headerTag.writeEnd(contentHandler);
}
bodyTag.writeStart(contentHandler);
writePayloadTo(contentHandler, errorHandler, true);
bodyTag.writeEnd(contentHandler);
envelopeTag.writeEnd(contentHandler);
contentHandler.endDocument();
}
use of com.sun.xml.ws.encoding.TagInfoset in project metro-jax-ws by eclipse-ee4j.
the class StreamMessage method readEnvelope.
private static void readEnvelope(StreamMessage message) {
if (message.envelopeReader == null)
return;
XMLStreamReader reader = message.envelopeReader;
message.envelopeReader = null;
SOAPVersion soapVersion = message.soapVersion;
// Move to soap:Envelope and verify
if (reader.getEventType() != XMLStreamConstants.START_ELEMENT)
XMLStreamReaderUtil.nextElementContent(reader);
XMLStreamReaderUtil.verifyReaderState(reader, XMLStreamConstants.START_ELEMENT);
if (SOAP_ENVELOPE.equals(reader.getLocalName()) && !soapVersion.nsUri.equals(reader.getNamespaceURI())) {
throw new VersionMismatchException(soapVersion, soapVersion.nsUri, reader.getNamespaceURI());
}
XMLStreamReaderUtil.verifyTag(reader, soapVersion.nsUri, SOAP_ENVELOPE);
TagInfoset envelopeTag = new TagInfoset(reader);
// Collect namespaces on soap:Envelope
Map<String, String> namespaces = new HashMap<>();
for (int i = 0; i < reader.getNamespaceCount(); i++) {
namespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
}
// Move to next element
XMLStreamReaderUtil.nextElementContent(reader);
XMLStreamReaderUtil.verifyReaderState(reader, javax.xml.stream.XMLStreamConstants.START_ELEMENT);
HeaderList headers = null;
TagInfoset headerTag = null;
if (reader.getLocalName().equals(SOAP_HEADER) && reader.getNamespaceURI().equals(soapVersion.nsUri)) {
headerTag = new TagInfoset(reader);
// Collect namespaces on soap:Header
for (int i = 0; i < reader.getNamespaceCount(); i++) {
namespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
}
// skip <soap:Header>
XMLStreamReaderUtil.nextElementContent(reader);
// If SOAP header blocks are present (i.e. not <soap:Header/>)
if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
headers = new HeaderList(soapVersion);
try {
// Cache SOAP header blocks
StreamHeaderDecoder headerDecoder = SOAPVersion.SOAP_11.equals(soapVersion) ? SOAP11StreamHeaderDecoder : SOAP12StreamHeaderDecoder;
cacheHeaders(reader, namespaces, headers, headerDecoder);
} catch (XMLStreamException e) {
// TODO need to throw more meaningful exception
throw new WebServiceException(e);
}
}
// Move to soap:Body
XMLStreamReaderUtil.nextElementContent(reader);
}
// Verify that <soap:Body> is present
XMLStreamReaderUtil.verifyTag(reader, soapVersion.nsUri, SOAP_BODY);
TagInfoset bodyTag = new TagInfoset(reader);
String bodyPrologue = XMLStreamReaderUtil.nextWhiteSpaceContent(reader);
message.init(envelopeTag, headerTag, message.attachmentSet, headers, bodyPrologue, bodyTag, null, reader, soapVersion);
// when there's no payload,
// it's tempting to use EmptyMessageImpl, but it doesn't preserve the infoset
// of <envelope>,<header>, and <body>, so we need to stick to StreamMessage.
}
use of com.sun.xml.ws.encoding.TagInfoset in project metro-jax-ws by eclipse-ee4j.
the class XMLReaderCompositeTest method testComposite.
// @Test
public void testComposite() throws Exception {
XMLStreamReader r = r("<root xmlns='ns0' xmlns:p1='ns1' att1='11' xmlns:p2='ns2' xmlns:p3='ns3'/>");
XMLStreamReader x = r("<p1:x xmlns:p2='ns2' xmlns:p1='ns1' att2='22' p2:att2='11'/>");
XMLStreamReader a = r("<a xmlns='ns0' att1='11'/>");
XMLStreamReader b = r("<p1:b xmlns='ns0' att1='11' xmlns:p3='ns3' xmlns:p1='ns1'/>");
TagInfoset rTag = new TagInfoset(r);
ElemInfo rElem = new ElemInfo(rTag, null);
TagInfoset xTag = new TagInfoset(x);
ElemInfo xElem = new ElemInfo(xTag, rElem);
XMLStreamReader[] kids = { a, b };
XMLReaderComposite xrc = new XMLReaderComposite(xElem, kids);
assertTrue(xrc.isStartElement());
assertEquals(new QName("ns1", "x"), xrc.getName());
assertEquals(2, xrc.getAttributeCount());
assertEquals(2, xrc.getNamespaceCount());
assertEquals("ns0", xrc.getNamespaceURI(""));
assertEquals("ns3", xrc.getNamespaceURI("p3"));
xrc.next();
assertTrue(xrc.isStartElement());
assertEquals(new QName("ns0", "a"), xrc.getName());
assertEquals(1, xrc.getAttributeCount());
xrc.next();
assertTrue(xrc.isEndElement());
xrc.next();
assertTrue(xrc.isStartElement());
assertEquals(new QName("ns1", "b"), xrc.getName());
assertEquals(1, xrc.getAttributeCount());
xrc.next();
assertTrue(xrc.isEndElement());
xrc.next();
assertTrue(xrc.isEndElement());
}
use of com.sun.xml.ws.encoding.TagInfoset in project metro-jax-ws by eclipse-ee4j.
the class StreamMessage method writeToBodyStart.
public void writeToBodyStart(XMLStreamWriter writer) throws XMLStreamException {
if (envelopeReader != null)
readEnvelope(this);
writer.writeStartDocument();
envelopeTag.writeStart(writer);
// write headers
MessageHeaders hl = getHeaders();
if (hl.hasHeaders() && headerTag == null)
headerTag = new TagInfoset(envelopeTag.nsUri, "Header", envelopeTag.prefix, EMPTY_ATTS);
if (headerTag != null) {
headerTag.writeStart(writer);
if (hl.hasHeaders()) {
for (Header h : hl.asList()) {
h.writeTo(writer);
}
}
writer.writeEndElement();
}
bodyTag.writeStart(writer);
}
use of com.sun.xml.ws.encoding.TagInfoset in project metro-jax-ws by eclipse-ee4j.
the class AbstractMessageImpl method create.
static void create(SOAPVersion v, List c) {
int base = v.ordinal() * 3;
c.add(base, new TagInfoset(v.nsUri, "Envelope", "S", EMPTY_ATTS, "S", v.nsUri));
c.add(base + 1, new TagInfoset(v.nsUri, "Header", "S", EMPTY_ATTS));
c.add(base + 2, new TagInfoset(v.nsUri, "Body", "S", EMPTY_ATTS));
}
Aggregations