Search in sources :

Example 1 with ExceptionList

use of org.omg.CORBA.ExceptionList in project cxf by apache.

the class CorbaConduit method buildRequest.

public void buildRequest(CorbaMessage message, OperationType opType) throws Exception {
    ServiceInfo service = message.getExchange().getEndpoint().getEndpointInfo().getService();
    NVList nvlist = getArguments(message);
    NamedValue ret = getReturn(message);
    Map<TypeCode, RaisesType> exceptions = getOperationExceptions(opType, typeMap);
    ExceptionList exList = getExceptionList(exceptions, message, opType);
    Request request = getRequest(message, opType.getName(), nvlist, ret, exList);
    if (request == null) {
        throw new CorbaBindingException("Couldn't build the corba request");
    }
    Exception ex;
    try {
        request.invoke();
        ex = request.env().exception();
    } catch (SystemException sysex) {
        ex = sysex;
    }
    if (ex != null) {
        if (ex instanceof SystemException) {
            message.setContent(Exception.class, new Fault(ex));
            message.setSystemException((SystemException) ex);
            return;
        }
        if (ex instanceof UnknownUserException) {
            UnknownUserException userEx = (UnknownUserException) ex;
            Any except = userEx.except;
            RaisesType raises = exceptions.get(except.type());
            if (raises == null) {
                throw new CorbaBindingException("Couldn't find the exception type code to unmarshall");
            }
            QName elName = new QName("", raises.getException().getLocalPart());
            CorbaObjectHandler handler = CorbaHandlerUtils.initializeObjectHandler(orb, elName, raises.getException(), typeMap, service);
            CorbaStreamable exStreamable = message.createStreamableObject(handler, elName);
            exStreamable._read(except.create_input_stream());
            message.setStreamableException(exStreamable);
            message.setContent(Exception.class, new Fault(userEx));
        } else {
            message.setContent(Exception.class, new Fault(ex));
        }
    }
}
Also used : TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) Request(org.omg.CORBA.Request) UnknownUserException(org.omg.CORBA.UnknownUserException) ExceptionList(org.omg.CORBA.ExceptionList) NamedValue(org.omg.CORBA.NamedValue) Fault(org.apache.cxf.interceptor.Fault) Any(org.omg.CORBA.Any) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) UnknownUserException(org.omg.CORBA.UnknownUserException) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) RaisesType(org.apache.cxf.binding.corba.wsdl.RaisesType) SystemException(org.omg.CORBA.SystemException) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) NVList(org.omg.CORBA.NVList)

Example 2 with ExceptionList

use of org.omg.CORBA.ExceptionList in project cxf by apache.

the class CorbaConduitTest method testBuildExceptionListWithExceptions.

@Test
public void testBuildExceptionListWithExceptions() throws Exception {
    CorbaConduit conduit = setupCorbaConduit(false);
    Message msg = new MessageImpl();
    CorbaMessage message = new CorbaMessage(msg);
    TestUtils testUtils = new TestUtils();
    CorbaDestination destination = testUtils.getExceptionTypesTestDestination();
    EndpointInfo endpointInfo2 = destination.getEndPointInfo();
    QName name = new QName("http://schemas.apache.org/idl/except", "review_data", "");
    BindingOperationInfo bInfo = destination.getBindingInfo().getOperation(name);
    OperationType opType = bInfo.getExtensor(OperationType.class);
    CorbaTypeMap typeMap = null;
    List<TypeMappingType> corbaTypes = endpointInfo2.getService().getDescription().getExtensors(TypeMappingType.class);
    if (corbaTypes != null) {
        typeMap = CorbaUtils.createCorbaTypeMap(corbaTypes);
    }
    ExceptionList exList = conduit.getExceptionList(conduit.getOperationExceptions(opType, typeMap), message, opType);
    assertNotNull("ExceptionList is not null", exList != null);
    assertNotNull("TypeCode is not null", exList.item(0) != null);
    assertEquals("ID should be equal", exList.item(0).id(), "IDL:BadRecord:1.0");
    assertEquals("ID should be equal", exList.item(0).name(), "BadRecord");
    assertEquals("ID should be equal", exList.item(0).member_count(), 2);
    assertEquals("ID should be equal", exList.item(0).member_name(0), "reason");
    assertNotNull("Member type is not null", exList.item(0).member_type(0) != null);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) ExceptionList(org.omg.CORBA.ExceptionList) TypeMappingType(org.apache.cxf.binding.corba.wsdl.TypeMappingType) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 3 with ExceptionList

use of org.omg.CORBA.ExceptionList in project cxf by apache.

the class CorbaConduit method getExceptionList.

