Search in sources :

Example 96 with OperationInfo

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

the class ColocOutInterceptorTest method testColocOutIsColocatedPropertySet.

@Test
public void testColocOutIsColocatedPropertySet() throws Exception {
    colocOut = new TestColocOutInterceptor1();
    Bus bus = setupBus();
    ServerRegistry sr = control.createMock(ServerRegistry.class);
    EasyMock.expect(bus.getExtension(ServerRegistry.class)).andReturn(sr);
    // Funtion Param
    Server s1 = control.createMock(Server.class);
    List<Server> list = new ArrayList<>();
    list.add(s1);
    Endpoint sep = control.createMock(Endpoint.class);
    ex.put(Endpoint.class, sep);
    QName op = new QName("E", "F");
    QName intf = new QName("G", "H");
    BindingInfo sbi = control.createMock(BindingInfo.class);
    ServiceInfo ssi = new ServiceInfo();
    InterfaceInfo sii = new InterfaceInfo(ssi, intf);
    sii.addOperation(op);
    OperationInfo soi = sii.getOperation(op);
    ServiceInfo rsi = new ServiceInfo();
    InterfaceInfo rii = new InterfaceInfo(rsi, intf);
    rii.addOperation(op);
    OperationInfo roi = rii.getOperation(op);
    BindingOperationInfo sboi = control.createMock(BindingOperationInfo.class);
    BindingOperationInfo rboi = control.createMock(BindingOperationInfo.class);
    ex.put(BindingOperationInfo.class, sboi);
    // Local var
    Service ses = control.createMock(Service.class);
    EndpointInfo sei = control.createMock(EndpointInfo.class);
    Endpoint rep = control.createMock(Endpoint.class);
    Service res = control.createMock(Service.class);
    BindingInfo rbi = control.createMock(BindingInfo.class);
    EndpointInfo rei = control.createMock(EndpointInfo.class);
    EasyMock.expect(sr.getServers()).andReturn(list);
    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).anyTimes();
    EasyMock.expect(sboi.getOperationInfo()).andReturn(soi);
    EasyMock.expect(rboi.getName()).andReturn(op).anyTimes();
    EasyMock.expect(rboi.getOperationInfo()).andReturn(roi);
    EasyMock.expect(rbi.getOperation(op)).andReturn(rboi);
    InterceptorChain chain = control.createMock(InterceptorChain.class);
    msg.setInterceptorChain(chain);
    EasyMock.expect(sboi.getBinding()).andReturn(sbi);
    EasyMock.expect(sbi.getInterface()).andReturn(sii);
    control.replay();
    colocOut.handleMessage(msg);
    assertEquals("COLOCATED property should be set", Boolean.TRUE, msg.get(COLOCATED));
    assertEquals("Message.WSDL_OPERATION property should be set", op, msg.get(Message.WSDL_OPERATION));
    assertEquals("Message.WSDL_INTERFACE property should be set", intf, msg.get(Message.WSDL_INTERFACE));
    control.verify();
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Server(org.apache.cxf.endpoint.Server) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) Service(org.apache.cxf.service.Service) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Endpoint(org.apache.cxf.endpoint.Endpoint) BindingInfo(org.apache.cxf.service.model.BindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) Test(org.junit.Test)

Example 97 with OperationInfo

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

the class ColocUtilTest method testIsSameMessageInfo.

