Search in sources :

Example 51 with Exchange

use of org.apache.cxf.message.Exchange in project cxf by apache.

the class DocLiteralInInterceptor method handleMessage.

public void handleMessage(Message message) {
    if (isGET(message) && message.getContent(List.class) != null) {
        LOG.fine("DocLiteralInInterceptor skipped in HTTP GET method");
        return;
    }
    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    MessageContentsList parameters = new MessageContentsList();
    Exchange exchange = message.getExchange();
    BindingOperationInfo bop = exchange.getBindingOperationInfo();
    boolean client = isRequestor(message);
    // operation anymore, just return
    if (bop != null && !StaxUtils.toNextElement(xmlReader)) {
        // body may be empty for partial response to decoupled request
        return;
    }
    Service service = ServiceModelUtil.getService(message.getExchange());
    bop = getBindingOperationInfo(xmlReader, exchange, bop, client);
    boolean forceDocLitBare = false;
    if (bop != null && bop.getBinding() != null) {
        forceDocLitBare = Boolean.TRUE.equals(bop.getBinding().getService().getProperty("soap.force.doclit.bare"));
    }
    DataReader<XMLStreamReader> dr = getDataReader(message);
    try {
        if (!forceDocLitBare && bop != null && bop.isUnwrappedCapable()) {
            ServiceInfo si = bop.getBinding().getService();
            // Wrapped case
            MessageInfo msgInfo = setMessage(message, bop, client, si);
            setDataReaderValidation(service, message, dr);
            // Determine if we should keep the parameters wrapper
            if (shouldWrapParameters(msgInfo, message)) {
                QName startQName = xmlReader.getName();
                MessagePartInfo mpi = msgInfo.getFirstMessagePart();
                if (!mpi.getConcreteName().equals(startQName)) {
                    throw new Fault("UNEXPECTED_WRAPPER_ELEMENT", LOG, null, startQName, mpi.getConcreteName());
                }
                Object wrappedObject = dr.read(mpi, xmlReader);
                parameters.put(mpi, wrappedObject);
            } else {
                // Unwrap each part individually if we don't have a wrapper
                bop = bop.getUnwrappedOperation();
                msgInfo = setMessage(message, bop, client, si);
                List<MessagePartInfo> messageParts = msgInfo.getMessageParts();
                Iterator<MessagePartInfo> itr = messageParts.iterator();
                // stuck
                if (xmlReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
                    StaxUtils.nextEvent(xmlReader);
                }
                // loop through each child element
                getPara(xmlReader, dr, parameters, itr, message);
            }
        } else {
            // Bare style
            BindingMessageInfo msgInfo = null;
            Endpoint ep = exchange.getEndpoint();
            ServiceInfo si = ep.getEndpointInfo().getService();
            if (bop != null) {
                // for xml binding or client side
                if (client) {
                    msgInfo = bop.getOutput();
                } else {
                    msgInfo = bop.getInput();
                    if (bop.getOutput() == null) {
                        exchange.setOneWay(true);
                    }
                }
                if (msgInfo == null) {
                    return;
                }
                setMessage(message, bop, client, si, msgInfo.getMessageInfo());
            }
            Collection<OperationInfo> operations = null;
            operations = new ArrayList<>();
            operations.addAll(si.getInterface().getOperations());
            if (xmlReader == null || !StaxUtils.toNextElement(xmlReader)) {
                // empty input
                getBindingOperationForEmptyBody(operations, ep, exchange);
                return;
            }
            setDataReaderValidation(service, message, dr);
            int paramNum = 0;
            do {
                QName elName = xmlReader.getName();
                Object o = null;
                MessagePartInfo p;
                if (!client && msgInfo != null && msgInfo.getMessageParts() != null && msgInfo.getMessageParts().isEmpty()) {
                    // no input messagePartInfo
                    return;
                }
                if (msgInfo != null && msgInfo.getMessageParts() != null && msgInfo.getMessageParts().size() > 0) {
                    if (msgInfo.getMessageParts().size() > paramNum) {
                        p = msgInfo.getMessageParts().get(paramNum);
                    } else {
                        p = null;
                    }
                } else {
                    p = findMessagePart(exchange, operations, elName, client, paramNum, message);
                }
                if (!forceDocLitBare) {
                    // Make sure the elName found on the wire is actually OK for
                    // the purpose we need it
                    validatePart(p, elName, message);
                }
                o = dr.read(p, xmlReader);
                if (forceDocLitBare && parameters.isEmpty()) {
                    // webservice provider does not need to ensure size
                    parameters.add(o);
                } else {
                    parameters.put(p, o);
                }
                paramNum++;
                if (message.getContent(XMLStreamReader.class) == null || o == xmlReader) {
                    xmlReader = null;
                }
            } while (xmlReader != null && StaxUtils.toNextElement(xmlReader));
        }
        message.setContent(List.class, parameters);
    } catch (Fault f) {
        if (!isRequestor(message)) {
            f.setFaultCode(Fault.FAULT_CODE_CLIENT);
        }
        throw f;
    }
}
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) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessageContentsList(org.apache.cxf.message.MessageContentsList) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Exchange(org.apache.cxf.message.Exchange) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 52 with Exchange

