Search in sources :

Example 11 with MessageInfo

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

the class ColocOutInterceptorTest method verifyIsColocatedWithCompatibleOperation.

private void verifyIsColocatedWithCompatibleOperation() {
    colocOut = new TestColocOutInterceptor1();
    // Funtion Param
    Server s1 = control.createMock(Server.class);
    List<Server> list = new ArrayList<>();
    list.add(s1);
    Endpoint sep = control.createMock(Endpoint.class);
    BindingOperationInfo sboi = control.createMock(BindingOperationInfo.class);
    // Local var
    Service ses = control.createMock(Service.class);
    EndpointInfo sei = control.createMock(EndpointInfo.class);
    BindingInfo rbi = control.createMock(BindingInfo.class);
    Endpoint rep = control.createMock(Endpoint.class);
    Service res = control.createMock(Service.class);
    EndpointInfo rei = control.createMock(EndpointInfo.class);
    BindingOperationInfo rboi = control.createMock(BindingOperationInfo.class);
    QName op = new QName("E", "F");
    QName intf = new QName("G", "H");
    QName inmi = new QName("M", "in");
    QName outmi = new QName("M", "out");
    ServiceInfo ssi = new ServiceInfo();
    InterfaceInfo sii = new InterfaceInfo(ssi, intf);
    sii.addOperation(op);
    OperationInfo soi = sii.getOperation(op);
    MessageInfo mii = new MessageInfo(soi, MessageInfo.Type.INPUT, inmi);
    MessagePartInfo mpi = mii.addMessagePart("parameters");
    mpi.setTypeClass(Source.class);
    MessageInfo mio = new MessageInfo(soi, MessageInfo.Type.OUTPUT, outmi);
    mpi = mio.addMessagePart("parameters");
    mpi.setTypeClass(Source.class);
    soi.setInput("in", mii);
    soi.setOutput("out", mio);
    ServiceInfo rsi = new ServiceInfo();
    InterfaceInfo rii = new InterfaceInfo(rsi, intf);
    rii.addOperation(op);
    OperationInfo roi = rii.getOperation(op);
    mii = new MessageInfo(roi, MessageInfo.Type.INPUT, inmi);
    mpi = mii.addMessagePart("parameters");
    mpi.setTypeClass(Object.class);
    mio = new MessageInfo(roi, MessageInfo.Type.OUTPUT, outmi);
    mpi = mio.addMessagePart("parameters");
    mpi.setTypeClass(Object.class);
    roi.setInput("in", mii);
    roi.setOutput("out", mio);
    EasyMock.expect(sep.getService()).andReturn(ses);
    EasyMock.expect(sep.getEndpointInfo()).andReturn(sei);
    EasyMock.expect(s1.getEndpoint()).andReturn(rep);
    EasyMock.expect(rep.getService()).andReturn(res);
    EasyMock.expect(rep.getEndpointInfo()).andReturn(rei);
    EasyMock.expect(ses.getName()).andReturn(new QName("A", "B"));
    EasyMock.expect(res.getName()).andReturn(new QName("A", "B"));
    EasyMock.expect(rei.getName()).andReturn(new QName("C", "D"));
    EasyMock.expect(sei.getName()).andReturn(new QName("C", "D"));
    EasyMock.expect(rei.getBinding()).andReturn(rbi);
    EasyMock.expect(sboi.getName()).andReturn(op);
    EasyMock.expect(sboi.getOperationInfo()).andReturn(soi);
    EasyMock.expect(rboi.getName()).andReturn(op);
    EasyMock.expect(rboi.getOperationInfo()).andReturn(roi);
    EasyMock.expect(rbi.getOperation(op)).andReturn(rboi);
    control.replay();
    Server val = colocOut.isColocated(list, sep, sboi);
    assertEquals("Expecting a colocated call", s1, val);
    control.reset();
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Server(org.apache.cxf.endpoint.Server) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) 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) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo)

Example 12 with MessageInfo

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

the class RPCInInterceptor method handleMessage.