@Test
public void testIsSameMessageInfo() {
    OperationInfo oi = control.createMock(OperationInfo.class);
    boolean match = ColocUtil.isSameMessageInfo(null, null);
    assertEquals("Should return true", true, match);
    QName mn1 = new QName("A", "B");
    QName mn2 = new QName("C", "D");
    MessageInfo mi1 = new MessageInfo(oi, MessageInfo.Type.INPUT, mn1);
    MessageInfo mi2 = new MessageInfo(oi, MessageInfo.Type.INPUT, mn2);
    match = ColocUtil.isSameMessageInfo(mi1, null);
    assertEquals("Should not find a match", false, match);
    match = ColocUtil.isSameMessageInfo(null, mi2);
    assertEquals("Should not find a match", false, match);
    MessagePartInfo mpi = new MessagePartInfo(new QName("", "B"), null);
    mpi.setTypeClass(InHeaderT.class);
    mi1.addMessagePart(mpi);
    mpi = new MessagePartInfo(new QName("", "D"), null);
    mpi.setTypeClass(OutHeaderT.class);
    mi2.addMessagePart(mpi);
    match = ColocUtil.isSameMessageInfo(mi1, mi2);
    assertEquals("Should not find a match", false, match);
    mpi.setTypeClass(InHeaderT.class);
    match = ColocUtil.isSameMessageInfo(mi1, mi2);
    assertEquals("Should find a match", true, match);
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) Test(org.junit.Test)

Example 98 with OperationInfo

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

the class CorbaStreamFaultInInterceptor method handleMessage.

public void handleMessage(Message msg) {
    CorbaMessage message = (CorbaMessage) msg;
    try {
        SystemException sysEx = message.getSystemException();
        if (sysEx != null) {
            message.setContent(Exception.class, sysEx);
            return;
        }
        CorbaStreamable exStreamable = message.getStreamableException();
        if (exStreamable != null) {
            DataReader<XMLStreamReader> reader = getDataReader(message);
            BindingOperationInfo bopInfo = message.getExchange().getBindingOperationInfo();
            OperationInfo opInfo = bopInfo.getOperationInfo();
            ServiceInfo service = message.getExchange().getEndpoint().getEndpointInfo().getService();
            org.omg.CORBA.ORB orb = (org.omg.CORBA.ORB) message.get(CorbaConstants.ORB);
            if (orb == null) {
                orb = message.getExchange().get(org.omg.CORBA.ORB.class);
            }
            QName elName = new QName("", exStreamable.getName());
            FaultInfo fault = getFaultInfo(opInfo, elName);
            CorbaTypeEventProducer faultEventProducer = CorbaHandlerUtils.getTypeEventProducer(exStreamable.getObject(), service, orb);
            CorbaStreamReader streamReader = new CorbaStreamReader(faultEventProducer);
            Object e = reader.read(fault.getMessageParts().get(0), streamReader);
            if (!(e instanceof Exception)) {
                Class<?> exClass = fault.getProperty(Class.class.getName(), Class.class);
                if (exClass != null) {
                    Class<?> beanClass = e.getClass();
                    Constructor<?> constructor = exClass.getConstructor(new Class[] { String.class, beanClass });
                    String repId = (message.getStreamableException()._type().id() != null) ? message.getStreamableException()._type().id() : "";
                    e = constructor.newInstance(new Object[] { repId, e });
                } else {
                    // Get the Fault
                    Fault faultEx = (Fault) message.getContent(Exception.class);
                    if (e instanceof Document) {
                        createFaultDetail((Document) e, fault, faultEx);
                    }
                    e = faultEx;
                }
            }
            message.setContent(Exception.class, e);
        }
    } catch (java.lang.Exception ex) {
        LOG.log(Level.SEVERE, "CORBA unmarshalFault exception", ex);
        throw new CorbaBindingException("CORBA unmarshalFault exception", ex);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) Fault(org.apache.cxf.interceptor.Fault) Document(org.w3c.dom.Document) CorbaStreamReader(org.apache.cxf.binding.corba.runtime.CorbaStreamReader) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) SystemException(org.omg.CORBA.SystemException) CorbaTypeEventProducer(org.apache.cxf.binding.corba.types.CorbaTypeEventProducer) CorbaStreamable(org.apache.cxf.binding.corba.CorbaStreamable) CorbaMessage(org.apache.cxf.binding.corba.CorbaMessage) QName(javax.xml.namespace.QName) SystemException(org.omg.CORBA.SystemException) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException)

Example 99 with OperationInfo

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

the class CorbaStreamFaultOutInterceptor method handleMessage.