use of org.apache.cxf.message.Exchange in project cxf by apache.

the class ColocMessageObserverTest method testObserverOnMessage.

@Test
public void testObserverOnMessage() throws Exception {
    msg.setExchange(ex);
    Binding binding = control.createMock(Binding.class);
    EasyMock.expect(ep.getBinding()).andReturn(binding);
    Message inMsg = new MessageImpl();
    EasyMock.expect(binding.createMessage()).andReturn(inMsg);
    EasyMock.expect(ep.getService()).andReturn(srv).anyTimes();
    EasyMock.expect(bus.getExtension(PhaseManager.class)).andReturn(new PhaseManagerImpl()).times(2);
    EasyMock.expect(bus.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>());
    EasyMock.expect(ep.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>());
    EasyMock.expect(srv.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>());
    EasyMock.expect(bus.getExtension(ClassLoader.class)).andReturn(this.getClass().getClassLoader());
    control.replay();
    observer = new TestColocMessageObserver(ep, bus);
    observer.onMessage(msg);
    control.verify();
    Exchange inEx = inMsg.getExchange();
    assertNotNull("Should Have a valid Exchange", inEx);
    assertEquals("Message.REQUESTOR_ROLE should be false", Boolean.FALSE, inMsg.get(Message.REQUESTOR_ROLE));
    assertEquals("Message.INBOUND_MESSAGE should be true", Boolean.TRUE, inMsg.get(Message.INBOUND_MESSAGE));
    assertNotNull("Chain should be set", inMsg.getInterceptorChain());
    Exchange ex1 = msg.getExchange();
    assertNotNull("Exchange should be set", ex1);
}
Also used : Binding(org.apache.cxf.binding.Binding) Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) PhaseManager(org.apache.cxf.phase.PhaseManager) MessageImpl(org.apache.cxf.message.MessageImpl) PhaseManagerImpl(org.apache.cxf.bus.managers.PhaseManagerImpl) Interceptor(org.apache.cxf.interceptor.Interceptor) Test(org.junit.Test)

Example 53 with Exchange

use of org.apache.cxf.message.Exchange in project cxf by apache.

the class ColocUtilTest method testGetOutInterceptorChain.