public void handleMessage(Message message) {
    if (isGET(message)) {
        LOG.fine("RPCInInterceptor skipped in HTTP GET method");
        return;
    }
    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    if (!StaxUtils.toNextElement(xmlReader)) {
        message.setContent(Exception.class, new RuntimeException("There must be a method name element."));
    }
    String opName = xmlReader.getLocalName();
    if (isRequestor(message) && opName.endsWith("Response")) {
        opName = opName.substring(0, opName.length() - 8);
    }
    final BindingOperationInfo operation;
    if (message.getExchange().getBindingOperationInfo() == null) {
        operation = getOperation(message, new QName(xmlReader.getNamespaceURI(), opName));
        if (operation == null) {
            // it's doc-lit-bare
            new BareInInterceptor().handleMessage(message);
            return;
        }
        setMessage(message, operation);
    } else {
        operation = message.getExchange().getBindingOperationInfo();
        if (!operation.getName().getLocalPart().equals(opName)) {
            String sa = (String) message.get(SoapBindingConstants.SOAP_ACTION);
            throw new Fault("SOAP_ACTION_MISMATCH_OP", LOG, null, sa, opName);
        }
    }
    MessageInfo msg;
    DataReader<XMLStreamReader> dr = getDataReader(message, XMLStreamReader.class);
    if (!isRequestor(message)) {
        msg = operation.getOperationInfo().getInput();
    } else {
        msg = operation.getOperationInfo().getOutput();
    }
    message.put(MessageInfo.class, msg);
    MessageContentsList parameters = new MessageContentsList();
    StaxUtils.nextEvent(xmlReader);
    boolean hasNext = true;
    Iterator<MessagePartInfo> itr = msg.getMessageParts().iterator();
    while (itr.hasNext()) {
        MessagePartInfo part = itr.next();
        if (hasNext) {
            hasNext = StaxUtils.toNextElement(xmlReader);
        }
        if (hasNext) {
            QName qn = xmlReader.getName();
            if (qn.equals(SOAP12_RESULT)) {
                // just ignore this.   The parts should work correctly.
                try {
                    while (xmlReader.getEventType() != XMLStreamConstants.END_ELEMENT) {
                        xmlReader.next();
                    }
                    xmlReader.next();
                } catch (XMLStreamException e) {
                // ignore
                }
                StaxUtils.toNextElement(xmlReader);
                qn = xmlReader.getName();
            }
            // WSI-BP states that RPC/Lit part accessors should be completely unqualified
            // However, older toolkits (Axis 1.x) are qualifying them.   We'll go
            // ahead and just match on the localpart.   The RPCOutInterceptor
            // will always generate WSI-BP compliant messages so it's unknown if
            // the non-WSI-BP toolkits will be able to understand the CXF
            // generated messages if they are expecting it to be qualified.
            Iterator<MessagePartInfo> partItr = msg.getMessageParts().iterator();
            while (!qn.getLocalPart().equals(part.getConcreteName().getLocalPart()) && partItr.hasNext()) {
                part = partItr.next();
            }
            // only check the localpart as explained above
            if (!qn.getLocalPart().equals(part.getConcreteName().getLocalPart())) {
                throw new Fault(new org.apache.cxf.common.i18n.Message("UNKNOWN_RPC_LIT_PART", LOG, qn));
            }
            try {
                parameters.put(part, dr.read(part, xmlReader));
            } catch (Fault f) {
                if (!isRequestor(message)) {
                    f.setFaultCode(Fault.FAULT_CODE_CLIENT);
                }
                throw f;
            }
        }
    }
    message.setContent(List.class, parameters);
}
Also used : 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) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) XMLStreamException(javax.xml.stream.XMLStreamException) BareInInterceptor(org.apache.cxf.wsdl.interceptors.BareInInterceptor)

Example 13 with MessageInfo

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

