Search in sources :

Example 1 with ContainerCreateException

use of org.eclipse.ecf.core.ContainerCreateException in project ecf by eclipse.

the class XMPPSContainerInstantiator method createInstance.

public IContainer createInstance(ContainerTypeDescription description, Object[] args) throws ContainerCreateException {
    try {
        Integer ka = new Integer(XMPPSContainer.DEFAULT_KEEPALIVE);
        String name = null;
        if (args != null) {
            if (args.length > 0) {
                name = (String) args[0];
                if (args.length > 1) {
                    ka = getIntegerFromArg(args[1]);
                }
            }
        }
        if (name == null) {
            if (ka == null) {
                return new XMPPSContainer();
            } else {
                return new XMPPSContainer(ka.intValue());
            }
        } else {
            if (ka == null) {
                ka = new Integer(XMPPSContainer.DEFAULT_KEEPALIVE);
            }
            return new XMPPSContainer(name, ka.intValue());
        }
    } catch (Exception e) {
        throw new ContainerCreateException("Exception creating generic container", e);
    }
}
Also used : XMPPSContainer(org.eclipse.ecf.provider.xmpp.XMPPSContainer) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException)

Example 2 with ContainerCreateException

use of org.eclipse.ecf.core.ContainerCreateException in project ecf by eclipse.

the class RssContainerInstantiator method createInstance.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.core.provider.IContainerInstantiator#createInstance(org.eclipse.ecf.core.ContainerDescription,
	 *      java.lang.Class[], java.lang.Object[])
	 */
public IContainer createInstance(ContainerTypeDescription description, Object[] args) throws ContainerCreateException {
    try {
        Integer keepAlive = new Integer(RssClientSOContainer.DEFAULT_KEEPALIVE);
        String name = null;
        if (args != null) {
            if (args.length > 0) {
                name = (String) args[0];
                if (args.length > 1) {
                    keepAlive = getIntegerFromArg(args[1]);
                }
            }
        }
        if (name == null) {
            if (keepAlive == null) {
                return new RssClientSOContainer();
            } else {
                return new RssClientSOContainer(keepAlive.intValue());
            }
        } else {
            if (keepAlive == null) {
                keepAlive = new Integer(RssClientSOContainer.DEFAULT_KEEPALIVE);
            }
            return new RssClientSOContainer(name, keepAlive.intValue());
        }
    } catch (Exception e) {
        throw new ContainerCreateException("Exception creating RSS container", e);
    }
}
Also used : ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException)

Example 3 with ContainerCreateException

use of org.eclipse.ecf.core.ContainerCreateException in project ecf by eclipse.

the class RemoteServiceAdmin method exportService.

