Search in sources :

Example 66 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList 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 67 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList 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;
    }
    final List<MessagePartInfo> parts;
    final BindingMessageInfo bmsg;
    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)

Example 68 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList in project BIMserver by opensourceBIM.

the class CustomInvoker method invoke.

@Override
protected Object invoke(Exchange exchange, Object service, Method method, List<Object> arguments) {
    if (method.getName().equals("login")) {
        MessageContentsList mcl = (MessageContentsList) super.invoke(exchange, service, method, arguments);
        String token = (String) mcl.get(0);
        exchange.getSession().put("token", token);
        return mcl;
    } else {
        return super.invoke(exchange, service, method, arguments);
    }
}
Also used : MessageContentsList(org.apache.cxf.message.MessageContentsList)

Example 69 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList in project jbossws-cxf by jbossws.

the class JBossWSInvoker method invoke.

/**
 * This overrides org.apache.cxf.jaxws.AbstractInvoker in order for using the JBoss AS target bean
 * and simplifying the business method matching
 */
@Override
public Object invoke(Exchange exchange, Object o) {
    BindingOperationInfo bop = exchange.getBindingOperationInfo();
    MethodDispatcher md = (MethodDispatcher) exchange.getService().get(MethodDispatcher.class.getName());
    List<Object> params = null;
    if (o instanceof List) {
        params = CastUtils.cast((List<?>) o);
    } else if (o != null) {
        params = new MessageContentsList(o);
    }
    final Object tb = (factory == null) ? targetBean : this.getServiceObject(exchange);
    final Method method = (bop == null) ? null : md.getMethod(bop);
    if (method == null) {
        throw Messages.MESSAGES.missingBindingOpeartionAndDispatchedMethod();
    }
    // performance optimization, adjustMethodAndParams currently looks for @UseAsyncMethod (which is expensive) and only performs actions if it's found
    final Method fm = checkForUseAsyncMethod ? adjustMethodAndParams(md.getMethod(bop), exchange, params, tb.getClass()) : method;
    return invoke(exchange, tb, fm, params);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) MessageContentsList(org.apache.cxf.message.MessageContentsList) List(java.util.List) MethodDispatcher(org.apache.cxf.service.invoker.MethodDispatcher) Method(java.lang.reflect.Method)

Aggregations

MessageContentsList (org.apache.cxf.message.MessageContentsList)69 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)24 Exchange (org.apache.cxf.message.Exchange)23 Message (org.apache.cxf.message.Message)22 Fault (org.apache.cxf.interceptor.Fault)19 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)18 ArrayList (java.util.ArrayList)14 List (java.util.List)13 Endpoint (org.apache.cxf.endpoint.Endpoint)11 MessageImpl (org.apache.cxf.message.MessageImpl)11 Response (javax.ws.rs.core.Response)10 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)10 Method (java.lang.reflect.Method)9 OperationInfo (org.apache.cxf.service.model.OperationInfo)9 XMLStreamException (javax.xml.stream.XMLStreamException)8 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)8 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)8 MessageInfo (org.apache.cxf.service.model.MessageInfo)8 Test (org.junit.Test)8 Service (org.apache.cxf.service.Service)7