public ExceptionList getExceptionList(Map<TypeCode, RaisesType> exceptions, CorbaMessage message, OperationType opType) {
    if (orb == null) {
        prepareOrb();
    }
    // Get the typecodes for the exceptions this operation can throw.
    // These are defined in the operation definition from WSDL.
    ExceptionList exList = orb.create_exception_list();
    if (exceptions != null) {
        Object[] tcs = null;
        tcs = exceptions.keySet().toArray();
        for (int i = 0; i < exceptions.size(); ++i) {
            exList.add((TypeCode) tcs[i]);
        }
    }
    return exList;
}
Also used : ExceptionList(org.omg.CORBA.ExceptionList)

Example 4 with ExceptionList

use of org.omg.CORBA.ExceptionList in project cxf by apache.

the class CorbaConduitTest method testBuildExceptionListEmpty.

@Test
public void testBuildExceptionListEmpty() throws Exception {
    CorbaConduit conduit = setupCorbaConduit(false);
    Message msg = new MessageImpl();
    CorbaMessage message = new CorbaMessage(msg);
    OperationType opType = new OperationType();
    opType.setName("review_data");
    ExceptionList exList = conduit.getExceptionList(conduit.getOperationExceptions(opType, null), message, opType);
    assertNotNull("ExcepitonList is not null", exList != null);
    assertEquals("The list should be empty", exList.count(), 0);
}
Also used : Message(org.apache.cxf.message.Message) ExceptionList(org.omg.CORBA.ExceptionList) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 5 with ExceptionList

use of org.omg.CORBA.ExceptionList in project cxf by apache.

the class CorbaConduitTest method testInvoke.

@Test
public void testInvoke() throws Exception {
    CorbaConduit conduit = setupCorbaConduit(false);
    // CorbaMessage message = new CorbaMessage(msg);
    CorbaMessage message = control.createMock(CorbaMessage.class);
    /*String opName = "GreetMe";
        NVList nvlist = (NVList)orb.create_list(0);

        Request request = conduit.getRequest(message, "GreetMe", nvlist, null, null);
        request.invoke();
        */
    org.omg.CORBA.Object obj = control.createMock(org.omg.CORBA.Object.class);
    EasyMock.expect(message.get(CorbaConstants.CORBA_ENDPOINT_OBJECT)).andReturn(obj);
    // msg.put(CorbaConstants.CORBA_ENDPOINT_OBJECT, obj);
    Request r = control.createMock(Request.class);
    NVList nvList = orb.create_list(0);
    NamedValue ret = control.createMock(NamedValue.class);
    ExceptionList exList = control.createMock(ExceptionList.class);
    EasyMock.expect(obj._create_request((Context) EasyMock.anyObject(), EasyMock.eq("greetMe"), EasyMock.isA(NVList.class), EasyMock.isA(NamedValue.class), EasyMock.isA(ExceptionList.class), EasyMock.isA(ContextList.class)));
    EasyMock.expectLastCall().andReturn(r);
    r.invoke();
    EasyMock.expectLastCall();
    control.replay();
    Request request = conduit.getRequest(message, "greetMe", nvList, ret, exList);
    request.invoke();
    control.verify();
/* try {
                ContextList ctxList = orb.create_context_list();
                Context ctx = orb.get_default_context();
                org.omg.CORBA.Object targetObj = (org.omg.CORBA.Object)message
                    .get(CorbaConstants.CORBA_ENDPOINT_OBJECT);
                Request request = targetObj._create_request(ctx, opName, list, ret, exList, ctxList);
                request.invoke();

            } catch (java.lang.Exception ex) {
                ex.printStackTrace();
            }*/
}
Also used : Context(org.omg.CORBA.Context) Request(org.omg.CORBA.Request) ExceptionList(org.omg.CORBA.ExceptionList) NamedValue(org.omg.CORBA.NamedValue) NVList(org.omg.CORBA.NVList) Test(org.junit.Test)

Aggregations

ExceptionList (org.omg.CORBA.ExceptionList)5 Test (org.junit.Test)3 QName (javax.xml.namespace.QName)2 OperationType (org.apache.cxf.binding.corba.wsdl.OperationType)2 Message (org.apache.cxf.message.Message)2 MessageImpl (org.apache.cxf.message.MessageImpl)2 NVList (org.omg.CORBA.NVList)2 NamedValue (org.omg.CORBA.NamedValue)2 Request (org.omg.CORBA.Request)2 IOException (java.io.IOException)1 CorbaObjectHandler (org.apache.cxf.binding.corba.types.CorbaObjectHandler)1 RaisesType (org.apache.cxf.binding.corba.wsdl.RaisesType)1 TypeMappingType (org.apache.cxf.binding.corba.wsdl.TypeMappingType)1 Fault (org.apache.cxf.interceptor.Fault)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)1 Any (org.omg.CORBA.Any)1 Context (org.omg.CORBA.Context)1 SystemException (org.omg.CORBA.SystemException)1