Example usage for java.util Hashtable put

List of usage examples for java.util Hashtable put

Introduction

In this page you can find the example usage for java.util Hashtable put.

Prototype

public synchronized V put(K key, V value) 

Source Link

Document

Maps the specified key to the specified value in this hashtable.

Usage

From source file:com.hs.mail.security.login.JndiLoginModule.java

@SuppressWarnings("unchecked")
protected DirContext open() throws NamingException {
    if (context == null) {
        try {// w ww  .j  a va 2  s. co m
            // Set up the environment for creating the initial context
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);
            if (StringUtils.isNotEmpty(username)) {
                env.put(Context.SECURITY_PRINCIPAL, username);
            }
            if (StringUtils.isNotEmpty(password)) {
                env.put(Context.SECURITY_CREDENTIALS, password);
            }
            env.put(Context.PROVIDER_URL, url);
            env.put(Context.SECURITY_AUTHENTICATION, authentication);
            context = new InitialDirContext(env);
        } catch (NamingException e) {
            throw e;
        }
    }
    return context;
}

From source file:com.softlayer.messaging.messagequeue.test.TestQueueClient.java

@Test
public void testPostMessage() throws IOException, JSONException, UnexpectedReplyTypeException {
    Message message = new Message();
    message.setBody("BAM right through your monitor!!!!");
    Hashtable<String, String> options = new Hashtable<String, String>();
    options.put("test", "option");
    message.setFields(options);//  www .  j  a  v a 2 s . c  o  m
    message.setVisibility_delay(10);
    MessageResponse response = client.getQueueClient().postMessage(queueName, message);
    assert (response.getMessage().equalsIgnoreCase("Object created"));
}

From source file:it.unipmn.di.dcs.sharegrid.web.management.ManagementEnv.java

/** Initialized the JNDI. */
protected void initJNDI() throws ManagementException {
    try {/*  ww  w .ja  v  a 2 s.co m*/
        this.ctxFactoryBuild = new ManagementContextFactoryBuilder();
        NamingManager.setInitialContextFactoryBuilder(this.ctxFactoryBuild);
        NamingManager.setObjectFactoryBuilder(this.ctxFactoryBuild);

        // Initial environment with various properties
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, ManagementContextFactory.class.getName());
        //env.put(Context.PROVIDER_URL, "");
        //env.put(Context.OBJECT_FACTORIES, "foo.bar.ObjFactory");
        env.put(Context.URL_PKG_PREFIXES, ManagementContextFactory.class.getPackage().getName());

        this.initCtx = new InitialContext(env);
        Context javaCompCtx = (Context) this.getOrCreateSubcontext("java:comp", initCtx);
        if (javaCompCtx == null) {
            throw new ManagementException("JNDI problem. Cannot get java:comp context from InitialContext.");
        }
        Context envCtx = (Context) this.getOrCreateSubcontext("env", javaCompCtx);
        if (envCtx == null) {
            throw new ManagementException("JNDI problem. Cannot get env context from java:comp context.");
        }
        Context jdbcCtx = (Context) this.getOrCreateSubcontext("jdbc", envCtx);
        if (jdbcCtx == null) {
            throw new ManagementException("JNDI problem. Cannot get jdbc context from java:comp/env context.");
        }

        // Create the DataSource

        //Properties properties = new Properties();
        //properties.put( "driverClassName", "com.mysql.jdbc.Driver" );
        //properties.put( "url", "jdbc:mysql://localhost:3306/DB" );
        //properties.put( "username", "username" );
        //properties.put( "password", "********" );
        //
        //DataSource dataSource = BasicDataSourceFactory.createDataSource( properties );
        //initContext.bind( "java:comp/env/jdbc/db", dataSource );

        //Reference ref = new Reference( "javax.sql.DataSource", "org.apache.commons.dbcp.BasicDataSourceFactory", null ); 
        //ref.add(new StringRefAddr("driverClassName", "com.mysql.jdbc.Driver"));
        //ref.add(new StringRefAddr("url", "jdbc:mysql://localhost:3306/sharegrid"));
        //ref.add(new StringRefAddr("username", "root"));
        //ref.add(new StringRefAddr("password", ""));
        //initCtx.rebind( "java:comp/env/jdbc/mysql", ref );
        java.util.Properties properties = new java.util.Properties();
        properties.put("driverClassName", "com.mysql.jdbc.Driver");
        properties.put("url", "jdbc:mysql://localhost:3306/sharegrid");
        properties.put("username", "root");
        properties.put("password", "");
        javax.sql.DataSource dataSource = org.apache.commons.dbcp.BasicDataSourceFactory
                .createDataSource(properties);
        initCtx.rebind("java:comp/env/jdbc/mysql", dataSource);

    } catch (Exception ex) {
        throw new ManagementException("JNDI problem.", ex);
    }
}

From source file:net.aepik.alasca.core.ldap.Schema.java

/**
 * Get sorted object identifiers keys, to loop on object identifiers
 * into a valid order.//from   w  ww.  j a  va 2  s . c om
 * @param oids Object identifiers.
 * @return String[] Sorted keys
 */
public static String[] getSortedObjectsIdentifiersKeys(Properties oids) {
    Hashtable<String, String> ht = new Hashtable<String, String>();
    for (Enumeration keys = oids.propertyNames(); keys.hasMoreElements();) {
        String k = (String) keys.nextElement();
        Oid o = new Oid(oids.getProperty(k));
        String v = o.toString();
        String p = o.getPrefix();
        while (p != null) {
            v = v.replaceFirst(p + ":", oids.getProperty(p) + ".");
            p = (new Oid(oids.getProperty(p))).getPrefix();
        }
        ht.put(v, k);
    }
    String[] st = ht.keySet().toArray(new String[0]);
    Arrays.sort(st);
    String[] result = new String[st.length];
    int result_index = 0;
    for (String k : st) {
        result[result_index] = ht.get(k);
        result_index++;
    }
    return result;
}

