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:ddf.catalog.transformer.input.tika.TikaInputTransformer.java

private Hashtable<String, Object> getServiceProperties() {
    Hashtable<String, Object> properties = new Hashtable<>();
    properties.put(ddf.catalog.Constants.SERVICE_ID, "tika");
    properties.put(ddf.catalog.Constants.SERVICE_TITLE, "Tika Input Transformer");
    properties.put(ddf.catalog.Constants.SERVICE_DESCRIPTION,
            "The Tika Input Transformer detects and extracts metadata and text content from various documents.");
    properties.put("mime-type", getSupportedMimeTypes());
    // The Tika Input Transformer should be tried last, so we set the service ranking to -1
    properties.put(Constants.SERVICE_RANKING, -1);

    return properties;
}

From source file:algorithm.OpenStegoRandomLSBSteganographyTest.java

@Test
public void openStegoRandomLsbSteganographyAlgorithmTest() {
    try {//from   w w  w .  ja  v a 2  s .  c  o m
        File carrier = TestDataProvider.PNG_FILE;
        File payload = TestDataProvider.TXT_FILE;
        OpenStegoRandomLSBSteganography algorithm = new OpenStegoRandomLSBSteganography();

        // Test encapsulation:
        List<File> payloadList = new ArrayList<File>();
        payloadList.add(payload);
        File outputFile = algorithm.encapsulate(carrier, payloadList);
        assertNotNull(outputFile);
        // Test restore:
        Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>();
        for (RestoredFile file : algorithm.restore(outputFile)) {
            outputHash.put(file.getName(), file);
        }
        assertEquals(outputHash.size(), 2);
        RestoredFile restoredCarrier = outputHash.get(carrier.getName());
        RestoredFile restoredPayload = outputHash.get(payload.getName());
        assertNotNull(restoredCarrier);
        assertNotNull(restoredPayload);
        // can only restore original payload with this algorithm, not
        // carrier!
        assertEquals(FileUtils.checksumCRC32(payload), FileUtils.checksumCRC32(restoredPayload));

        // check restoration metadata:
        assertEquals("" + carrier.getAbsolutePath(), restoredCarrier.originalFilePath);
        assertEquals("" + payload.getAbsolutePath(), restoredPayload.originalFilePath);
        assertEquals(algorithm, restoredCarrier.algorithm);
        // This can't be true for steganography algorithms:
        // assertTrue(restoredCarrier.checksumValid);
        assertTrue(restoredPayload.checksumValid);
        assertTrue(restoredCarrier.wasCarrier);
        assertFalse(restoredCarrier.wasPayload);
        assertTrue(restoredPayload.wasPayload);
        assertFalse(restoredPayload.wasCarrier);
        assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload));
        assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier));
        assertTrue(restoredPayload.relatedFiles.contains(restoredCarrier));
        assertFalse(restoredPayload.relatedFiles.contains(restoredPayload));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:br.com.upic.camel.ldap.LdapEndpoint.java

@Override
protected void onExchange(final Exchange exchange) throws Exception {
    LOG.info("Setting up the context");

    final Hashtable<String, String> conf = new Hashtable<String, String>();

    LOG.debug("Initial Context Factory = " + initialContextFactory);

    conf.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);

    LOG.debug("Provider URL = " + providerUrl);

    conf.put(Context.PROVIDER_URL, providerUrl);

    LOG.debug("Security Authentication = " + securityAuthentication);

    conf.put(Context.SECURITY_AUTHENTICATION, securityAuthentication);

    final Message in = exchange.getIn();

    final String user = in.getHeader(HEADER_USER, String.class);

    LOG.debug("User = " + user);

    conf.put(Context.SECURITY_PRINCIPAL, user);

    final String password = in.getHeader(HEADER_PASSWORD, String.class);

    LOG.debug("Password = " + password);

    conf.put(Context.SECURITY_CREDENTIALS, password);

    LOG.info("Authenticating in directory");

    final Message out = exchange.getOut();

    try {//from w w  w  .  j  a v a2 s.co m
        new InitialContext(conf);

        out.setBody(true);
    } catch (final AuthenticationException e) {
        LOG.error(e.getMessage(), e);

        out.setBody(false);
    }

}

From source file:com.dianping.cat.system.page.login.service.SessionManager.java

