use of org.apache.cxf.staxutils.PartialXMLStreamReader in project cxf by apache.
the class InTransformReaderTest method testPartialReadWithComplexRequestMultipleNamespace.
@Test
public void testPartialReadWithComplexRequestMultipleNamespace() throws Exception {
XMLStreamReader reader = StaxUtils.createXMLStreamReader(InTransformReader.class.getResourceAsStream("../resources/complexReqIn2.xml"));
Map<String, String> inMap = new HashMap<>();
inMap.put("{http://cxf.apache.org/transform/header/element}*", "{http://cxf.apache.org/transform/header/otherelement}*");
inMap.put("{http://cxf.apache.org/transform/test}*", "{http://cxf.apache.org/transform/othertest}*");
reader = new InTransformReader(reader, inMap, null, null, null, false);
QName bodyTag = new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body");
PartialXMLStreamReader filteredReader = new PartialXMLStreamReader(reader, bodyTag);
XMLStreamReader reader2 = StaxUtils.createXMLStreamReader(InTransformReader.class.getResourceAsStream("../resources/complexReq2partial.xml"));
TransformTestUtils.verifyReaders(reader2, filteredReader, false, true);
}
use of org.apache.cxf.staxutils.PartialXMLStreamReader in project cxf by apache.
the class InTransformReaderTest method testPartialReadWithComplexTransformationNamespace.
@Test
public void testPartialReadWithComplexTransformationNamespace() throws Exception {
XMLStreamReader reader = StaxUtils.createXMLStreamReader(InTransformReader.class.getResourceAsStream("../resources/complexReqIn3.xml"));
Map<String, String> inMap = new HashMap<>();
inMap.put("{http://cxf.apache.org/transform/header/element}*", "{http://cxf.apache.org/transform/header/otherelement}*");
inMap.put("{http://cxf.apache.org/transform/test}*", "{http://cxf.apache.org/transform/othertest}*");
inMap.put("{http://schemas.xmlsoap.org/soap/envelope/}Envelope", "{http://schemas.xmlsoap.org/soap/envelope/}TheEnvelope");
// set the block original reader flag to true
reader = new InTransformReader(reader, inMap, null, null, null, true);
QName bodyTag = new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body");
PartialXMLStreamReader filteredReader = new PartialXMLStreamReader(reader, bodyTag);
XMLStreamReader reader2 = StaxUtils.createXMLStreamReader(InTransformReader.class.getResourceAsStream("../resources/complexReq3partial.xml"));
TransformTestUtils.verifyReaders(reader2, filteredReader, false, true);
}
use of org.apache.cxf.staxutils.PartialXMLStreamReader in project cxf by apache.
the class DocLiteralInInterceptorTest method testUnmarshalSourceData.
@Test
public void testUnmarshalSourceData() throws Exception {
XMLStreamReader reader = StaxUtils.createXMLStreamReader(getClass().getResourceAsStream("resources/multiPartDocLitBareReq.xml"));
assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag());
XMLStreamReader filteredReader = new PartialXMLStreamReader(reader, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body"));
// advance the xml reader to the message parts
StaxUtils.read(filteredReader);
assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag());
Message m = new MessageImpl();
Exchange exchange = new ExchangeImpl();
Service service = control.createMock(Service.class);
exchange.put(Service.class, service);
EasyMock.expect(service.getDataBinding()).andReturn(new SourceDataBinding());
EasyMock.expect(service.size()).andReturn(0).anyTimes();
EasyMock.expect(service.isEmpty()).andReturn(true).anyTimes();
Endpoint endpoint = control.createMock(Endpoint.class);
exchange.put(Endpoint.class, endpoint);
OperationInfo operationInfo = new OperationInfo();
operationInfo.setProperty("operation.is.synthetic", Boolean.TRUE);
MessageInfo messageInfo = new MessageInfo(operationInfo, Type.INPUT, new QName("http://foo.com", "bar"));
messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo1"), null));
messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo2"), null));
messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo3"), null));
messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo4"), null));
for (MessagePartInfo mpi : messageInfo.getMessageParts()) {
mpi.setMessageContainer(messageInfo);
}
operationInfo.setInput("inputName", messageInfo);
BindingOperationInfo boi = new BindingOperationInfo(null, operationInfo);
exchange.put(BindingOperationInfo.class, boi);
EndpointInfo endpointInfo = control.createMock(EndpointInfo.class);
BindingInfo binding = control.createMock(BindingInfo.class);
EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).anyTimes();
EasyMock.expect(endpointInfo.getBinding()).andReturn(binding).anyTimes();
EasyMock.expect(binding.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
EasyMock.expect(endpointInfo.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
EasyMock.expect(endpoint.size()).andReturn(0).anyTimes();
EasyMock.expect(endpoint.isEmpty()).andReturn(true).anyTimes();
ServiceInfo serviceInfo = control.createMock(ServiceInfo.class);
EasyMock.expect(endpointInfo.getService()).andReturn(serviceInfo).anyTimes();
EasyMock.expect(serviceInfo.getName()).andReturn(new QName("http://foo.com", "service")).anyTimes();
InterfaceInfo interfaceInfo = control.createMock(InterfaceInfo.class);
EasyMock.expect(serviceInfo.getInterface()).andReturn(interfaceInfo).anyTimes();
EasyMock.expect(interfaceInfo.getName()).andReturn(new QName("http://foo.com", "interface")).anyTimes();
EasyMock.expect(endpointInfo.getName()).andReturn(new QName("http://foo.com", "endpoint")).anyTimes();
EasyMock.expect(endpointInfo.getProperty("URI", URI.class)).andReturn(new URI("dummy")).anyTimes();
List<OperationInfo> operations = new ArrayList<>();
EasyMock.expect(interfaceInfo.getOperations()).andReturn(operations).anyTimes();
m.setExchange(exchange);
m.put(Message.SCHEMA_VALIDATION_ENABLED, false);
m.setContent(XMLStreamReader.class, reader);
control.replay();
new DocLiteralInInterceptor().handleMessage(m);
MessageContentsList params = (MessageContentsList) m.getContent(List.class);
assertEquals(4, params.size());
assertEquals("StringDefaultInputElem", ((DOMSource) params.get(0)).getNode().getFirstChild().getNodeName());
assertEquals("IntParamInElem", ((DOMSource) params.get(1)).getNode().getFirstChild().getNodeName());
}
use of org.apache.cxf.staxutils.PartialXMLStreamReader in project cxf by apache.
the class SOAPHandlerInterceptorTest method preparemXMLStreamReader.
private XMLStreamReader preparemXMLStreamReader(String resouceName) throws Exception {
InputStream is = this.getClass().getResourceAsStream(resouceName);
XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(is);
// skip until soap body
if (xmlReader.nextTag() == XMLStreamConstants.START_ELEMENT) {
String ns = xmlReader.getNamespaceURI();
SoapVersion soapVersion = SoapVersionFactory.getInstance().getSoapVersion(ns);
// message.setVersion(soapVersion);
QName qn = xmlReader.getName();
while (!qn.equals(soapVersion.getBody()) && !qn.equals(soapVersion.getHeader())) {
while (xmlReader.nextTag() != XMLStreamConstants.START_ELEMENT) {
// nothing to do
}
qn = xmlReader.getName();
}
if (qn.equals(soapVersion.getHeader())) {
XMLStreamReader filteredReader = new PartialXMLStreamReader(xmlReader, soapVersion.getBody());
StaxUtils.read(filteredReader);
}
// advance just past body.
xmlReader.next();
while (xmlReader.isWhiteSpace()) {
xmlReader.next();
}
}
return xmlReader;
}
use of org.apache.cxf.staxutils.PartialXMLStreamReader in project cxf by apache.
the class RetransmissionQueueImpl method readHeaders.
private void readHeaders(XMLStreamReader xmlReader, SoapMessage message) throws XMLStreamException {
// read header portion of SOAP document into DOM
SoapVersion version = message.getVersion();
XMLStreamReader filteredReader = new PartialXMLStreamReader(xmlReader, version.getBody());
Node nd = message.getContent(Node.class);
W3CDOMStreamWriter writer = message.get(W3CDOMStreamWriter.class);
Document doc = null;
if (writer != null) {
StaxUtils.copy(filteredReader, writer);
doc = writer.getDocument();
} else if (nd instanceof Document) {
doc = (Document) nd;
StaxUtils.readDocElements(doc, doc, filteredReader, false, false);
} else {
doc = StaxUtils.read(filteredReader);
message.setContent(Node.class, doc);
}
// get the actual SOAP header
Element element = doc.getDocumentElement();
QName header = version.getHeader();
List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(element, header.getNamespaceURI(), header.getLocalPart());
for (Element elem : elemList) {
// set all child elements as headers for message transmission
Element hel = DOMUtils.getFirstElement(elem);
while (hel != null) {
SoapHeader sheader = new SoapHeader(DOMUtils.getElementQName(hel), hel);
message.getHeaders().add(sheader);
hel = DOMUtils.getNextElement(hel);
}
}
}
Aggregations