Search in sources :

Example 1 with CorbaDSIServant

use of org.apache.cxf.binding.corba.runtime.CorbaDSIServant in project cxf by apache.

the class CorbaDestination method activate.

public void activate() {
    java.util.Properties props = new java.util.Properties();
    Properties configSpecifiedOrbProperties = orbConfig.getOrbProperties();
    props.putAll(configSpecifiedOrbProperties);
    if (orbConfig.getOrbClass() != null) {
        props.put("org.omg.CORBA.ORBClass", orbConfig.getOrbClass());
    }
    if (orbConfig.getOrbSingletonClass() != null) {
        props.put("org.omg.CORBA.ORBSingletonClass", orbConfig.getOrbSingletonClass());
    }
    String location = getDestinationAddress();
    if (!CorbaUtils.isValidURL(location)) {
        throw new CorbaBindingException("Invalid addressing specified for CORBA port location");
    }
    LOG.info("Service address retrieved: " + location);
    URI addressURI = null;
    try {
        addressURI = new URI(location);
    } catch (java.net.URISyntaxException ex) {
        throw new CorbaBindingException("Unable to create ORB with address " + address);
    }
    List<String> orbArgs = new ArrayList<>(orbConfig.getOrbArgs());
    String scheme = addressURI.getScheme();
    // host and port used when no preference has been specified.
    if (poaName != null) {
        poaName = poaName.replace('.', '_');
    }
    if ("corbaloc".equals(scheme)) {
        if (poaName == null) {
            poaName = getEndPointInfo().getName().getLocalPart().replace('.', '_');
        }
        setCorbaLocArgs(addressURI, orbArgs);
    } else if ("corbaname".equals(scheme)) {
        int idx = location.indexOf("#");
        if (idx != -1) {
            serviceId = location.substring(idx + 1);
        }
    }
    if (isPersistent) {
        if (poaName == null) {
            throw new CorbaBindingException("POA name missing for corba port " + "with a persistent policy");
        }
    } else {
        poaName = CorbaUtils.getUniquePOAName(getEndPointInfo().getService().getName(), getEndPointInfo().getName().getLocalPart(), poaName).replace('.', '_');
    }
    orb = getORB(orbArgs, location, props);
    try {
        POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
        POAManager poaManager = rootPOA.the_POAManager();
        try {
            bindingPOA = rootPOA.find_POA(poaName, false);
        } catch (org.omg.PortableServer.POAPackage.AdapterNonExistent ex) {
        // do nothing
        }
        // an activate two objects with the same servant ID instead.
        if (bindingPOA != null && !isPersistent && serviceId == null) {
            throw new CorbaBindingException("Corba Port activation failed because the poa " + poaName + " already exists");
        } else if (bindingPOA == null) {
            bindingPOA = createPOA(poaName, rootPOA, poaManager);
        }
        if (bindingPOA == null) {
            throw new CorbaBindingException("Unable to create CXF CORBA Binding POA");
        }
        CorbaDSIServant servant = new CorbaDSIServant();
        servant.init(orb, bindingPOA, this, incomingObserver, typeMap);
        if (serviceId != null) {
            objectId = serviceId.getBytes();
            try {
                bindingPOA.activate_object_with_id(objectId, servant);
            } catch (org.omg.PortableServer.POAPackage.ObjectAlreadyActive ex) {
                if (!isPersistent) {
                    throw new CorbaBindingException("Object " + serviceId + " already active for non-persistent poa");
                }
            }
        } else {
            objectId = bindingPOA.activate_object(servant);
        }
        bindingPOA.set_servant(servant);
        obj = bindingPOA.id_to_reference(objectId);
        orbConfig.exportObjectReference(orb, obj, location, address);
        populateEpr(orb.object_to_string(obj));
        LOG.info("Object Reference: " + orb.object_to_string(obj));
        poaManager.activate();
    } catch (Exception ex) {
        throw new CorbaBindingException("Unable to activate CORBA servant", ex);
    }
}
Also used : CorbaDSIServant(org.apache.cxf.binding.corba.runtime.CorbaDSIServant) Properties(java.util.Properties) POA(org.omg.PortableServer.POA) ArrayList(java.util.ArrayList) Properties(java.util.Properties) URI(java.net.URI) IOException(java.io.IOException) POAManager(org.omg.PortableServer.POAManager)

Aggregations

IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 CorbaDSIServant (org.apache.cxf.binding.corba.runtime.CorbaDSIServant)1 POA (org.omg.PortableServer.POA)1 POAManager (org.omg.PortableServer.POAManager)1