the class XMLMessageOutInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
    MessageInfo mi;
    BindingMessageInfo bmi;
    if (isRequestor(message)) {
        mi = boi.getOperationInfo().getInput();
        bmi = boi.getInput();
    } else {
        mi = boi.getOperationInfo().getOutput();
        bmi = boi.getOutput();
    }
    XMLBindingMessageFormat xmf = bmi.getExtensor(XMLBindingMessageFormat.class);
    QName rootInModel = null;
    if (xmf != null) {
        rootInModel = xmf.getRootNode();
    }
    final int mpn = mi.getMessagePartsNumber();
    if (boi.isUnwrapped() || mpn == 1) {
        // wrapper out interceptor created the wrapper
        // or if bare-one-param
        new BareOutInterceptor().handleMessage(message);
    } else {
        if (rootInModel == null) {
            rootInModel = boi.getName();
        }
        if (mpn == 0 && !boi.isUnwrapped()) {
            // write empty operation qname
            writeMessage(message, rootInModel, false);
        } else {
            // multi param, bare mode, needs write root node
            writeMessage(message, rootInModel, true);
        }
    }
    // in the end we do flush ;)
    XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
    try {
        writer.flush();
    } catch (XMLStreamException e) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE, e));
    }
}
Also used : BareOutInterceptor(org.apache.cxf.wsdl.interceptors.BareOutInterceptor) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) Fault(org.apache.cxf.interceptor.Fault) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) XMLStreamException(javax.xml.stream.XMLStreamException) XMLBindingMessageFormat(org.apache.cxf.bindings.xformat.XMLBindingMessageFormat) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 14 with MessageInfo

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

the class ServiceModelVisitor method visitOperation.

private void visitOperation(OperationInfo o) {
    MessageInfo in = o.getInput();
    if (in != null) {
        begin(in);
        for (MessagePartInfo part : in.getMessageParts()) {
            begin(part);
            end(part);
        }
        end(in);
    }
    MessageInfo out = o.getOutput();
    if (out != null) {
        begin(out);
        for (MessagePartInfo part : out.getMessageParts()) {
            begin(part);
            end(part);
        }
        end(out);
    }
    for (FaultInfo f : o.getFaults()) {
        begin(f);
        for (MessagePartInfo part : f.getMessageParts()) {
            begin(part);
            end(part);
        }
        end(f);
    }
    if (o.isUnwrappedCapable()) {
        OperationInfo uop = o.getUnwrappedOperation();
        begin(uop);
        visitOperation(o.getUnwrappedOperation());
        end(uop);
    }
}
Also used : UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 15 with MessageInfo

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

the class JaxWsServiceConfigurationTest method testGetOutPartName.

@Test
public void testGetOutPartName() throws Exception {
    QName opName = new QName("http://cxf.com/", "sayHi");
    Method sayHiMethod = Hello.class.getMethod("sayHi", new Class[] {});
    ServiceInfo si = getMockedServiceModel("/wsdl/default_partname_test.wsdl");
    JaxWsServiceConfiguration jwsc = new JaxWsServiceConfiguration();
    JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    bean.setServiceClass(Hello.class);
    jwsc.setServiceFactory(bean);
    // clear the output
    OperationInfo op = si.getInterface().getOperation(opName);
    op.setOutput("output", new MessageInfo(op, MessageInfo.Type.OUTPUT, new QName("http://cxf.com/", "output")));
    QName partName = jwsc.getOutPartName(op, sayHiMethod, -1);
    assertEquals("get wrong return partName", new QName("http://cxf.com/", "return"), partName);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) QName(javax.xml.namespace.QName) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) MessageInfo(org.apache.cxf.service.model.MessageInfo) Test(org.junit.Test)

Aggregations

MessageInfo (org.apache.cxf.service.model.MessageInfo)73 QName (javax.xml.namespace.QName)42 OperationInfo (org.apache.cxf.service.model.OperationInfo)42 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)38 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)36 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)19 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)15 Test (org.junit.Test)15 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)14 Endpoint (org.apache.cxf.endpoint.Endpoint)13 Method (java.lang.reflect.Method)11 ArrayList (java.util.ArrayList)10 Service (org.apache.cxf.service.Service)9 MessageContentsList (org.apache.cxf.message.MessageContentsList)8 Fault (org.apache.cxf.interceptor.Fault)7 Exchange (org.apache.cxf.message.Exchange)7 Message (org.apache.cxf.message.Message)7 BindingInfo (org.apache.cxf.service.model.BindingInfo)7 FaultInfo (org.apache.cxf.service.model.FaultInfo)7 UnwrappedOperationInfo (org.apache.cxf.service.model.UnwrappedOperationInfo)7