Search in sources :

Example 1 with Exception

use of org.apache.cxf.binding.corba.wsdl.Exception in project cxf by apache.

the class CorbaObjectReaderTest method testReadException.

@Test
public void testReadException() {
    OutputStream oStream = orb.create_output_stream();
    // create the following exception
    // exception TestExcept {
    // short code;
    // string message;
    // }
    short code = 12345;
    String message = "54321";
    oStream.write_string("IDL:org.apache.cxf.TestException/1.0");
    oStream.write_short(code);
    oStream.write_string(message);
    InputStream iStream = oStream.create_input_stream();
    CorbaObjectReader reader = new CorbaObjectReader(iStream);
    QName exceptIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "exception", CorbaConstants.NP_WSDL_CORBA);
    QName shortIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "short", CorbaConstants.NP_WSDL_CORBA);
    QName stringIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "string", CorbaConstants.NP_WSDL_CORBA);
    Exception exceptType = new Exception();
    exceptType.setName("TestException");
    MemberType m1 = new MemberType();
    m1.setIdltype(shortIdlType);
    m1.setName("code");
    MemberType m2 = new MemberType();
    m2.setIdltype(stringIdlType);
    m2.setName("message");
    exceptType.getMember().add(m1);
    exceptType.getMember().add(m2);
    // build the object holder
    StructMember[] exceptMembers = new StructMember[2];
    exceptMembers[0] = new StructMember("code", orb.get_primitive_tc(TCKind.tk_short), null);
    exceptMembers[1] = new StructMember("message", orb.get_primitive_tc(TCKind.tk_string), null);
    TypeCode exceptTC = orb.create_exception_tc("IDL:org.apache.cxf.TestException/1.0", "TestException", exceptMembers);
    CorbaExceptionHandler obj = new CorbaExceptionHandler(new QName("TestException"), exceptIdlType, exceptTC, exceptType);
    obj.addMember(new CorbaPrimitiveHandler(new QName("code"), shortIdlType, exceptMembers[0].type, null));
    obj.addMember(new CorbaPrimitiveHandler(new QName("message"), stringIdlType, exceptMembers[1].type, null));
    reader.readException(obj);
    List<CorbaObjectHandler> nestedObjs = obj.getMembers();
    assertTrue(new Short(((CorbaPrimitiveHandler) nestedObjs.get(0)).getDataFromValue()).shortValue() == code);
    assertTrue(((CorbaPrimitiveHandler) nestedObjs.get(1)).getDataFromValue().equals(message));
}
Also used : TypeCode(org.omg.CORBA.TypeCode) InputStream(org.omg.CORBA.portable.InputStream) QName(javax.xml.namespace.QName) OutputStream(org.omg.CORBA.portable.OutputStream) StructMember(org.omg.CORBA.StructMember) Exception(org.apache.cxf.binding.corba.wsdl.Exception) IOException(java.io.IOException) CorbaPrimitiveHandler(org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler) CorbaExceptionHandler(org.apache.cxf.binding.corba.types.CorbaExceptionHandler) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) Test(org.junit.Test)

Example 2 with Exception

use of org.apache.cxf.binding.corba.wsdl.Exception in project cxf by apache.

the class CorbaObjectWriter method writeException.

public void writeException(CorbaExceptionHandler exHandler) throws CorbaBindingException {
    Exception exType = (Exception) exHandler.getType();
    List<CorbaObjectHandler> exMembers = exHandler.getMembers();
    stream.write_string(exType.getRepositoryID());
    for (int i = 0; i < exMembers.size(); ++i) {
        this.write(exMembers.get(i));
    }
}
Also used : CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) Exception(org.apache.cxf.binding.corba.wsdl.Exception) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException)

Example 3 with Exception

use of org.apache.cxf.binding.corba.wsdl.Exception in project cxf by apache.

the class CorbaHandlerUtils method initializeExceptionHandler.

public static void initializeExceptionHandler(ORB orb, CorbaObjectHandler obj, CorbaTypeMap typeMap, ServiceInfo serviceInfo, Map<QName, CorbaObjectHandler> seenTypes) {
    Exception exceptType = (Exception) obj.getType();
    List<MemberType> exceptMembers = exceptType.getMember();
    QName typeName = exceptType.getType();
    for (int i = 0; i < exceptMembers.size(); ++i) {
        MemberType member = exceptMembers.get(i);
        QName memberName;
        if (member.isSetQualified() && member.isQualified() && (typeName != null)) {
            memberName = new QName(typeName.getNamespaceURI(), member.getName());
        } else {
            memberName = new QName("", member.getName());
        }
        QName memberType = member.getIdltype();
        CorbaObjectHandler memberObj = initializeObjectHandler(orb, memberName, memberType, typeMap, serviceInfo, seenTypes);
        ((CorbaExceptionHandler) obj).addMember(memberObj);
    }
}
Also used : MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) QName(javax.xml.namespace.QName) Exception(org.apache.cxf.binding.corba.wsdl.Exception) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException)

