use of com.sun.xml.stream.buffer.XMLStreamBuffer 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.XMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.
the class WSEndpointReference method parseEPRExtensions.
private void parseEPRExtensions() throws XMLStreamException {
rootEprExtensions = new HashMap<>();
StreamReaderBufferProcessor xsr = infoset.readAsXMLStreamReader();
// parser should be either at the start element or the start document
if (xsr.getEventType() == XMLStreamReader.START_DOCUMENT) {
xsr.nextTag();
}
assert xsr.getEventType() == XMLStreamReader.START_ELEMENT;
if (!xsr.getNamespaceURI().equals(version.nsUri)) {
throw new WebServiceException(AddressingMessages.WRONG_ADDRESSING_VERSION(version.nsUri, xsr.getNamespaceURI()));
}
// since often EPR doesn't have extensions, create array lazily
XMLStreamBuffer mark;
String localName;
String ns;
while ((mark = xsr.nextTagAndMark()) != null) {
localName = xsr.getLocalName();
ns = xsr.getNamespaceURI();
if (version.nsUri.equals(ns)) {
// EPR extensions do not use the same namespace of the Addressing Version.
// Not an extension - SKIP
XMLStreamReaderUtil.skipElement(xsr);
} else {
QName qn = new QName(ns, localName);
rootEprExtensions.put(qn, new WSEPRExtension(mark, qn));
XMLStreamReaderUtil.skipElement(xsr);
}
}
// hit to </EndpointReference> by now
}
use of com.sun.xml.stream.buffer.XMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.
the class WSEndpointReferenceTest method creaateSubtreeEPR.
/**
* This creates {@link WSEndpointReference} that uses a fragment infoset.
* We should really fix this in XMLStreamBuffer.
*/
private WSEndpointReference creaateSubtreeEPR() throws XMLStreamException {
XMLStreamBuffer xsb = XMLStreamBuffer.createNewBufferFromXMLStreamReader(XMLInputFactory.newInstance().createXMLStreamReader(getClass().getClassLoader().getResourceAsStream("test-epr.xml")));
StreamReaderBufferProcessor p = xsb.readAsXMLStreamReader();
XMLStreamBuffer mark = p.nextTagAndMark();
return new WSEndpointReference(mark, W3C);
}
use of com.sun.xml.stream.buffer.XMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.
the class JAXBTest method testJAXBElementMarshalling.
public void testJAXBElementMarshalling() throws Exception {
JAXBRIContext jc = (JAXBRIContext) JAXBContext.newInstance(whitebox.jaxb.client.DetailType.class);
DetailType dt = new DetailType();
SOAPFault sf = createFault();
dt.getDetails().add(sf.getDetail());
Marshaller m = jc.createMarshaller();
m.marshal(dt, System.out);
XMLStreamBufferResult sbr = new XMLStreamBufferResult();
m.setProperty(Marshaller.JAXB_FRAGMENT, true);
m.marshal(dt, sbr);
XMLStreamBuffer infoset = sbr.getXMLStreamBuffer();
XMLStreamReader reader = infoset.readAsXMLStreamReader();
if (reader.getEventType() == START_DOCUMENT)
XMLStreamReaderUtil.nextElementContent(reader);
verifyDetail(reader);
}
use of com.sun.xml.stream.buffer.XMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.
the class WSEndpointReference method parse.
/**
* Parses inside EPR and mark all reference parameters.
*/
private void parse() throws XMLStreamException {
// TODO: validate the EPR structure.
// check for non-existent Address, that sort of things.
StreamReaderBufferProcessor xsr = infoset.readAsXMLStreamReader();
// parser should be either at the start element or the start document
if (xsr.getEventType() == XMLStreamReader.START_DOCUMENT) {
xsr.nextTag();
}
assert xsr.getEventType() == XMLStreamReader.START_ELEMENT;
String rootLocalName = xsr.getLocalName();
if (!xsr.getNamespaceURI().equals(version.nsUri)) {
throw new WebServiceException(AddressingMessages.WRONG_ADDRESSING_VERSION(version.nsUri, xsr.getNamespaceURI()));
}
this.rootElement = new QName(xsr.getNamespaceURI(), rootLocalName);
// since often EPR doesn't have a reference parameter, create array lazily
List<Header> marks = null;
while (xsr.nextTag() == XMLStreamReader.START_ELEMENT) {
String localName = xsr.getLocalName();
if (version.isReferenceParameter(localName)) {
XMLStreamBuffer mark;
while ((mark = xsr.nextTagAndMark()) != null) {
if (marks == null) {
marks = new ArrayList<>();
}
// TODO: need a different header for member submission version
marks.add(version.createReferenceParameterHeader(mark, xsr.getNamespaceURI(), xsr.getLocalName()));
XMLStreamReaderUtil.skipElement(xsr);
}
} else if (localName.equals("Address")) {
if (address != null) {
throw new InvalidAddressingHeaderException(new QName(version.nsUri, rootLocalName), AddressingVersion.fault_duplicateAddressInEpr);
}
address = xsr.getElementText().trim();
} else {
XMLStreamReaderUtil.skipElement(xsr);
}
}
if (marks == null) {
this.referenceParameters = EMPTY_ARRAY;
} else {
this.referenceParameters = marks.toArray(new Header[0]);
}
if (address == null) {
throw new InvalidAddressingHeaderException(new QName(version.nsUri, rootLocalName), version.fault_missingAddressInEpr);
}
}
Aggregations