From source file:com.softlayer.objectstorage.Account.java

/**
 * List the CDN urls for streaming and SSL and streaming
 * /* w ww  .  jav a 2  s  .  c o m*/
 * @return a string list of URLs
 * @throws IOException
 */
public List<String> listCDNUrls() throws IOException {
    Hashtable<String, String> params = super.createAuthParams();
    params.put(X_CONTENT, "cdn");
    ClientResource client = super.head(params, super.storageurl);
    ArrayList<String> urls = new ArrayList<String>();
    urls.add(getCustomHttpHeader(X_CDN_URL, client));
    urls.add(getCustomHttpHeader(X_CDN_SSL_URL, client));
    urls.add(getCustomHttpHeader(X_CDN_STREAM_HTTP_URL, client));
    urls.add(getCustomHttpHeader(X_CDN_STREAM_FLASH_URL, client));
    return urls;
}

From source file:com.softlayer.objectstorage.Account.java

/**
 * Search the container for values//from   w  w w  . jav a 2  s .c  om
 * 
 * @param base
 *            the base url for objectstorage api
 * @param query
 *            terms for searching
 * @param limit
 *            number of results to return (pass null for default value)
 * @param start
 *            pagination offset for results to return (pass null for default
 *            value)
 * @param field
 *            name of a field to limit the search to (pass null for default
 *            value)
 * @param type
 * @param format
 * @param marker
 * @param recursive
 * @return search result
 * @throws IOException
 */
public String search(String base, String query, Long limit, Long start, String field, String type,
        String format, String marker, boolean recursive) throws IOException {

    Hashtable<String, String> params = super.createAuthParams();
    params.put(X_CONTENT, "search");
    String url = super.storageurl
            + super.makeSearchUrl(query, limit, start, field, type, format, marker, recursive);

    ClientResource client = super.get(params, url);
    Representation entity = client.getResponseEntity();
    String s = entity.getText();
    return s;
}

From source file:net.sourceforge.floggy.persistence.fr2422928.FR2422928AbstractVersionTest.java

/**
 * DOCUMENT ME!/*from  www.j a  v a 2 s. com*/
*/
public void testNotThrowExceptionWhenMigratingFromPreviousVersion() {
    Hashtable properties = new Hashtable();
    properties.put(MigrationManager.MIGRATE_FROM_PREVIOUS_1_3_0_VERSION, Boolean.TRUE);

    try {
        Enumeration enumeration = MigrationManager.getInstance().start(FR2422928.class, properties);
        assertNotNull(enumeration);
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
}

From source file:com.softlayer.objectstorage.Account.java

/**
 * list all CDN enabled containers for this account
 * /*  w  ww.j av  a2s .co  m*/
 * @return a list of containers with CDN enabled
 * @throws IOException
 */
public List<Container> listAllCDNContainers() throws IOException {
    Hashtable<String, String> params = super.createAuthParams();
    params.put(X_CONTENT, "cdn");
    ClientResource client = super.get(params, super.storageurl);
    Representation entity = client.getResponseEntity();
    String containers = entity.getText();
    StrTokenizer tokenize = new StrTokenizer(containers);
    tokenize.setDelimiterString("\n");
    String[] cont = tokenize.getTokenArray();
    ArrayList<Container> conts = new ArrayList<Container>();
    for (String token : cont) {

        conts.add(new Container(token, super.baseurl, this.username, this.password, false));

    }

    return conts;

}

From source file:org.malaguna.cmdit.service.ldap.LDAPBase.java

public DirContext getDirContext() {
    DirContext ctx = null;//from   w  ww .  jav a 2 s . com
    String cadena = "uid=" + user + "," + context;
    Hashtable<String, String> entorno = new Hashtable<String, String>();

    entorno.put(Context.PROVIDER_URL, server);
    entorno.put(Context.SECURITY_PRINCIPAL, cadena);
    entorno.put(Context.SECURITY_CREDENTIALS, password);
    entorno.put(Context.INITIAL_CONTEXT_FACTORY, initContext);

    try {
        ctx = new InitialDirContext(entorno);
    } catch (NamingException e) {
        logger.error(messages.getMessage("err.ldap.attribute", new Object[] { e }, Locale.getDefault()));
    }

    return ctx;
}

From source file:com.softlayer.messaging.messagequeue.test.TestTopicClient.java

@Test
public void testSubscribe() throws IOException, JSONException, UnexpectedReplyTypeException {
    Subscription sub = new Subscription();

    Endpoint end = sub.new Endpoint();

    sub.setSubscriptionType(EndpointType.http);
    end.setMethod(HttpMethod.get);// ww w .jav  a 2 s .  c om
    end.setUrl("http://www.example.com/");
    Hashtable<String, String> headers = new Hashtable<String, String>();
    headers.put("Content-Type", "application/x-www-form-urlencoded");
    end.setHeaders(headers);
    end.setBody("Hello World!");

    sub.setEndpoint(end);

    Topic topic = new Topic();
    topic.setName("testSubscriptionTopic");
    TopicResponse topResponse = client.getTopicClient().create(topic);

    assert (topResponse.getMessage().equalsIgnoreCase("Object created"));

    SubscriptionResponse subResponse = client.getTopicClient().subscribe(topic.getName(), sub);

    assert (subResponse.getMessage().equalsIgnoreCase("Object created"));
}