Example 4 with Exception

use of org.apache.cxf.binding.corba.wsdl.Exception in project cxf by apache.

the class CorbaUtils method getComplexTypeCode.

public static TypeCode getComplexTypeCode(ORB orb, QName type, Object obj, CorbaTypeMap typeMap, Stack<QName> seenTypes) {
    TypeCode tc = getAnonTypeCode(orb, type, obj, typeMap, seenTypes);
    if (tc == null) {
        if (obj instanceof Alias) {
            Alias aliasType = (Alias) obj;
            tc = orb.create_alias_tc(aliasType.getRepositoryID(), getTypeCodeName(aliasType.getName()), getTypeCode(orb, aliasType.getBasetype(), typeMap, seenTypes));
        } else if (obj instanceof Array) {
            Array arrayType = (Array) obj;
            tc = orb.create_array_tc((int) arrayType.getBound(), getTypeCode(orb, arrayType.getElemtype(), typeMap, seenTypes));
        } else if (obj instanceof Enum) {
            Enum enumType = (Enum) obj;
            String name = enumType.getName();
            List<Enumerator> enums = enumType.getEnumerator();
            String[] members = new String[enums.size()];
            for (int i = 0; i < members.length; ++i) {
                members[i] = enums.get(i).getValue();
            }
            name = getTypeCodeName(name);
            tc = orb.create_enum_tc(enumType.getRepositoryID(), name, members);
        } else if (obj instanceof Exception) {
            Exception exceptType = (Exception) obj;
            List<MemberType> list = exceptType.getMember();
            StructMember[] members = new StructMember[list.size()];
            for (int i = 0; i < members.length; ++i) {
                MemberType member = list.get(i);
                members[i] = new StructMember(member.getName(), getTypeCode(orb, member.getIdltype(), typeMap, seenTypes), null);
            }
            String name = getTypeCodeName(exceptType.getName());
            tc = orb.create_exception_tc(exceptType.getRepositoryID(), name, members);
        } else if (obj instanceof Fixed) {
            Fixed fixedType = (Fixed) obj;
            tc = orb.create_fixed_tc((short) fixedType.getDigits(), (short) fixedType.getScale());
        } else if (obj instanceof org.apache.cxf.binding.corba.wsdl.Object) {
            org.apache.cxf.binding.corba.wsdl.Object objType = (org.apache.cxf.binding.corba.wsdl.Object) obj;
            if (objType.getName().equals("CORBA.Object")) {
                tc = orb.create_interface_tc(objType.getRepositoryID(), "Object");
            } else {
                tc = orb.create_interface_tc(objType.getRepositoryID(), getTypeCodeName(objType.getName()));
            }
        } else if (obj instanceof Sequence) {
            Sequence seqType = (Sequence) obj;
            tc = orb.create_sequence_tc((int) seqType.getBound(), getTypeCode(orb, seqType.getElemtype(), typeMap, seenTypes));
        } else if (obj instanceof Struct) {
            Struct structType = (Struct) obj;
            if (seenTypes.contains(new QName(structType.getName()))) {
                tc = orb.create_recursive_tc(structType.getRepositoryID());
            } else {
                seenTypes.push(new QName(structType.getName()));
                List<MemberType> list = structType.getMember();
                StructMember[] members = new StructMember[list.size()];
                for (int i = 0; i < members.length; ++i) {
                    MemberType member = list.get(i);
                    members[i] = new StructMember(member.getName(), getTypeCode(orb, member.getIdltype(), typeMap, seenTypes), null);
                }
                String name = getTypeCodeName(structType.getName());
                tc = orb.create_struct_tc(structType.getRepositoryID(), name, members);
                seenTypes.pop();
            }
        } else if (obj instanceof Union) {
            tc = getUnionTypeCode(orb, obj, typeMap, seenTypes);
        }
    }
    return tc;
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) Union(org.apache.cxf.binding.corba.wsdl.Union) Struct(org.apache.cxf.binding.corba.wsdl.Struct) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator) NVList(org.omg.CORBA.NVList) List(java.util.List) Fixed(org.apache.cxf.binding.corba.wsdl.Fixed) TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) Sequence(org.apache.cxf.binding.corba.wsdl.Sequence) StructMember(org.omg.CORBA.StructMember) Exception(org.apache.cxf.binding.corba.wsdl.Exception) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) Array(org.apache.cxf.binding.corba.wsdl.Array) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) Alias(org.apache.cxf.binding.corba.wsdl.Alias)

