Search in sources :

Example 81 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class DocLiteralInInterceptorTest method testUnmarshalSourceDataWrapped.

@Test
public void testUnmarshalSourceDataWrapped() throws Exception {
    XMLStreamReader reader = StaxUtils.createXMLStreamReader(getClass().getResourceAsStream("resources/docLitWrappedReq.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();
    // request to keep the document as wrapped
    m.put(DocLiteralInInterceptor.KEEP_PARAMETERS_WRAPPER, true);
    Exchange exchange = new ExchangeImpl();
    Service service = control.createMock(Service.class);
    exchange.put(Service.class, service);
    EasyMock.expect(service.getDataBinding()).andReturn(new SourceDataBinding()).anyTimes();
    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);
    // wrapped
    OperationInfo operationInfo = new OperationInfo();
    MessageInfo messageInfo = new MessageInfo(operationInfo, Type.INPUT, new QName(NS, "foo"));
    messageInfo.addMessagePart(new MessagePartInfo(new QName(NS, "personId"), null));
    messageInfo.addMessagePart(new MessagePartInfo(new QName(NS, "ssn"), null));
    messageInfo.getMessagePart(0).setConcreteName(new QName(NS, "personId"));
    messageInfo.getMessagePart(1).setConcreteName(new QName(NS, "ssn"));
    operationInfo.setInput("inputName", messageInfo);
    // wrapper
    OperationInfo operationInfoWrapper = new OperationInfo();
    MessageInfo messageInfoWrapper = new MessageInfo(operationInfo, Type.INPUT, new QName(NS, "foo"));
    messageInfoWrapper.addMessagePart(new MessagePartInfo(new QName(NS, "GetPerson"), null));
    messageInfoWrapper.getMessagePart(0).setConcreteName(new QName(NS, "GetPerson"));
    operationInfoWrapper.setInput("inputName", messageInfoWrapper);
    operationInfoWrapper.setUnwrappedOperation(operationInfo);
    ServiceInfo serviceInfo = control.createMock(ServiceInfo.class);
    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();
    BindingInfo bindingInfo = new BindingInfo(serviceInfo, "");
    BindingOperationInfo boi = new BindingOperationInfo(bindingInfo, operationInfoWrapper);
    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();
    EasyMock.expect(endpointInfo.getService()).andReturn(serviceInfo).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);
    // we expect a wrapped document
    assertEquals(1, params.size());
    Map<String, String> ns = new HashMap<>();
    ns.put("ns", NS);
    XPathUtils xu = new XPathUtils(ns);
    assertEquals("hello", xu.getValueString("//ns:GetPerson/ns:personId", ((DOMSource) params.get(0)).getNode().getFirstChild()));
    assertEquals("1234", xu.getValueString("//ns:GetPerson/ns:ssn", ((DOMSource) params.get(0)).getNode().getFirstChild()));
}
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) XPathUtils(org.apache.cxf.helpers.XPathUtils) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 82 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class WSDLServiceBuilderTest method testNoBodyParts.

@Test
public void testNoBodyParts() throws Exception {
    setUpWSDL(NO_BODY_PARTS_WSDL_PATH, 0);
    QName messageName = new QName("urn:org:apache:cxf:no_body_parts/wsdl", "operation1Request");
    MessageInfo mi = serviceInfo.getMessage(messageName);
    QName partName = new QName("urn:org:apache:cxf:no_body_parts/wsdl", "mimeAttachment");
    MessagePartInfo pi = mi.getMessagePart(partName);
    QName typeName = new QName("http://www.w3.org/2001/XMLSchema", "base64Binary");
    assertEquals(typeName, pi.getTypeQName());
    assertNull(pi.getElementQName());
}
Also used : QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Test(org.junit.Test)

Example 83 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class WSDLServiceBuilderTest method doDiffPortTypeNsImport.

