use of org.apache.cxf.binding.corba.CorbaBindingException in project cxf by apache.
the class CorbaBindingHelper method getORBNameFromAddress.
private static String getORBNameFromAddress(String address) {
String name = null;
URI addressURI = null;
try {
addressURI = new URI(address);
} catch (URISyntaxException ex) {
throw new CorbaBindingException("Unable to locate ORB with address " + address);
}
String scheme = addressURI.getScheme();
if ("corbaloc".equals(scheme) || "corbaname".equals(scheme)) {
String schemeSpecificPart = addressURI.getSchemeSpecificPart();
if (schemeSpecificPart.startsWith(":")) {
schemeSpecificPart = schemeSpecificPart.substring(1);
}
int keyIndex = schemeSpecificPart.indexOf('/');
if (keyIndex != -1) {
name = schemeSpecificPart.substring(0, keyIndex);
} else {
name = schemeSpecificPart;
}
if (addressURI.getRawQuery() != null) {
name += addressURI.getRawQuery();
}
} else if ("IOR".equals(scheme) || "ior".equals(scheme)) {
name = addressURI.toString();
} else if ("file".equals(scheme) || "relfile".equals(scheme)) {
name = addressURI.getPath();
if (name == null) {
name = addressURI.getSchemeSpecificPart();
}
} else {
throw new CorbaBindingException("Unsupported address scheme type " + scheme);
}
return name;
}
use of org.apache.cxf.binding.corba.CorbaBindingException in project cxf by apache.
the class CorbaBindingHelper method createAddressSpecificORB.
private static ORB createAddressSpecificORB(String address, Properties props, List<String> orbArgs) {
ORB orb = null;
URI addressURI = null;
try {
addressURI = new URI(address);
} catch (URISyntaxException ex) {
throw new CorbaBindingException("Unable to create ORB with address " + address);
}
String scheme = addressURI.getScheme();
// host and port used when no preference has been specified.
if ("corbaloc".equals(scheme)) {
String schemeSpecificPart = addressURI.getSchemeSpecificPart();
int keyIndex = schemeSpecificPart.indexOf('/');
String corbaAddr = schemeSpecificPart.substring(0, keyIndex);
int index = corbaAddr.indexOf(':');
String protocol = "iiop";
if (index != 0) {
protocol = corbaAddr.substring(0, index);
}
int oldIndex = index;
index = corbaAddr.indexOf(':', oldIndex + 1);
String host = corbaAddr.substring(oldIndex + 1, index);
String port = corbaAddr.substring(index + 1);
props.put("yoko.orb.oa.endpoint", new String(protocol + " --host " + host + " --port " + port));
// WHAT to do for non-yoko orb?
} else if ("corbaname".equals(scheme)) {
String schemeSpecificPart = addressURI.getSchemeSpecificPart();
if (schemeSpecificPart.startsWith(":")) {
schemeSpecificPart = schemeSpecificPart.substring(1);
}
int idx = schemeSpecificPart.indexOf(':');
props.put("org.omg.CORBA.ORBInitialHost", schemeSpecificPart.substring(0, idx));
props.put("org.omg.CORBA.ORBInitialPort", schemeSpecificPart.substring(idx + 1));
} else if ("file".equals(scheme) || "relfile".equals(scheme) || "IOR".equals(scheme) || "ior".equals(scheme)) {
// use defaults
} else {
throw new CorbaBindingException("Unsupported address scheme type " + scheme);
}
orb = ORB.init(orbArgs.toArray(new String[orbArgs.size()]), props);
orbList.put(getORBNameFromAddress(address), orb);
return orb;
}
use of org.apache.cxf.binding.corba.CorbaBindingException in project cxf by apache.
the class CorbaBindingHelper method destroyORB.
// Signals that the ORB should be tested to see if it can be destroyed. Actual destruction will
// only occur if the ORB is not being used by someone else. If it is, then we simply decrement
// the count.
public static synchronized void destroyORB(String address, ORB orb) throws CorbaBindingException {
Integer count = orbUseCount.get(getORBNameFromAddress(address));
if (count == null) {
return;
}
count = count - 1;
if (count < 1) {
// We shouldn't have anyone waiting on this ORB. Destroy it.
orbUseCount.remove(getORBNameFromAddress(address));
orbList.remove(getORBNameFromAddress(address));
try {
orb.destroy();
} catch (Exception ex) {
throw new CorbaBindingException(ex);
}
} else {
orbUseCount.put(getORBNameFromAddress(address), count);
}
}
use of org.apache.cxf.binding.corba.CorbaBindingException in project cxf by apache.
the class CorbaUtils method getUnionTypeCode.
public static TypeCode getUnionTypeCode(ORB orb, Object obj, CorbaTypeMap typeMap, Stack<QName> seenTypes) {
Union unionType = (Union) obj;
if (seenTypes.contains(new QName(unionType.getName()))) {
return orb.create_recursive_tc(unionType.getRepositoryID());
}
seenTypes.push(new QName(unionType.getName()));
TypeCode discTC = getTypeCode(orb, unionType.getDiscriminator(), typeMap, seenTypes);
Map<String, UnionMember> members = new LinkedHashMap<String, UnionMember>();
List<Unionbranch> branches = unionType.getUnionbranch();
for (Iterator<Unionbranch> branchIter = branches.iterator(); branchIter.hasNext(); ) {
Unionbranch branch = branchIter.next();
List<CaseType> cases = branch.getCase();
for (Iterator<CaseType> caseIter = cases.iterator(); caseIter.hasNext(); ) {
CaseType cs = caseIter.next();
if (!members.containsKey(cs.getLabel())) {
UnionMember member = new UnionMember();
member.name = branch.getName();
member.type = getTypeCode(orb, branch.getIdltype(), typeMap, seenTypes);
member.label = orb.create_any();
// * enum
switch(discTC.kind().value()) {
case TCKind._tk_short:
member.label.insert_short(Short.parseShort(cs.getLabel()));
break;
case TCKind._tk_ushort:
member.label.insert_ushort(Short.parseShort(cs.getLabel()));
break;
case TCKind._tk_long:
member.label.insert_long(Integer.parseInt(cs.getLabel()));
break;
case TCKind._tk_ulong:
member.label.insert_ulong(Integer.parseInt(cs.getLabel()));
break;
case TCKind._tk_longlong:
member.label.insert_longlong(Long.parseLong(cs.getLabel()));
break;
case TCKind._tk_ulonglong:
member.label.insert_ulonglong(Long.parseLong(cs.getLabel()));
break;
case TCKind._tk_char:
member.label.insert_char(cs.getLabel().charAt(0));
break;
case TCKind._tk_boolean:
member.label.insert_boolean(Boolean.parseBoolean(cs.getLabel()));
break;
case TCKind._tk_enum:
org.omg.CORBA.portable.OutputStream out = member.label.create_output_stream();
Enum enumVal = (Enum) getCorbaType(unionType.getDiscriminator(), typeMap);
List<Enumerator> enumerators = enumVal.getEnumerator();
for (int i = 0; i < enumerators.size(); ++i) {
Enumerator e = enumerators.get(i);
if (e.getValue().equals(cs.getLabel())) {
out.write_long(i);
}
}
member.label.read_value(out.create_input_stream(), discTC);
break;
default:
throw new CorbaBindingException("Unsupported discriminator type");
}
// Some orbs are strict on how the case labels are stored for
// each member. So we can't
// simply insert the labels as strings
members.put(cs.getLabel(), member);
}
}
}
seenTypes.pop();
return orb.create_union_tc(unionType.getRepositoryID(), getTypeCodeName(unionType.getName()), discTC, members.values().toArray(new UnionMember[members.size()]));
}
use of org.apache.cxf.binding.corba.CorbaBindingException in project cxf by apache.
the class CorbaUtilsTest method testErrorConditionNullTypeQName.
@Test
public void testErrorConditionNullTypeQName() {
try {
CorbaUtils.getTypeCode(orb, null, new CorbaTypeMap("dud:namespace"));
fail("expect exception on null type");
} catch (CorbaBindingException expected) {
// ignore
}
CorbaTypeMap typeMap = new CorbaTypeMap("dud:namespace");
QName seen = new QName("bla", "Bla");
Stack<QName> seenTypes = new Stack<QName>();
seenTypes.add(seen);
try {
CorbaUtils.getTypeCode(orb, null, typeMap, seenTypes);
fail("expect exception on null type");
} catch (CorbaBindingException expected) {
assertTrue("enclosed type is present", expected.getMessage().indexOf(seen.toString()) != -1);
}
CorbaType ctype = new CorbaType();
try {
CorbaUtils.getTypeCode(orb, null, ctype, typeMap);
fail("expect exception on null type");
} catch (CorbaBindingException expected) {
assertTrue("enclosed corba type is present", expected.getMessage().indexOf(ctype.toString()) != -1);
}
}
Aggregations