public SessionManager() {
    super();// w ww  .j  a  v a 2 s  .c  o m
    AuthType type = AuthType.valueOf(CatPropertyProvider.INST.getProperty("CAT_AUTH_TYPE", "ADMIN_PWD"));
    switch (type) {
    case NOP:
        tokenCreator = new Function<Credential, Token>() {
            @Override
            public Token apply(Credential credential) {
                String account = credential.getAccount();
                return new Token(account, account);
            }
        };
        break;
    case LDAP:
        final String ldapUrl = CatPropertyProvider.INST.getProperty("CAT_LDAP_URL", null);
        if (StringUtils.isBlank(ldapUrl)) {
            throw new IllegalArgumentException("required CAT_LDAP_URL");
        }
        final String userDnTpl = CatPropertyProvider.INST.getProperty("CAT_LDAP_USER_DN_TPL", null);
        if (StringUtils.isBlank(userDnTpl)) {
            throw new IllegalArgumentException("required CAT_LDAP_USER_DN_TPL");
        }
        final String userDisplayAttr = CatPropertyProvider.INST.getProperty("CAT_LDAP_USER_DISPLAY_ATTR", null);
        final Pattern pattern = Pattern.compile("\\{0}");
        final Matcher userDnTplMatcher = pattern.matcher(userDnTpl);
        final String[] attrs = userDisplayAttr == null ? null : new String[] { userDisplayAttr };
        tokenCreator = new Function<Credential, Token>() {
            @Override
            public Token apply(Credential credential) {
                final String account = credential.getAccount();
                final String pwd = credential.getPassword();
                if (StringUtils.isEmpty(account) || StringUtils.isEmpty(pwd)) {
                    return null;
                }
                Hashtable<String, String> env = new Hashtable<String, String>();
                env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
                env.put(Context.PROVIDER_URL, ldapUrl);// LDAP server
                String userDn = userDnTplMatcher.replaceAll(account);
                env.put(Context.SECURITY_PRINCIPAL, pwd);
                env.put(Context.SECURITY_CREDENTIALS, pwd);
                try {
                    InitialLdapContext context = new InitialLdapContext(env, null);
                    final String baseDn = context.getNameInNamespace();
                    if (userDn.endsWith(baseDn)) {
                        userDn = userDn.substring(0, userDn.length() - baseDn.length() - 1);
                    }
                    String displayName = null;
                    if (attrs != null) {
                        final Attributes attributes = context.getAttributes(userDn, attrs);
                        if (attributes.size() > 0) {
                            displayName = attributes.getAll().next().get().toString();
                        }
                    }

                    return new Token(account, displayName == null ? account : displayName);
                } catch (Exception e) {
                    Cat.logError(e);
                    return null;
                }
            }

        };
        break;
    case ADMIN_PWD:
        final String p = CatPropertyProvider.INST.getProperty("CAT_ADMIN_PWD", "admin");

        tokenCreator = new Function<Credential, Token>() {
            @Override
            public Token apply(Credential credential) {
                String account = credential.getAccount();

                if ("admin".equals(account) && p.equals(credential.getPassword())) {
                    return new Token(account, account);
                }
                return null;
            }

        };
        break;
    }
}

From source file:com.feilong.commons.core.tools.json.JsonUtilTest.java

/**
 * Test hashtable./*from   www  . j  a v  a  2  s.c  om*/
 */
@Test
public void testHashtable() {
    Hashtable<String, Object> hashtable = new Hashtable<String, Object>();
    hashtable.put("a", "a");
    // hashtable.put("a", null);
    log.info("hashtable:{}", JsonUtil.format(hashtable));
}

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

/**
 * change the ttl value for this container on the objectstorage server
 * //  ww  w .  java 2 s  .c om
 * @param ttl
 *            the ttl for the CDN objects in this container
 * @throws EncoderException
 * @throws IOException
 */
public void updateCDNTTL(int ttl) throws EncoderException, IOException {

    Hashtable<String, String> params = super.createAuthParams();
    params.put(Client.X_CDN_TTL, Integer.toString(ttl));
    String uName = super.saferUrlEncode(this.name);
    super.post(params, null, super.cdnurl + "/" + uName);
}

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

/**
 * disable CDN access to the files in this container
 * /*from  ww  w. j  av  a  2  s. c o  m*/
 * @throws EncoderException
 * @throws IOException
 */
public void disableCDN() throws EncoderException, IOException {

    Hashtable<String, String> params = super.createAuthParams();
    params.put(Client.X_CDN_ENABLED, "false");
    String uName = super.saferUrlEncode(this.name);
    super.post(params, null, super.cdnurl + "/" + uName);
}