public void handleMessage(Message msg) {
    CorbaMessage message = (CorbaMessage) msg;
    Exchange exchange = message.getExchange();
    CorbaDestination destination;
    Fault faultEx = null;
    if (message.getDestination() != null) {
        destination = (CorbaDestination) message.getDestination();
    } else {
        destination = (CorbaDestination) exchange.getDestination();
    }
    orb = (ORB) message.get(CorbaConstants.ORB);
    if (orb == null) {
        orb = exchange.get(ORB.class);
    }
    DataWriter<XMLStreamWriter> writer = getDataWriter(message);
    Throwable ex = message.getContent(Exception.class);
    // is a Fault instance and contains a detail object.
    if (ex.getCause() == null) {
        if ((ex instanceof Fault) && (((Fault) ex).getDetail() != null)) {
            faultEx = (Fault) ex;
        } else {
            throw new CorbaBindingException(ex);
        }
    } else {
        ex = ex.getCause();
    }
    if (ex instanceof InvocationTargetException) {
        ex = ex.getCause();
    }
    if (ex instanceof SystemException) {
        setSystemException(message, ex, destination);
        return;
    }
    String exClassName = null;
    if (faultEx == null) {
        // REVISIT, we should not have to depend on WebFault annotation
        // Try changing the fault name to the proper mangled java exception classname.
        WebFault fault = ex.getClass().getAnnotation(WebFault.class);
        if (fault == null) {
            throw new CorbaBindingException(ex);
        }
        exClassName = fault.name();
    } else {
        // JCGS: exClassName to be set to the exception name
        Element faultElement = (Element) faultEx.getDetail().getFirstChild();
        exClassName = faultElement.getLocalName();
    }
    // Get information about the operation being invoked from the WSDL
    // definition.
    // We need this to marshal data correctly
    BindingInfo bInfo = destination.getBindingInfo();
    String opName = message.getExchange().get(String.class);
    Iterator<BindingOperationInfo> iter = bInfo.getOperations().iterator();
    BindingOperationInfo bopInfo = null;
    OperationType opType = null;
    while (iter.hasNext()) {
        bopInfo = iter.next();
        if (bopInfo.getName().getLocalPart().equals(opName)) {
            opType = bopInfo.getExtensor(OperationType.class);
            break;
        }
    }
    if (opType == null) {
        throw new CorbaBindingException("Unable to find binding operation for " + opName);
    }
    OperationInfo opInfo = bopInfo.getOperationInfo();
    if (faultEx != null) {
        MessagePartInfo partInfo = getFaultMessagePartInfo(opInfo, new QName("", exClassName));
        if (partInfo != null) {
            exClassName = partInfo.getTypeQName().getLocalPart();
        }
    }
    RaisesType exType = getRaisesType(opType, exClassName, ex);
    try {
        if (exType != null) {
            if (faultEx != null) {
                setUserExceptionFromFaultDetail(message, faultEx.getDetail(), exType, opInfo, writer, exchange.getEndpoint().getEndpointInfo().getService());
            } else {
                setUserException(message, ex, exType, opInfo, writer, exchange.getEndpoint().getEndpointInfo().getService());
            }
        } else {
            throw new CorbaBindingException(ex);
        }
    } catch (Exception exp) {
        throw new CorbaBindingException(exp);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) CorbaMessage(org.apache.cxf.binding.corba.CorbaMessage) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Fault(org.apache.cxf.interceptor.Fault) WebFault(javax.xml.ws.WebFault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException) SystemException(org.omg.CORBA.SystemException) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Exchange(org.apache.cxf.message.Exchange) WebFault(javax.xml.ws.WebFault) CorbaDestination(org.apache.cxf.binding.corba.CorbaDestination) RaisesType(org.apache.cxf.binding.corba.wsdl.RaisesType) SystemException(org.omg.CORBA.SystemException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) BindingInfo(org.apache.cxf.service.model.BindingInfo) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType) ORB(org.omg.CORBA.ORB)

Example 100 with OperationInfo

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

the class CorbaStreamInInterceptor method prepareDIIArgsList.

