use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer 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.MutableXMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.
the class ProblemActionHeader method readHeader.
public XMLStreamReader readHeader() throws XMLStreamException {
MutableXMLStreamBuffer buf = new MutableXMLStreamBuffer();
XMLStreamWriter w = buf.createFromXMLStreamWriter();
writeTo(w);
return buf.readAsXMLStreamReader();
}
use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.
the class StringHeader method readHeader.
public XMLStreamReader readHeader() throws XMLStreamException {
MutableXMLStreamBuffer buf = new MutableXMLStreamBuffer();
XMLStreamWriter w = buf.createFromXMLStreamWriter();
writeTo(w);
return buf.readAsXMLStreamReader();
}
use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.
the class WSEndpointReference method createBufferFromAddress.
private static XMLStreamBuffer createBufferFromAddress(String address, AddressingVersion version) {
try {
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
StreamWriterBufferCreator w = new StreamWriterBufferCreator(xsb);
w.writeStartDocument();
w.writeStartElement(version.getPrefix(), "EndpointReference", version.nsUri);
w.writeNamespace(version.getPrefix(), version.nsUri);
w.writeStartElement(version.getPrefix(), version.eprType.address, version.nsUri);
w.writeCharacters(address);
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
return xsb;
} catch (XMLStreamException e) {
// can never happen because we are writing to XSB
throw new AssertionError(e);
}
}
use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.
the class WSEndpointReference method createWithAddress.
/**
* Creates a new {@link WSEndpointReference} by replacing the address of this EPR
* to the new one.
*
* <p>
* The following example shows how you can use this to force an HTTPS EPR,
* when the endpoint can serve both HTTP and HTTPS requests.
* <pre>
* if(epr.getAddress().startsWith("http:"))
* epr = epr.createWithAddress("https:"+epr.getAddress().substring(5));
* </pre>
*
* @param newAddress
* This is a complete URL to be written inside <Address> element of the EPR,
* such as "http://foo.bar/abc/def"
*/
@NotNull
public WSEndpointReference createWithAddress(@NotNull final String newAddress) {
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
XMLFilterImpl filter = new XMLFilterImpl() {
private boolean inAddress = false;
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
if (localName.equals("Address") && uri.equals(version.nsUri)) {
inAddress = true;
}
super.startElement(uri, localName, qName, atts);
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (!inAddress) {
super.characters(ch, start, length);
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (inAddress) {
super.characters(newAddress.toCharArray(), 0, newAddress.length());
}
inAddress = false;
super.endElement(uri, localName, qName);
}
};
filter.setContentHandler(xsb.createFromSAXBufferCreator());
try {
infoset.writeTo(filter, false);
} catch (SAXException e) {
// impossible since we are writing from XSB to XSB.
throw new AssertionError(e);
}
return new WSEndpointReference(xsb, version);
}
Aggregations