Search in sources :

Example 36 with NamingException

use of javax.naming.NamingException in project ACS by ACS-Community.

the class ManagerImpl method bind.

/**
	 * Bind object to remote directory.
	 *
	 * Use INS syntax specified in the INS specification.
	 * In short, the syntax is that components are left-to-right slash ('/') separated and case-sensitive.
	 * The id and kind of each component are separated by the period character ('.').
	 *
	 * @param	remoteDirectory	remote directory context to be used.
	 * @param	name	name of the object, code non-<code>null</code>
	 * @param	object	object to be binded
	 */
private void bind(Context remoteDirectory, String name, String type, Object object) {
    assert (name != null);
    // do not bind interdomain names
    if (name.startsWith(CURL_URI_SCHEMA))
        return;
    if (remoteDirectory != null) {
        try {
            // hierarchical name check
            int pos = name.indexOf('/');
            if (pos != -1) {
                if (pos == 0 || pos == name.length())
                    throw new IllegalArgumentException("Invalid hierarchical name '" + name + "'.");
                String parent = name.substring(0, pos);
                String child = name.substring(pos + 1);
                // lookup for subcontext, if not found create one
                Context parentContext = null;
                try {
                    parentContext = (Context) remoteDirectory.lookup(parent);
                } catch (NameNotFoundException nnfe) {
                // noop
                }
                if (parentContext == null) {
                    parentContext = remoteDirectory.createSubcontext(parent);
                /// @todo temp. commented out
                //generateHiearchyContexts(remoteDirectory, parent, parentContext);
                }
                // delegate
                bind(parentContext, child, type, object);
                return;
            }
            NameParser parser = remoteDirectory.getNameParser("");
            Name n;
            if (type != null)
                n = parser.parse(name + "." + type);
            else
                n = parser.parse(name);
            // special case
            if (name.endsWith(".D")) {
                remoteDirectory.rebind(n, object);
            /// @todo temp. commented out
            //generateHiearchyContexts(remoteDirectory, name, (Context)remoteDirectory.lookup(name));
            } else
                remoteDirectory.bind(n, object);
        } catch (NameAlreadyBoundException nabe) {
            rebind(remoteDirectory, name, type, object);
        } catch (NamingException ne) {
            CoreException ce = new CoreException("Failed to bind name '" + name + "' to the remote directory.", ne);
            logger.log(Level.FINE, ce.getMessage(), ce);
        }
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) CoreException(com.cosylab.acs.maci.CoreException) NameNotFoundException(javax.naming.NameNotFoundException) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 37 with NamingException

use of javax.naming.NamingException in project ACS by ACS-Community.

the class ManagerImpl method lookup.

/**
	 * Lookups for an object in remote directory.
	 *
	 * Use INS syntax specified in the INS specification.
	 * In short, the syntax is that components are left-to-right slash ('/') separated and case-sensitive.
	 * The id and kind of each component are separated by the period character ('.').
	 *
	 * @param	remoteDirectory	remote directory context to be used.
	 * @param	name	name of the object, code non-<code>null</code>
	 * @param	type	type of the object
	 * @return	object	object found in the remote directory, <code>null<code> if nout found
	 */
private Object lookup(Context remoteDirectory, String name, String type) {
    assert (name != null);
    // do not look for interdomain names
    if (name.startsWith(CURL_URI_SCHEMA))
        return null;
    Object resolved = null;
    if (remoteDirectory != null) {
        try {
            NameParser parser = remoteDirectory.getNameParser("");
            Name n;
            if (type != null)
                n = parser.parse(name + "." + type);
            else
                n = parser.parse(name);
            resolved = remoteDirectory.lookup(n);
        } catch (NamingException ne) {
            CoreException ce = new CoreException("Failed to lookup name '" + name + "' in the remote directory.", ne);
            logger.log(Level.FINE, ce.getMessage(), ce);
        }
    }
    return resolved;
}
Also used : CoreException(com.cosylab.acs.maci.CoreException) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 38 with NamingException

use of javax.naming.NamingException in project CloudStack-archive by CloudStack-extras.

the class LDAPConfigCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        boolean result = _configService.updateLDAP(this);
        if (result) {
            LDAPConfigResponse lr = _responseGenerator.createLDAPConfigResponse(getHostname(), getPort(), getUseSSL(), getQueryFilter(), getSearchBase(), getBindDN());
            lr.setResponseName(getCommandName());
            this.setResponseObject(lr);
        }
    } catch (NamingException ne) {
        ne.printStackTrace();
    }
}
Also used : LDAPConfigResponse(com.cloud.api.response.LDAPConfigResponse) NamingException(javax.naming.NamingException)

Example 39 with NamingException

use of javax.naming.NamingException in project ACS by ACS-Community.

the class DefaultSubscriberImpl method subscribe.

/**
   * Method subscribe
   *
   *
   * @param topic
   * @param listener
   * @param selector
   *
   * @return long the subscription handle identifier
   *
   * @throws JMSException
   * @throws NamingException
   *
   */