// RemoteServiceAdmin service interface impl methods
public Collection<org.osgi.service.remoteserviceadmin.ExportRegistration> exportService(final ServiceReference<?> serviceReference, Map<String, ?> op) {
    trace("exportService", // $NON-NLS-1$ //$NON-NLS-2$
    "serviceReference=" + serviceReference + ",properties=" + // $NON-NLS-1$
    op);
    final Map<String, ?> overridingProperties = PropertiesUtil.mergeProperties(serviceReference, op == null ? Collections.EMPTY_MAP : op);
    // get exported interfaces
    final String[] exportedInterfaces = PropertiesUtil.getExportedInterfaces(serviceReference, overridingProperties);
    if (exportedInterfaces == null)
        throw new IllegalArgumentException(// $NON-NLS-1$
        org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_INTERFACES + " not set");
    // verifyExportedInterfaces
    if (!validExportedInterfaces(serviceReference, exportedInterfaces))
        return Collections.EMPTY_LIST;
    // Get optional exported configs
    String[] ecs = PropertiesUtil.getStringArrayFromPropertyValue(overridingProperties.get(org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_CONFIGS));
    if (ecs == null) {
        ecs = PropertiesUtil.getStringArrayFromPropertyValue(serviceReference.getProperty(org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_CONFIGS));
    }
    final String[] exportedConfigs = ecs;
    // Get all intents (service.intents, service.exported.intents,
    // service.exported.intents.extra)
    final String[] serviceIntents = PropertiesUtil.getServiceIntents(serviceReference, overridingProperties);
    // Create result registrations. This collection will be returned
    Collection<ExportRegistration> resultRegistrations = new ArrayList<ExportRegistration>();
    // check for previously exported registration for the serviceReference
    synchronized (exportedRegistrations) {
        ExportEndpoint exportEndpoint = findExistingExportEndpoint(serviceReference, null);
        // If found then create a second ExportRegistration from endpoint
        if (exportEndpoint != null) {
            trace("exportService", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            "serviceReference=" + serviceReference + " export endpoint already exists=" + exportEndpoint + // $NON-NLS-1$
            ".  Returning new ExportRegistration for existing endpoint");
            ExportRegistration reg = new ExportRegistration(exportEndpoint);
            addExportRegistration(reg);
            resultRegistrations.add(reg);
        }
    }
    // If the serviceReference hasn't already been exported before (above)
    if (resultRegistrations.size() == 0) {
        // Get a host container selector
        final IHostContainerSelector hostContainerSelector = getHostContainerSelector();
        // and use it to select ECF remote service containers that match given exported
        // interfaces, configs, and intents
        IRemoteServiceContainer[] rsContainers = null;
        try {
            rsContainers = AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws SelectContainerException {
                    return hostContainerSelector.selectHostContainers(serviceReference, (Map<String, Object>) overridingProperties, exportedInterfaces, exportedConfigs, serviceIntents);
                }
            });
        } catch (PrivilegedActionException e) {
            Exception except = e.getException();
            // see discussion on osgi bug
            // https://www.osgi.org/members/bugzilla/show_bug.cgi?id=2591
            // $NON-NLS-1$
            String errorMessage = "Failed to select host container";
            if (except instanceof SelectContainerException) {
                SelectContainerException sce = (SelectContainerException) except;
                Throwable sceCause = sce.getCause();
                if (sceCause instanceof ContainerCreateException) {
                    // Some dummy props need to be set to allow the creation of a dummy export
                    // registration
                    Map<String, Object> props = new HashMap<String, Object>(overridingProperties);
                    // $NON-NLS-1$
                    props.put(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_ID, "0");
                    props.put(org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_IMPORTED_CONFIGS, // $NON-NLS-1$
                    "import.error.config");
                    // $NON-NLS-1$
                    props.put(RemoteConstants.ENDPOINT_ID, "export.error.id");
                    props.put(RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE, StringID.class.getName());
                    ExportRegistration errorRegistration = new RemoteServiceAdmin.ExportRegistration(sceCause, new EndpointDescription(serviceReference, props));
                    addExportRegistration(errorRegistration);
                    resultRegistrations.add(errorRegistration);
                } else
                    throw new IllegalArgumentException(errorMessage, except);
            } else
                throw new IllegalArgumentException(errorMessage, except);
        }
        // If no registration exist (no errorRegistration added above)
        if (resultRegistrations.size() == 0) {
            // If no containers found above, log warning and return
            if (rsContainers == null || rsContainers.length == 0) {
                String errorMessage = // $NON-NLS-1$
                "No containers found for serviceReference=" + serviceReference + " properties=" + // $NON-NLS-1$
                overridingProperties + // $NON-NLS-1$
                ". Remote service NOT EXPORTED";
                // $NON-NLS-1$
                logWarning("exportService", errorMessage);
                return Collections.EMPTY_LIST;
            }
            // actually do the export
            synchronized (exportedRegistrations) {
                // For all selected containers
                for (int i = 0; i < rsContainers.length; i++) {
                    Map endpointDescriptionProperties = createExportEndpointDescriptionProperties(serviceReference, (Map<String, Object>) overridingProperties, exportedInterfaces, serviceIntents, rsContainers[i]);
                    // otherwise, actually export the service to create
                    // a new ExportEndpoint and use it to create a new
                    // ExportRegistration
                    EndpointDescription endpointDescription = new EndpointDescription(endpointDescriptionProperties);
                    checkEndpointPermission(endpointDescription, EndpointPermission.EXPORT);
                    ExportRegistration exportRegistration = null;
                    try {
                        // Actually do the export and return export
                        // registration
                        exportRegistration = exportService(serviceReference, overridingProperties, exportedInterfaces, rsContainers[i], endpointDescriptionProperties);
                    } catch (Exception e) {
                        exportRegistration = new ExportRegistration(e, endpointDescription);
                    }
                    addExportRegistration(exportRegistration);
                    // We add it to the results in either success or error case
                    resultRegistrations.add(exportRegistration);
                }
            }
        }
    }
    // publish all activeExportRegistrations
    for (ExportRegistration exportReg : resultRegistrations) publishExportEvent(exportReg);
    // $NON-NLS-1$ //$NON-NLS-2$
    trace("exportService", "exported registrations=" + resultRegistrations);
    // and return
    return new ArrayList<org.osgi.service.remoteserviceadmin.ExportRegistration>(resultRegistrations);
}
Also used : ArrayList(java.util.ArrayList) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) IRemoteServiceContainer(org.eclipse.ecf.remoteservice.IRemoteServiceContainer) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ECFException(org.eclipse.ecf.core.util.ECFException) ServiceException(org.osgi.framework.ServiceException) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) PrivilegedActionException(java.security.PrivilegedActionException) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 4 with ContainerCreateException