From source file:com.cws.esolutions.core.utils.NetworkUtils.java

/**
 * Creates an SSH connection to a target host and then executes an SCP
 * request to send or receive a file to or from the target. This is fully
 * key-based, as a result, a keyfile is required for the connection to
 * successfully authenticate./* w  ww .  java 2 s.c  o  m*/
 * 
 * NOTE: The key file provided MUST be an OpenSSH key. If its not, it must
 * be converted using ssh-keygen:
 * If no passphrase exists on the key: ssh-keygen -i -f /path/to/file
 * If a passphrase exists:
 * Remove the passphrase first: ssh-keygen-g3 -e /path/to/file
 *  - provide passphrase
 * Type 'yes'
 * Type 'no'
 * Type 'yes'
 * Hit enter twice without entering a new passphrase
 * Convert the keyfile: ssh-keygen -i -f /path/to/file &gt; /path/to/new-file
 * Re-encrypt the file: ssh-keygen -p -f /path/to/new-file
 *
 * @param sourceFile - The full path to the source file to transfer
 * @param targetFile - The full path (including file name) of the desired target file
 * @param targetHost - The target server to perform the transfer to
 * @param isUpload - <code>true</code> is the transfer is an upload, <code>false</code> if it
 *            is a download 
 * @throws UtilityException - If an error occurs processing SSH keys or file transfer operations
 */
public static final synchronized void executeSftpTransfer(final String sourceFile, final String targetFile,
        final String targetHost, final boolean isUpload) throws UtilityException {
    final String methodName = NetworkUtils.CNAME
            + "#executeSftpTransfer(final String sourceFile, final String targetFile, final String targetHost, final boolean isUpload) throws UtilityException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", sourceFile);
        DEBUGGER.debug("Value: {}", targetFile);
        DEBUGGER.debug("Value: {}", targetHost);
        DEBUGGER.debug("Value: {}", isUpload);
    }

    Session session = null;
    Channel channel = null;

    final SSHConfig sshConfig = appBean.getConfigData().getSshConfig();

    if (DEBUG) {
        DEBUGGER.debug("SSHConfig sshConfig: {}", sshConfig);
    }

    try {
        Hashtable<String, String> sshProperties = new Hashtable<String, String>();
        sshProperties.put("StrictHostKeyChecking", "no");

        if (DEBUG) {
            DEBUGGER.debug("Hashtable<String, String> sshProperties: {}", sshProperties);
        }

        JSch jsch = new JSch();
        JSch.setConfig(sshProperties);

        if (DEBUG) {
            DEBUGGER.debug("JSch jsch: {}", jsch);
        }

        session = jsch
                .getSession((StringUtils.isNotEmpty(sshConfig.getSshAccount())) ? sshConfig.getSshAccount()
                        : System.getProperty("user.name"), targetHost, 22);

        if (DEBUG) {
            DEBUGGER.debug("Session session: {}", session);
        }

        if (StringUtils.isNotEmpty(sshConfig.getSshKey())) {
            if (!(FileUtils.getFile(sshConfig.getSshKey()).canRead())) {
                throw new UtilityException("Provided keyfile cannot be accessed.");
            }

            switch (sshConfig.getSshPassword().length()) {
            case 0:
                jsch.addIdentity(FileUtils.getFile(sshConfig.getSshKey()).toString());

                break;
            default:
                jsch.addIdentity(FileUtils.getFile(sshConfig.getSshKey()).toString(),
                        PasswordUtils.decryptText(sshConfig.getSshPassword(), sshConfig.getSshSalt(),
                                secBean.getConfigData().getSecurityConfig().getEncryptionAlgorithm(),
                                secBean.getConfigData().getSecurityConfig().getIterations(),
                                secBean.getConfigData().getSecurityConfig().getKeyBits(),
                                secBean.getConfigData().getSecurityConfig().getEncryptionAlgorithm(),
                                secBean.getConfigData().getSecurityConfig().getEncryptionInstance(),
                                appBean.getConfigData().getSystemConfig().getEncoding()));

                break;
            }
        } else {
            session.setPassword(PasswordUtils.decryptText(sshConfig.getSshPassword(), sshConfig.getSshSalt(),
                    secBean.getConfigData().getSecurityConfig().getEncryptionAlgorithm(),
                    secBean.getConfigData().getSecurityConfig().getIterations(),
                    secBean.getConfigData().getSecurityConfig().getKeyBits(),
                    secBean.getConfigData().getSecurityConfig().getEncryptionAlgorithm(),
                    secBean.getConfigData().getSecurityConfig().getEncryptionInstance(),
                    appBean.getConfigData().getSystemConfig().getEncoding()));
        }

        session.connect((int) TimeUnit.SECONDS.toMillis(appBean.getConfigData().getSshConfig().getTimeout()));

        if (!(session.isConnected())) {
            throw new UtilityException("Failed to connect to the target host");
        }

        channel = session.openChannel("sftp");
        channel.connect();

        if (DEBUG) {
            DEBUGGER.debug("Channel channel: {}", channel);
        }

        ChannelSftp sftpChannel = (ChannelSftp) channel;

        if (DEBUG) {
            DEBUGGER.debug("ChannelSftp sftpChannel: {}", sftpChannel);
        }

        if (isUpload) {

            sftpChannel.put(sourceFile, targetFile, ChannelSftp.OVERWRITE);

            int returnCode = sftpChannel.getExitStatus();

            if (DEBUG) {
                DEBUGGER.debug("int returnCode: {}", returnCode);
            }
        } else {
            FileOutputStream outStream = new FileOutputStream(FileUtils.getFile(targetFile));

            if (DEBUG) {
                DEBUGGER.debug("BufferedInputStream outStream: {}", outStream);
            }

            sftpChannel.get(sourceFile, outStream);

            int returnCode = sftpChannel.getExitStatus();

            if (DEBUG) {
                DEBUGGER.debug("int returnCode: {}", returnCode);
            }

            outStream.flush();
            outStream.close();
        }

        channel.disconnect();
    } catch (IOException iox) {
        throw new UtilityException(iox.getMessage(), iox);
    } catch (SftpException sx) {
        throw new UtilityException(sx.getMessage(), sx);
    } catch (JSchException jx) {
        throw new UtilityException(jx.getMessage(), jx);
    } finally {
        if ((channel != null) && (channel.isConnected())) {
            channel.disconnect();
        }

        if ((session != null) && (session.isConnected())) {
            session.disconnect();
        }
    }
}

