use of org.apache.cxf.binding.corba.types.CorbaObjectHandler in project cxf by apache.
the class CorbaObjectReaderTest method testReadArray.
// need to add tests for arrays, sequences, struct, exceptions
@Test
public void testReadArray() {
int[] data = { 1, 1, 2, 3, 5, 8, 13, 21 };
OutputStream oStream = orb.create_output_stream();
oStream.write_long_array(data, 0, data.length);
InputStream iStream = oStream.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(iStream);
// create an array of longs
QName longIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "long", CorbaConstants.NP_WSDL_CORBA);
QName arrayIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "array", CorbaConstants.NP_WSDL_CORBA);
Array arrayType = new Array();
arrayType.setBound(data.length);
arrayType.setElemtype(longIdlType);
// name and respoitory ID of the array are not needed for this test
// build the object holder for an array.
TypeCode arrayTC = orb.create_array_tc(data.length, orb.get_primitive_tc(TCKind.tk_long));
CorbaArrayHandler obj = new CorbaArrayHandler(new QName("Array"), arrayIdlType, arrayTC, arrayType);
for (int i = 0; i < data.length; ++i) {
CorbaObjectHandler nestedObj = new CorbaPrimitiveHandler(new QName("item"), longIdlType, orb.get_primitive_tc(TCKind.tk_long), null);
obj.addElement(nestedObj);
}
reader.readArray(obj);
int length = obj.getElements().size();
for (int i = 0; i < length; ++i) {
assertTrue(new Long(((CorbaPrimitiveHandler) obj.getElement(i)).getDataFromValue()).intValue() == data[i]);
}
}
use of org.apache.cxf.binding.corba.types.CorbaObjectHandler 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));
}
use of org.apache.cxf.binding.corba.types.CorbaObjectHandler in project cxf by apache.
the class CorbaObjectReaderTest method testReadStruct.
@Test
public void testReadStruct() {
OutputStream oStream = orb.create_output_stream();
// create the following struct
// struct TestStruct {
// long member1;
// string member2;
// boolean member3;
// }
int member1 = 12345;
String member2 = "54321";
boolean member3 = true;
oStream.write_long(member1);
oStream.write_string(member2);
oStream.write_boolean(member3);
InputStream iStream = oStream.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(iStream);
QName structIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "struct", CorbaConstants.NP_WSDL_CORBA);
QName longIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "long", CorbaConstants.NP_WSDL_CORBA);
QName stringIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "string", CorbaConstants.NP_WSDL_CORBA);
QName boolIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "boolean", CorbaConstants.NP_WSDL_CORBA);
Struct structType = new Struct();
structType.setName("TestStruct");
MemberType m1 = new MemberType();
m1.setIdltype(longIdlType);
m1.setName("member1");
MemberType m2 = new MemberType();
m2.setIdltype(stringIdlType);
m2.setName("member2");
MemberType m3 = new MemberType();
m3.setIdltype(boolIdlType);
m3.setName("member3");
structType.getMember().add(m1);
structType.getMember().add(m2);
structType.getMember().add(m3);
// build the object holder
StructMember[] structMembers = new StructMember[3];
structMembers[0] = new StructMember("member1", orb.get_primitive_tc(TCKind.tk_long), null);
structMembers[1] = new StructMember("member2", orb.get_primitive_tc(TCKind.tk_string), null);
structMembers[2] = new StructMember("member3", orb.get_primitive_tc(TCKind.tk_boolean), null);
TypeCode structTC = orb.create_struct_tc("IDL:org.apache.cxf.TestStruct/1.0", "TestStruct", structMembers);
CorbaStructHandler obj = new CorbaStructHandler(new QName("TestStruct"), structIdlType, structTC, structType);
obj.addMember(new CorbaPrimitiveHandler(new QName("member1"), longIdlType, structMembers[0].type, null));
obj.addMember(new CorbaPrimitiveHandler(new QName("member2"), stringIdlType, structMembers[1].type, null));
obj.addMember(new CorbaPrimitiveHandler(new QName("member3"), boolIdlType, structMembers[2].type, null));
reader.readStruct(obj);
List<CorbaObjectHandler> nestedObjs = obj.getMembers();
assertTrue(new Integer(((CorbaPrimitiveHandler) nestedObjs.get(0)).getDataFromValue()).intValue() == member1);
assertTrue(((CorbaPrimitiveHandler) nestedObjs.get(1)).getDataFromValue().equals(member2));
assertTrue(Boolean.valueOf(((CorbaPrimitiveHandler) nestedObjs.get(2)).getDataFromValue()).booleanValue() == member3);
}
use of org.apache.cxf.binding.corba.types.CorbaObjectHandler 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 = null;
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));
}
}
}
use of org.apache.cxf.binding.corba.types.CorbaObjectHandler 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);
}
Aggregations