@Test
public void testGetOutInterceptorChain() throws Exception {
    PhaseManagerImpl phaseMgr = new PhaseManagerImpl();
    SortedSet<Phase> list = phaseMgr.getInPhases();
    ColocUtil.setPhases(list, Phase.SETUP, Phase.POST_LOGICAL);
    Endpoint ep = control.createMock(Endpoint.class);
    Service srv = control.createMock(Service.class);
    Exchange ex = new ExchangeImpl();
    ex.put(Bus.class, bus);
    ex.put(Endpoint.class, ep);
    ex.put(Service.class, srv);
    EasyMock.expect(ep.getOutInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
    EasyMock.expect(ep.getService()).andReturn(srv).atLeastOnce();
    EasyMock.expect(srv.getOutInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
    EasyMock.expect(bus.getOutInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
    control.replay();
    InterceptorChain chain = ColocUtil.getOutInterceptorChain(ex, list);
    control.verify();
    assertNotNull("Should have chain instance", chain);
    Iterator<Interceptor<? extends Message>> iter = chain.iterator();
    assertEquals("Should not have interceptors in chain", false, iter.hasNext());
}
Also used : Exchange(org.apache.cxf.message.Exchange) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Phase(org.apache.cxf.phase.Phase) Endpoint(org.apache.cxf.endpoint.Endpoint) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) PhaseManagerImpl(org.apache.cxf.bus.managers.PhaseManagerImpl) Interceptor(org.apache.cxf.interceptor.Interceptor) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 54 with Exchange

use of org.apache.cxf.message.Exchange in project cxf by apache.

the class ColocUtilTest method testGetInInterceptorChain.

@Test
public void testGetInInterceptorChain() throws Exception {
    PhaseManagerImpl phaseMgr = new PhaseManagerImpl();
    SortedSet<Phase> list = phaseMgr.getInPhases();
    ColocUtil.setPhases(list, Phase.SETUP, Phase.POST_LOGICAL);
    Endpoint ep = control.createMock(Endpoint.class);
    Service srv = control.createMock(Service.class);
    Exchange ex = new ExchangeImpl();
    ex.put(Bus.class, bus);
    ex.put(Endpoint.class, ep);
    ex.put(Service.class, srv);
    EasyMock.expect(bus.getExtension(PhaseManager.class)).andReturn(phaseMgr);
    EasyMock.expect(ep.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
    EasyMock.expect(ep.getService()).andReturn(srv).atLeastOnce();
    EasyMock.expect(srv.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
    EasyMock.expect(bus.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
    control.replay();
    InterceptorChain chain = ColocUtil.getInInterceptorChain(ex, list);
    control.verify();
    assertNotNull("Should have chain instance", chain);
    Iterator<Interceptor<? extends Message>> iter = chain.iterator();
    assertEquals("Should not have interceptors in chain", false, iter.hasNext());
    assertNotNull("OutFaultObserver should be set", chain.getFaultObserver());
}
Also used : Exchange(org.apache.cxf.message.Exchange) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Phase(org.apache.cxf.phase.Phase) Endpoint(org.apache.cxf.endpoint.Endpoint) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) PhaseManagerImpl(org.apache.cxf.bus.managers.PhaseManagerImpl) Interceptor(org.apache.cxf.interceptor.Interceptor) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 55 with Exchange

use of org.apache.cxf.message.Exchange in project cxf by apache.

the class CorbaServerConduit method buildRequestResult.

public void buildRequestResult(CorbaMessage msg) {
    Exchange exg = msg.getExchange();
    ServerRequest request = exg.get(ServerRequest.class);
    try {
        if (!exg.isOneWay()) {
            CorbaMessage inMsg = (CorbaMessage) msg.getExchange().getInMessage();
            NVList list = inMsg.getList();
            if (msg.getStreamableException() != null) {
                Any exAny = CorbaAnyHelper.createAny(orb);
                CorbaStreamable exception = msg.getStreamableException();
                exAny.insert_Streamable(exception);
                request.set_exception(exAny);
                if (msg.getExchange() != null) {
                    msg.getExchange().setOutFaultMessage(msg);
                }
            } else {
                CorbaStreamable[] arguments = msg.getStreamableArguments();
                if (arguments != null) {
                    for (int i = 0; i < arguments.length; ++i) {
                        if (list.item(i).flags() != org.omg.CORBA.ARG_IN.value) {
                            arguments[i].getObject().setIntoAny(list.item(i).value(), arguments[i], true);
                        }
                    }
                }
                CorbaStreamable resultValue = msg.getStreamableReturn();
                if (resultValue != null) {
                    Any resultAny = CorbaAnyHelper.createAny(orb);
                    resultValue.getObject().setIntoAny(resultAny, resultValue, true);
                    request.set_result(resultAny);
                }
            }
        }
    } catch (java.lang.Exception ex) {
        throw new CorbaBindingException("Exception during buildRequestResult", ex);
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) ServerRequest(org.omg.CORBA.ServerRequest) NVList(org.omg.CORBA.NVList) Any(org.omg.CORBA.Any)

Aggregations

Exchange (org.apache.cxf.message.Exchange)272 Message (org.apache.cxf.message.Message)151 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)131 MessageImpl (org.apache.cxf.message.MessageImpl)118 Test (org.junit.Test)93 Endpoint (org.apache.cxf.endpoint.Endpoint)66 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)50 QName (javax.xml.namespace.QName)42 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)33 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)32 Bus (org.apache.cxf.Bus)30 Fault (org.apache.cxf.interceptor.Fault)27 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)26 IOException (java.io.IOException)25 ArrayList (java.util.ArrayList)25 Conduit (org.apache.cxf.transport.Conduit)25 MessageContentsList (org.apache.cxf.message.MessageContentsList)22 SOAPMessage (javax.xml.soap.SOAPMessage)19 XMLStreamReader (javax.xml.stream.XMLStreamReader)19 ServerProviderFactory (org.apache.cxf.jaxrs.provider.ServerProviderFactory)19