From source file:de.filiberry.bathcontrol.Activator.java

/**
 * /*from   ww w  .j  av  a  2s  .co m*/
 */
public void start(BundleContext context) {
    LOGGER.info("Start Bundle " + BUNDLE_ID);
    mqttHost = "";
    mqttTopic = "";
    this.context = context;
    bathControlContext = new BathControlContext();
    bathControlWorker.setBathControlContext(bathControlContext);
    Hashtable<String, Object> properties = new Hashtable<String, Object>();
    properties.put(Constants.SERVICE_PID, BUNDLE_ID);
    serviceReg = context.registerService(ManagedService.class.getName(), this, properties);

}

From source file:de.ub0r.android.websms.connector.sipgate.ConnectorSipgate.java

/**
 * Sets up and instance of {@link XMLRPCClient}.
 * /*  ww w . ja  v a 2 s.c om*/
 * @param context
 *            {@link Context}
 * @return the initialized {@link XMLRPCClient}
 * @throws XMLRPCException
 *             XMLRPCException
 */
private XMLRPCClient init(final Context context) throws XMLRPCException {
    Log.d(TAG, "init()");
    final String version = context.getString(R.string.app_version);
    final String vendor = context.getString(R.string.connector_sipgate_author);
    XMLRPCClient client = null;
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
    if (p.getBoolean(Preferences.PREFS_ENABLE_SIPGATE_TEAM, false)) {
        client = new XMLRPCClient(SIPGATE_TEAM_URL);
    } else {
        client = new XMLRPCClient(SIPGATE_URL);
    }

    client.setBasicAuthentication(p.getString(Preferences.PREFS_USER_SIPGATE, ""),
            p.getString(Preferences.PREFS_PASSWORD_SIPGATE, ""));
    Object back;
    try {
        Hashtable<String, String> ident = new Hashtable<String, String>();
        ident.put("ClientName", TAG);
        ident.put("ClientVersion", version);
        ident.put("ClientVendor", vendor);
        back = client.call("samurai.ClientIdentify", ident);
        Log.d(TAG, back.toString());
        return client;
    } catch (XMLRPCException e) {
        Log.e(TAG, "XMLRPCExceptin in init()", e);
        throw e;
    }
}