Search in sources :

Example 31 with MessagePartInfo

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

the class CorbaStreamFaultOutInterceptor method setUserException.

protected void setUserException(CorbaMessage message, Throwable ex, RaisesType exType, OperationInfo opInfo, DataWriter<XMLStreamWriter> writer, ServiceInfo service) throws Exception {
    QName exIdlType = exType.getException();
    QName elName = new QName("", exIdlType.getLocalPart());
    MessagePartInfo faultPart = getFaultMessagePartInfo(opInfo, elName);
    if (faultPart == null) {
        throw new CorbaBindingException("Coulnd't find the message fault part : " + elName);
    }
    Method faultMethod = ex.getClass().getMethod("getFaultInfo");
    if (faultMethod == null) {
        return;
    }
    Object fault = faultMethod.invoke(ex);
    // one has not been created on the servant side which throws the UserException.
    if (fault == null) {
        Class<?> faultClass = faultMethod.getReturnType();
        fault = faultClass.newInstance();
    }
    CorbaFaultStreamWriter faultWriter = new CorbaFaultStreamWriter(orb, exType, message.getCorbaTypeMap(), service);
    writer.write(fault, faultPart, faultWriter);
    CorbaObjectHandler[] objs = faultWriter.getCorbaObjects();
    CorbaStreamable streamable = message.createStreamableObject(objs[0], elName);
    message.setStreamableException(streamable);
}
Also used : CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) CorbaStreamable(org.apache.cxf.binding.corba.CorbaStreamable) QName(javax.xml.namespace.QName) CorbaFaultStreamWriter(org.apache.cxf.binding.corba.runtime.CorbaFaultStreamWriter) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) Method(java.lang.reflect.Method) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 32 with MessagePartInfo

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

the class CorbaStreamFaultOutInterceptor method getFaultMessagePartInfo.

protected MessagePartInfo getFaultMessagePartInfo(OperationInfo opInfo, QName faultName) {
    Iterator<FaultInfo> faults = opInfo.getFaults().iterator();
    while (faults.hasNext()) {
        FaultInfo fault = faults.next();
        MessagePartInfo partInfo = fault.getMessageParts().get(0);
        if (partInfo.isElement() && partInfo.getElementQName().getLocalPart().equals(faultName.getLocalPart())) {
            return partInfo;
        } else if (partInfo.getTypeQName().getLocalPart().equals(faultName.getLocalPart())) {
            return partInfo;
        }
    }
    return null;
}
Also used : FaultInfo(org.apache.cxf.service.model.FaultInfo) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 33 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo 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 34 with MessagePartInfo

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

the class ColocUtil method convertSourceToObject.

public static void convertSourceToObject(Message message) {
    List<Object> content = CastUtils.cast(message.getContent(List.class));
    if (content == null || content.isEmpty()) {
        // nothing to convert
        return;
    }
    // only supporting the wrapped style for now  (one pojo <-> one source)
    Source source = (Source) content.get(0);
    DataReader<XMLStreamReader> reader = message.getExchange().getService().getDataBinding().createReader(XMLStreamReader.class);
    MessagePartInfo mpi = getMessageInfo(message).getMessagePart(0);
    XMLStreamReader streamReader = null;
    Object wrappedObject;
    try {
        streamReader = StaxUtils.createXMLStreamReader(source);
        wrappedObject = reader.read(mpi, streamReader);
    } finally {
        try {
            StaxUtils.close(streamReader);
        } catch (XMLStreamException e) {
        // Ignore
        }
    }
    MessageContentsList parameters = new MessageContentsList();
    parameters.put(mpi, wrappedObject);
    message.setContent(List.class, parameters);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) MessageContentsList(org.apache.cxf.message.MessageContentsList) MessageContentsList(org.apache.cxf.message.MessageContentsList) List(java.util.List) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 35 with MessagePartInfo

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

the class ColocUtil method isSameMessageInfo.

public static boolean isSameMessageInfo(MessageInfo mi1, MessageInfo mi2) {
    if ((mi1 == null && mi2 != null) || (mi1 != null && mi2 == null)) {
        return false;
    }
    if (mi1 != null && mi2 != null) {
        List<MessagePartInfo> mpil1 = mi1.getMessageParts();
        List<MessagePartInfo> mpil2 = mi2.getMessageParts();
        if (mpil1.size() != mpil2.size()) {
            return false;
        }
        int idx = 0;
        for (MessagePartInfo mpi1 : mpil1) {
            MessagePartInfo mpi2 = mpil2.get(idx);
            if (!mpi1.getTypeClass().equals(mpi2.getTypeClass())) {
                return false;
            }
            ++idx;
        }
    }
    return true;
}
Also used : MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint)

Aggregations

MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)163 QName (javax.xml.namespace.QName)99 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)60 OperationInfo (org.apache.cxf.service.model.OperationInfo)46 MessageInfo (org.apache.cxf.service.model.MessageInfo)38 Test (org.junit.Test)38 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)29 Fault (org.apache.cxf.interceptor.Fault)21 Service (org.apache.cxf.service.Service)21 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)21 BindingInfo (org.apache.cxf.service.model.BindingInfo)20 ArrayList (java.util.ArrayList)19 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)13 Method (java.lang.reflect.Method)12