Search in sources :

Example 1 with PartialXMLStreamReader

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);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) PartialXMLStreamReader(org.apache.cxf.staxutils.PartialXMLStreamReader) PartialXMLStreamReader(org.apache.cxf.staxutils.PartialXMLStreamReader) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 2 with PartialXMLStreamReader

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);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) PartialXMLStreamReader(org.apache.cxf.staxutils.PartialXMLStreamReader) PartialXMLStreamReader(org.apache.cxf.staxutils.PartialXMLStreamReader) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 3 with PartialXMLStreamReader

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());
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) PartialXMLStreamReader(org.apache.cxf.staxutils.PartialXMLStreamReader) PartialXMLStreamReader(org.apache.cxf.staxutils.PartialXMLStreamReader) Message(org.apache.cxf.message.Message) MessageContentsList(org.apache.cxf.message.MessageContentsList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) URI(java.net.URI) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) BindingInfo(org.apache.cxf.service.model.BindingInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) ArrayList(java.util.ArrayList) List(java.util.List) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) MessageInfo(org.apache.cxf.service.model.MessageInfo) Exchange(org.apache.cxf.message.Exchange) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 4 with PartialXMLStreamReader

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;
}
Also used : SoapVersion(org.apache.cxf.binding.soap.SoapVersion) XMLStreamReader(javax.xml.stream.XMLStreamReader) PartialXMLStreamReader(org.apache.cxf.staxutils.PartialXMLStreamReader) PartialXMLStreamReader(org.apache.cxf.staxutils.PartialXMLStreamReader) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName)

Example 5 with PartialXMLStreamReader

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);
        }
    }
}
Also used : SoapVersion(org.apache.cxf.binding.soap.SoapVersion) W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) XMLStreamReader(javax.xml.stream.XMLStreamReader) PartialXMLStreamReader(org.apache.cxf.staxutils.PartialXMLStreamReader) PartialXMLStreamReader(org.apache.cxf.staxutils.PartialXMLStreamReader) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) Document(org.w3c.dom.Document)

Aggregations

QName (javax.xml.namespace.QName)8 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 PartialXMLStreamReader (org.apache.cxf.staxutils.PartialXMLStreamReader)8 HashMap (java.util.HashMap)6 Test (org.junit.Test)5 SoapVersion (org.apache.cxf.binding.soap.SoapVersion)3 InputStream (java.io.InputStream)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SoapHeader (org.apache.cxf.binding.soap.SoapHeader)2 SourceDataBinding (org.apache.cxf.databinding.source.SourceDataBinding)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 Exchange (org.apache.cxf.message.Exchange)2 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)2 Message (org.apache.cxf.message.Message)2 MessageContentsList (org.apache.cxf.message.MessageContentsList)2 MessageImpl (org.apache.cxf.message.MessageImpl)2 Service (org.apache.cxf.service.Service)2 BindingInfo (org.apache.cxf.service.model.BindingInfo)2