use of org.eclipse.ecf.core.ContainerCreateException in project ecf by eclipse.

the class RemoteServiceHandlerUtil method getActiveIRemoteServiceContainerChecked.

public static IContainer getActiveIRemoteServiceContainerChecked(ExecutionEvent event) throws ExecutionException {
    final IServiceInfo serviceInfo = DiscoveryHandlerUtil.getActiveIServiceInfoChecked(event);
    final ID createConnectId = getActiveConnectIDChecked(event);
    final IContainer container = getContainerWithConnectID(createConnectId);
    if (container != null) {
        return container;
    }
    // TODO remove parameters once
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=256586 is fixed
    final Object[] parameters = new Object[] { createConnectId };
    try {
        // new one
        return ContainerFactory.getDefault().createContainer(getContainerFactory(serviceInfo), parameters);
    } catch (ContainerCreateException e) {
        throw new ExecutionException(e.getMessage(), e);
    }
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) ID(org.eclipse.ecf.core.identity.ID) IContainer(org.eclipse.ecf.core.IContainer) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 5 with ContainerCreateException

use of org.eclipse.ecf.core.ContainerCreateException in project ecf by eclipse.

the class LookupHandler method execute.

/**
 * the command has been executed, so extract extract the needed information
 * from the application context.
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    IDialogSettings dialogSettings = Activator.getDefault().getDialogSettings();
    String[] inputs = dialogSettings.getArray(MANUAL_LOOKUP_HANDLER);
    InputDialogWithComboHistory dialog = new InputDialogWithComboHistory(window.getShell(), Messages.LookupHandler_DIALOG_TITLE, Messages.LookupHandler_DIALOG_LABEL, HOST_DOMAIN_TLD_PORT, inputs, VALIDATOR);
    if (dialog.open() == InputDialog.OK) {
        String input = dialog.getValue();
        try {
            URI uri = URI.create(input);
            // verify the hostname to be resolveable
            InetAddress.getByName(uri.getHost());
            Job job = new LookupJob(uri);
            job.setUser(false);
            job.schedule();
            // add the newly added input to the preference store
            String[] copyOfPreviousInput;
            if (inputs != null) {
                copyOfPreviousInput = new String[inputs.length + 1];
                copyOfPreviousInput[0] = input;
                for (int i = 0; i < inputs.length; i++) {
                    copyOfPreviousInput[i + 1] = inputs[i];
                }
            } else {
                copyOfPreviousInput = new String[] { input };
            }
            // but we don't want dups
            Set aSet = new LinkedHashSet(Arrays.asList(copyOfPreviousInput));
            dialogSettings.put(MANUAL_LOOKUP_HANDLER, (String[]) aSet.toArray(new String[aSet.size()]));
        } catch (ContainerCreateException e) {
            throw new ExecutionException(Messages.LookupHandler_EXEC_FAILED, e);
        } catch (IDCreateException e) {
            throw new ExecutionException(Messages.LookupHandler_EXEC_FAILED, e);
        } catch (UnknownHostException e) {
            IStatus status = new Status(IStatus.INFO, Activator.PLUGIN_ID, Messages.LookupHandler_UNKNOWN_HOSTNAME);
            ErrorDialog.openError(null, Messages.LookupHandler_UNKNOWN_HOSTNAME, NLS.bind(Messages.LookupHandler_HOSTNAME_UNABLE_TO_RESOLVE, input), status);
        }
    }
    return null;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IStatus(org.eclipse.core.runtime.IStatus) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) UnknownHostException(java.net.UnknownHostException) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) URI(java.net.URI) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) Job(org.eclipse.core.runtime.jobs.Job) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

ContainerCreateException (org.eclipse.ecf.core.ContainerCreateException)8 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IContainer (org.eclipse.ecf.core.IContainer)2 ID (org.eclipse.ecf.core.identity.ID)2 IRemoteServiceContainer (org.eclipse.ecf.remoteservice.IRemoteServiceContainer)2 URI (java.net.URI)1 UnknownHostException (java.net.UnknownHostException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Job (org.eclipse.core.runtime.jobs.Job)1 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)1 IContainerFactory (org.eclipse.ecf.core.IContainerFactory)1