Example 5 with Exception

use of org.apache.cxf.binding.corba.wsdl.Exception in project cxf by apache.

the class CorbaObjectWriterTest method testWriteException.

@Test
public void testWriteException() {
    // create the following exception
    // exception TestExcept {
    // short code;
    // string message;
    // }
    short code = 12345;
    String message = "54321";
    String reposID = "IDL:org.apache.cxf.TestException/1.0";
    QName exceptIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "exception", CorbaConstants.NP_WSDL_CORBA);
    QName shortIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "short", CorbaConstants.NP_WSDL_CORBA);
    QName stringIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "string", CorbaConstants.NP_WSDL_CORBA);
    Exception exceptType = new Exception();
    exceptType.setName("TestException");
    exceptType.setRepositoryID(reposID);
    MemberType m1 = new MemberType();
    m1.setIdltype(shortIdlType);
    m1.setName("code");
    MemberType m2 = new MemberType();
    m2.setIdltype(stringIdlType);
    m2.setName("message");
    exceptType.getMember().add(m1);
    exceptType.getMember().add(m2);
    // build the object holder
    StructMember[] exceptMembers = new StructMember[2];
    exceptMembers[0] = new StructMember("code", orb.get_primitive_tc(TCKind.tk_short), null);
    exceptMembers[1] = new StructMember("message", orb.get_primitive_tc(TCKind.tk_string), null);
    TypeCode exceptTC = orb.create_exception_tc(reposID, "TestException", exceptMembers);
    CorbaExceptionHandler obj = new CorbaExceptionHandler(new QName("TestException"), exceptIdlType, exceptTC, exceptType);
    CorbaPrimitiveHandler member1 = new CorbaPrimitiveHandler(new QName("code"), shortIdlType, exceptMembers[0].type, null);
    member1.setValueFromData(Short.toString(code));
    CorbaPrimitiveHandler member2 = new CorbaPrimitiveHandler(new QName("message"), stringIdlType, exceptMembers[1].type, null);
    member2.setValueFromData(message);
    obj.addMember(member1);
    obj.addMember(member2);
    OutputStream oStream = orb.create_output_stream();
    CorbaObjectWriter writer = new CorbaObjectWriter(oStream);
    writer.writeException(obj);
    InputStream iStream = oStream.create_input_stream();
    String readId = iStream.read_string();
    assertTrue(readId.equals(reposID));
    short readCode = iStream.read_short();
    assertTrue(readCode == code);
    String readMessage = iStream.read_string();
    assertTrue(readMessage.equals(message));
}
Also used : TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) InputStream(org.omg.CORBA.portable.InputStream) OutputStream(org.omg.CORBA.portable.OutputStream) StructMember(org.omg.CORBA.StructMember) Exception(org.apache.cxf.binding.corba.wsdl.Exception) IOException(java.io.IOException) CorbaPrimitiveHandler(org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler) CorbaExceptionHandler(org.apache.cxf.binding.corba.types.CorbaExceptionHandler) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) Test(org.junit.Test)

Aggregations

Exception (org.apache.cxf.binding.corba.wsdl.Exception)5 QName (javax.xml.namespace.QName)4 MemberType (org.apache.cxf.binding.corba.wsdl.MemberType)4 CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)3 StructMember (org.omg.CORBA.StructMember)3 TypeCode (org.omg.CORBA.TypeCode)3 IOException (java.io.IOException)2 CorbaExceptionHandler (org.apache.cxf.binding.corba.types.CorbaExceptionHandler)2 CorbaObjectHandler (org.apache.cxf.binding.corba.types.CorbaObjectHandler)2 CorbaPrimitiveHandler (org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler)2 Test (org.junit.Test)2 InputStream (org.omg.CORBA.portable.InputStream)2 OutputStream (org.omg.CORBA.portable.OutputStream)2 List (java.util.List)1 Alias (org.apache.cxf.binding.corba.wsdl.Alias)1 Array (org.apache.cxf.binding.corba.wsdl.Array)1 Enum (org.apache.cxf.binding.corba.wsdl.Enum)1 Enumerator (org.apache.cxf.binding.corba.wsdl.Enumerator)1 Fixed (org.apache.cxf.binding.corba.wsdl.Fixed)1 Sequence (org.apache.cxf.binding.corba.wsdl.Sequence)1