private void doDiffPortTypeNsImport() {
    if (serviceInfo.getName().getLocalPart().endsWith("Rpc")) {
        String ns = serviceInfo.getInterface().getName().getNamespaceURI();
        OperationInfo oi = serviceInfo.getInterface().getOperation(new QName(ns, "NewOperationRpc"));
        assertNotNull(oi);
        ns = oi.getInput().getName().getNamespaceURI();
        MessagePartInfo mpi = oi.getInput().getMessagePart(new QName(ns, "NewOperationRequestRpc"));
        assertNotNull(mpi);
    } else {
        String ns = serviceInfo.getInterface().getName().getNamespaceURI();
        OperationInfo oi = serviceInfo.getInterface().getOperation(new QName(ns, "NewOperation"));
        assertNotNull(oi);
        ns = oi.getInput().getName().getNamespaceURI();
        MessagePartInfo mpi = oi.getInput().getMessagePart(new QName(ns, "NewOperationRequest"));
        assertNotNull(mpi);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 84 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class WSDLServiceBuilderTest method testParameterOrder.

@Test
public void testParameterOrder() throws Exception {
    String ns = "http://apache.org/hello_world_xml_http/bare";
    setUpWSDL("hello_world_xml_bare.wsdl", 0);
    OperationInfo operation = serviceInfo.getInterface().getOperation(new QName(ns, "testTriPart"));
    assertNotNull(operation);
    List<MessagePartInfo> parts = operation.getInput().getMessageParts();
    assertNotNull(parts);
    assertEquals(3, parts.size());
    assertEquals("in3", parts.get(0).getName().getLocalPart());
    assertEquals("in1", parts.get(1).getName().getLocalPart());
    assertEquals("in2", parts.get(2).getName().getLocalPart());
    List<String> order = operation.getParameterOrdering();
    assertNotNull(order);
    assertEquals(3, order.size());
    assertEquals("in1", order.get(0));
    assertEquals("in3", order.get(1));
    assertEquals("in2", order.get(2));
    parts = operation.getInput().getOrderedParts(order);
    assertNotNull(parts);
    assertEquals(3, parts.size());
    assertEquals("in1", parts.get(0).getName().getLocalPart());
    assertEquals("in3", parts.get(1).getName().getLocalPart());
    assertEquals("in2", parts.get(2).getName().getLocalPart());
    operation = serviceInfo.getInterface().getOperation(new QName(ns, "testTriPartNoOrder"));
    assertNotNull(operation);
    parts = operation.getInput().getMessageParts();
    assertNotNull(parts);
    assertEquals(3, parts.size());
    assertEquals("in3", parts.get(0).getName().getLocalPart());
    assertEquals("in1", parts.get(1).getName().getLocalPart());
    assertEquals("in2", parts.get(2).getName().getLocalPart());
    control.verify();
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Test(org.junit.Test)

Example 85 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class BareOutInterceptor method handleMessage.

public void handleMessage(Message message) {
    Exchange exchange = message.getExchange();
    BindingOperationInfo operation = exchange.getBindingOperationInfo();
    if (operation == null) {
        return;
    }
    MessageContentsList objs = MessageContentsList.getContentsList(message);
    if (objs == null || objs.isEmpty()) {
        return;
    }
    List<MessagePartInfo> parts = null;
    BindingMessageInfo bmsg = null;
    boolean client = isRequestor(message);
    if (!client) {
        if (operation.getOutput() != null) {
            bmsg = operation.getOutput();
            parts = bmsg.getMessageParts();
        } else {
            // partial response to oneway
            return;
        }
    } else {
        bmsg = operation.getInput();
        parts = bmsg.getMessageParts();
    }
    writeParts(message, exchange, operation, objs, parts);
}
Also used : Exchange(org.apache.cxf.message.Exchange) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Aggregations

MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)157 QName (javax.xml.namespace.QName)97 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)60 OperationInfo (org.apache.cxf.service.model.OperationInfo)44 Test (org.junit.Test)38 MessageInfo (org.apache.cxf.service.model.MessageInfo)36 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)27 Service (org.apache.cxf.service.Service)21 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)21 Fault (org.apache.cxf.interceptor.Fault)20 BindingInfo (org.apache.cxf.service.model.BindingInfo)20 ArrayList (java.util.ArrayList)18 Endpoint (org.apache.cxf.endpoint.Endpoint)18 MessageContentsList (org.apache.cxf.message.MessageContentsList)18 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)16 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)15 XMLStreamReader (javax.xml.stream.XMLStreamReader)13 Exchange (org.apache.cxf.message.Exchange)13 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)12 FaultInfo (org.apache.cxf.service.model.FaultInfo)11