Search in sources :

Example 21 with CorbaBindingException

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;
}
Also used : CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 22 with CorbaBindingException

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;
}
Also used : CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ORB(org.omg.CORBA.ORB)

Example 23 with CorbaBindingException

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);
    }
}
Also used : CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) URISyntaxException(java.net.URISyntaxException) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException)

Example 24 with CorbaBindingException

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()]));
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) Union(org.apache.cxf.binding.corba.wsdl.Union) UnionMember(org.omg.CORBA.UnionMember) LinkedHashMap(java.util.LinkedHashMap) CaseType(org.apache.cxf.binding.corba.wsdl.CaseType) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator) Unionbranch(org.apache.cxf.binding.corba.wsdl.Unionbranch)

Example 25 with CorbaBindingException

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);
    }
}
Also used : CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) CorbaTypeMap(org.apache.cxf.binding.corba.CorbaTypeMap) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) QName(javax.xml.namespace.QName) Stack(java.util.Stack) Test(org.junit.Test)

Aggregations

CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)25 QName (javax.xml.namespace.QName)8 TypeCode (org.omg.CORBA.TypeCode)5 URISyntaxException (java.net.URISyntaxException)4 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)4 CorbaMessage (org.apache.cxf.binding.corba.CorbaMessage)3 CorbaObjectHandler (org.apache.cxf.binding.corba.types.CorbaObjectHandler)3 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)3 SystemException (org.omg.CORBA.SystemException)3 Method (java.lang.reflect.Method)2 URI (java.net.URI)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 CorbaStreamable (org.apache.cxf.binding.corba.CorbaStreamable)2 Alias (org.apache.cxf.binding.corba.wsdl.Alias)2 Enum (org.apache.cxf.binding.corba.wsdl.Enum)2 Enumerator (org.apache.cxf.binding.corba.wsdl.Enumerator)2 OperationType (org.apache.cxf.binding.corba.wsdl.OperationType)2 Fault (org.apache.cxf.interceptor.Fault)2 Exchange (org.apache.cxf.message.Exchange)2