protected NVList prepareDIIArgsList(CorbaMessage corbaMsg, BindingOperationInfo boi, CorbaStreamable[] streamables, List<ParamType> paramTypes, CorbaTypeMap map, ORB orb, ServiceInfo service) {
    try {
        // Build the list of DII arguments, returns, and exceptions
        NVList list = orb.create_list(streamables.length);
        OperationInfo opInfo = boi.getOperationInfo();
        MessageInfo input = opInfo.getInput();
        MessageInfo output = opInfo.getOutput();
        String inWrapNSUri = null;
        String outWrapNSUri = null;
        boolean wrap = false;
        if (boi.isUnwrappedCapable()) {
            wrap = true;
            if (input != null) {
                inWrapNSUri = getWrappedParamNamespace(input);
                if (!CorbaUtils.isElementFormQualified(service, inWrapNSUri)) {
                    inWrapNSUri = "";
                }
            }
            if (output != null) {
                outWrapNSUri = getWrappedParamNamespace(output);
                if (!CorbaUtils.isElementFormQualified(service, outWrapNSUri)) {
                    outWrapNSUri = "";
                }
            }
        }
        int inMsgIndex = 0;
        int outMsgIndex = 0;
        for (int i = 0; i < paramTypes.size(); i++) {
            ParamType param = paramTypes.get(i);
            QName paramIdlType = param.getIdltype();
            QName paramName;
            ModeType paramMode = param.getMode();
            if (paramMode.value().equals("in")) {
                if (wrap) {
                    paramName = new QName(inWrapNSUri, param.getName());
                } else {
                    paramName = getMessageParamQName(input, param.getName(), inMsgIndex);
                    inMsgIndex++;
                }
            } else {
                if (wrap) {
                    paramName = new QName(outWrapNSUri, param.getName());
                } else {
                    paramName = getMessageParamQName(output, param.getName(), outMsgIndex);
                    outMsgIndex++;
                }
            }
            CorbaObjectHandler obj = CorbaHandlerUtils.initializeObjectHandler(orb, paramName, paramIdlType, map, service);
            streamables[i] = corbaMsg.createStreamableObject(obj, paramName);
            Any value = CorbaAnyHelper.createAny(orb);
            if (paramMode.value().equals("in")) {
                streamables[i].setMode(org.omg.CORBA.ARG_IN.value);
                streamables[i].getObject().setIntoAny(value, streamables[i], false);
            } else if (paramMode.value().equals("out")) {
                streamables[i].setMode(org.omg.CORBA.ARG_OUT.value);
                streamables[i].getObject().setIntoAny(value, streamables[i], true);
            } else {
                streamables[i].setMode(org.omg.CORBA.ARG_INOUT.value);
                streamables[i].getObject().setIntoAny(value, streamables[i], false);
            }
            list.add_value(streamables[i].getName(), value, streamables[i].getMode());
            corbaMsg.addStreamableArgument(streamables[i]);
        }
        return list;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) QName(javax.xml.namespace.QName) Any(org.omg.CORBA.Any) Endpoint(org.apache.cxf.endpoint.Endpoint) ParamType(org.apache.cxf.binding.corba.wsdl.ParamType) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) ModeType(org.apache.cxf.binding.corba.wsdl.ModeType) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) NVList(org.omg.CORBA.NVList)

Aggregations

OperationInfo (org.apache.cxf.service.model.OperationInfo)135 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)87 QName (javax.xml.namespace.QName)58 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)44 MessageInfo (org.apache.cxf.service.model.MessageInfo)40 Test (org.junit.Test)38 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)36 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)31 Method (java.lang.reflect.Method)25 Endpoint (org.apache.cxf.endpoint.Endpoint)24 Service (org.apache.cxf.service.Service)22 BindingInfo (org.apache.cxf.service.model.BindingInfo)21 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)19 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)17 Exchange (org.apache.cxf.message.Exchange)17 ArrayList (java.util.ArrayList)13 UnwrappedOperationInfo (org.apache.cxf.service.model.UnwrappedOperationInfo)13 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)12 Fault (org.apache.cxf.interceptor.Fault)10 Message (org.apache.cxf.message.Message)10