public long subscribe(String topic, SubscriptionListener listener, String selector) throws JMSException, NamingException {
    cat.info("subscribe(" + topic + ", listener, " + selector + ")");
    if (closed) {
        throw (new JMSException("Subscriber closed."));
    }
    SubscriptionHandle handle = new SubscriptionHandle();
    handle.setSubscriptionTopic(topic);
    handle.setSubscriptionSelector(selector);
    handle.setSubscriptionListener(listener);
    StringBuffer local_selector = new StringBuffer();
    if (NotificationHelper.isNotification(topic)) {
        // this is a subscription to notifications, no further selection is required
        local_selector.append(selector);
    } else {
        // subscription to a generic topic, adding subscriber specific selection
        if (selector != null) {
            local_selector.append(selector);
            local_selector.append(" AND ");
        }
        local_selector.append("( (");
        local_selector.append(NotificationHelper.SUBSCRIPTION_ID_PROPERTY);
        local_selector.append(" IS NULL) OR (");
        local_selector.append(NotificationHelper.SUBSCRIPTION_ID_PROPERTY);
        local_selector.append(" = '");
        local_selector.append(subscriberId);
        local_selector.append("@");
        local_selector.append(handle.getSubscriptionToken());
        local_selector.append("') )");
    }
    TopicSession session = null;
    TopicSubscriber subscriber = null;
    Topic the_topic = createTopic(topic);
    try {
        session = connection.createTopicSession();
        subscriber = session.createSubscriber(the_topic, local_selector.toString(), false);
    } catch (JMSSecurityException jse) {
        cat.error("JMSSecurityException caught");
        throw (new NamingException(jse.getMessage()));
    } catch (JMSException je) {
        cat.error("JMSException caught");
        throw (new NamingException(je.getMessage()));
    } catch (ConnectionException ce) {
        cat.error("ConnectionException caught");
        throw (new JMSException(ce.getMessage()));
    } catch (Exception e) {
        cat.error("Generic exception caught", e);
    }
    subscriber.setMessageListener(listener);
    handle.setSubscriber(subscriber);
    handle.setSession(session);
    synchronized (subscribers) {
        subscribers.put(new Long(handle.getSubscriptionToken()), handle);
    }
    if (!NotificationHelper.isNotification(topic)) {
        publishNotification(NotificationHelper.CONSUMER_OPEN_NOTIFICATION, handle);
    }
    return handle.getSubscriptionToken();
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) TopicSession(javax.jms.TopicSession) JMSSecurityException(javax.jms.JMSSecurityException) JMSException(javax.jms.JMSException) NamingException(javax.naming.NamingException) Topic(javax.jms.Topic) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) MOMException(cern.cmw.mom.pubsub.MOMException) JMSSecurityException(javax.jms.JMSSecurityException)

Example 40 with NamingException

use of javax.naming.NamingException in project ACS by ACS-Community.

the class DefaultSubscriberImpl method publishNotification.

/**
   * Method publishNotification
   *
   * @param type
   * @param handle
   * @throws JMSException
   */
private void publishNotification(int type, SubscriptionHandle handle) throws JMSException {
    if (notificationsEnabled) {
        cat.info("publishNotification(" + type + ", " + handle.getSubscriptionTopic() + ", " + handle.getSubscriptionSelector() + ")");
        notificationMessage.setIntProperty(NotificationHelper.NOTIFICATION_TYPE_PROPERTY, type);
        notificationMessage.setStringProperty(NotificationHelper.SELECTOR_PROPERTY, handle.getSubscriptionSelector());
        notificationMessage.setStringProperty(NotificationHelper.TOPIC_PROPERTY, handle.getSubscriptionTopic());
        notificationMessage.setStringProperty(NotificationHelper.SUBSCRIPTION_ID_PROPERTY, subscriberId + "@" + handle.getSubscriptionToken());
        Topic t = null;
        try {
            t = createTopic(NotificationHelper.CarrierTopics[type]);
        } catch (NamingException ne) {
            ne.printStackTrace();
        }
        notificationPublisher.publish(t, notificationMessage);
    }
}
Also used : NamingException(javax.naming.NamingException) Topic(javax.jms.Topic)

Aggregations

NamingException (javax.naming.NamingException)1246 InitialContext (javax.naming.InitialContext)417 Context (javax.naming.Context)259 IOException (java.io.IOException)163 Attribute (javax.naming.directory.Attribute)111 DirContext (javax.naming.directory.DirContext)100 SearchResult (javax.naming.directory.SearchResult)98 ArrayList (java.util.ArrayList)95 SQLException (java.sql.SQLException)93 NameNotFoundException (javax.naming.NameNotFoundException)88 Attributes (javax.naming.directory.Attributes)85 DataSource (javax.sql.DataSource)84 Properties (java.util.Properties)77 Reference (javax.naming.Reference)77 InitialDirContext (javax.naming.directory.InitialDirContext)77 Test (org.junit.Test)75 Hashtable (java.util.Hashtable)73 SearchControls (javax.naming.directory.SearchControls)73 HashMap (java.util.HashMap)55 LdapContext (javax.naming.ldap.LdapContext)55