use of com.sun.xml.stream.buffer.stax.StreamReaderBufferCreator in project metro-jax-ws by eclipse-ee4j.
the class StreamMessage method cacheHeaders.
private static XMLStreamBuffer cacheHeaders(XMLStreamReader reader, Map<String, String> namespaces, HeaderList headers, StreamHeaderDecoder headerDecoder) throws XMLStreamException {
MutableXMLStreamBuffer buffer = createXMLStreamBuffer();
StreamReaderBufferCreator creator = new StreamReaderBufferCreator();
creator.setXMLStreamBuffer(buffer);
// Reader is positioned at the first header block
while (reader.getEventType() == javax.xml.stream.XMLStreamConstants.START_ELEMENT) {
Map<String, String> headerBlockNamespaces = namespaces;
// Collect namespaces on SOAP header block
if (reader.getNamespaceCount() > 0) {
headerBlockNamespaces = new HashMap<>(namespaces);
for (int i = 0; i < reader.getNamespaceCount(); i++) {
headerBlockNamespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
}
}
// Mark
XMLStreamBuffer mark = new XMLStreamBufferMark(headerBlockNamespaces, creator);
// Create Header
headers.add(headerDecoder.decodeHeader(reader, mark));
// Cache the header block
// After caching Reader will be positioned at next header block or
// the end of the </soap:header>
creator.createElementFragment(reader, false);
if (reader.getEventType() != XMLStreamConstants.START_ELEMENT && reader.getEventType() != XMLStreamConstants.END_ELEMENT) {
XMLStreamReaderUtil.nextElementContent(reader);
}
}
return buffer;
}
use of com.sun.xml.stream.buffer.stax.StreamReaderBufferCreator in project metro-jax-ws by eclipse-ee4j.
the class StreamMessage method copy.
// TODO: this method should be probably rewritten to respect spaces between elements; is it used at all?
@Override
public Message copy() {
if (envelopeReader != null)
readEnvelope(this);
try {
assert unconsumed();
// but we don't want to mark it as consumed
consumedAt = null;
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
StreamReaderBufferCreator c = new StreamReaderBufferCreator(xsb);
// preserving inscope namespaces from envelope, and body. Other option
// would be to create a filtering XMLStreamReader from reader+envelopeTag+bodyTag
c.storeElement(envelopeTag.nsUri, envelopeTag.localName, envelopeTag.prefix, envelopeTag.ns);
c.storeElement(bodyTag.nsUri, bodyTag.localName, bodyTag.prefix, bodyTag.ns);
if (hasPayload()) {
// Loop all the way for multi payload case
while (reader.getEventType() != XMLStreamConstants.END_DOCUMENT) {
String name = reader.getLocalName();
String nsUri = reader.getNamespaceURI();
if (isBodyElement(name, nsUri) || (reader.getEventType() == XMLStreamConstants.END_DOCUMENT))
break;
c.create(reader);
// those won't be in the message itself, but we store them in field bodyEpilogue
if (reader.isWhiteSpace()) {
bodyEpilogue = XMLStreamReaderUtil.currentWhiteSpaceContent(reader);
} else {
// clear it in case the existing was not the last one
// (we are interested only in the last one?)
bodyEpilogue = null;
}
}
}
// create structure element for </Body>
c.storeEndElement();
// create structure element for </Envelope>
c.storeEndElement();
// create structure element for END_DOCUMENT
c.storeEndElement();
XMLStreamReaderUtil.readRest(reader);
XMLStreamReaderUtil.close(reader);
XMLStreamReaderFactory.recycle(reader);
reader = xsb.readAsXMLStreamReader();
XMLStreamReader clone = xsb.readAsXMLStreamReader();
// advance to the start tag of the <Body> first child element
proceedToRootElement(reader);
proceedToRootElement(clone);
return new StreamMessage(envelopeTag, headerTag, attachmentSet, HeaderList.copy(headers), bodyPrologue, bodyTag, bodyEpilogue, clone, soapVersion).copyFrom(this);
} catch (XMLStreamException e) {
throw new WebServiceException("Failed to copy a message", e);
}
}
use of com.sun.xml.stream.buffer.stax.StreamReaderBufferCreator 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<>();
}
Aggregations