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:Controller.ControllerImageCustomerIndex.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from  w w  w.ja  v  a  2 s . co  m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    if (!isMultipart) {

    } else {
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        List items = null;
        try {
            items = upload.parseRequest(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Iterator iter = items.iterator();
        Hashtable params = new Hashtable();
        String fileName = null;
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            if (item.isFormField()) {
                params.put(item.getFieldName(), item.getString());
            } else {

                try {
                    String itemName = item.getName();
                    fileName = itemName.substring(itemName.lastIndexOf("\\") + 1);
                    System.out.println("path" + fileName);
                    String RealPath = getServletContext().getRealPath("/") + "upload\\" + fileName;
                    System.out.println("Rpath" + RealPath);
                    File savedFile = new File(RealPath);
                    item.write(savedFile);
                    String username = (String) params.get("txtusername");
                    String password = (String) params.get("txpassword");
                    String hoten = (String) params.get("txthoten");
                    String gioitinh = (String) params.get("txtgioitinh");
                    String email = (String) params.get("txtemail");
                    String role = "false";
                    Customer cus = new Customer(username, password, hoten, gioitinh, email, role,
                            "upload\\" + fileName);

                    CustomerDAO.ThemKhachHang(cus);
                    RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
                    rd.forward(request, response);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }

    }

}

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

public Attributes loadUser(String uid, String[] attrs) {

    // Preparar las variables de entorno para la conexin JNDI
    Hashtable<String, String> entorno = new Hashtable<String, String>();

    // Credenciales del usuario para realizar la bsqueda
    String cadena = "uid=" + user + "," + context;

    entorno.put(Context.PROVIDER_URL, server);
    entorno.put(Context.INITIAL_CONTEXT_FACTORY, initContext);
    if (password != null && user != null) {
        entorno.put(Context.SECURITY_PRINCIPAL, cadena);
        entorno.put(Context.SECURITY_CREDENTIALS, password);
    }/*from  w ww . j  a va2s. c  o  m*/

    Attributes atributos = null;

    try {
        // Crear contexto de directorio inicial
        DirContext ctx = new InitialDirContext(entorno);

        // Recuperar atributos del usuario que se est buscando
        if (attrs != null)
            atributos = ctx.getAttributes("uid=" + uid + "," + context, attrs);
        else
            atributos = ctx.getAttributes("uid=" + uid + "," + context);

        // Cerrar la conexion
        ctx.close();
    } catch (NamingException e) {
        logger.error(messages.getMessage("err.ldap.attribute", new Object[] { e }, Locale.getDefault()));
    }

    return atributos;

}

From source file:net.ripe.rpki.commons.crypto.cms.RpkiSignedObjectBuilder.java

private AttributeTable createSignedAttributes(Date signingTime) {
    Hashtable<ASN1ObjectIdentifier, Attribute> attributes = new Hashtable<ASN1ObjectIdentifier, Attribute>(); //NOPMD - ReplaceHashtableWithMap
    Attribute signingTimeAttribute = new Attribute(CMSAttributes.signingTime,
            new DERSet(new Time(signingTime)));
    attributes.put(CMSAttributes.signingTime, signingTimeAttribute);
    return new AttributeTable(attributes);
}

From source file:alpine.auth.LdapConnectionWrapper.java

/**
 * Creates a DirContext with the applications configuration settings.
 * @return a DirContext/*from  w  w  w.  j a v a 2s  . com*/
 * @throws NamingException if an exception is thrown
 * @since 1.4.0
 */
public DirContext createDirContext() throws NamingException {
    final Hashtable<String, String> env = new Hashtable<>();
    env.put(Context.SECURITY_PRINCIPAL, BIND_USERNAME);
    env.put(Context.SECURITY_CREDENTIALS, BIND_PASSWORD);
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, LDAP_URL);
    if (IS_LDAP_SSLTLS) {
        env.put("java.naming.ldap.factory.socket", "alpine.crypto.RelaxedSSLSocketFactory");
    }
    return new InitialDirContext(env);
}

From source file:com.aurel.track.util.LdapUtil.java

public static boolean authenticate(TSiteBean siteBean, String loginName, String ppassword)
        throws NamingException {
    boolean userIsOK = false;
    ArrayList<String> trace = new ArrayList<String>();

    trace.add("Ldap trying to authenticate user with loginname >" + loginName + "<");

    if (siteBean.getLdapServerURL().startsWith("ldaps:")) {
        System.setProperty("javax.net.ssl.trustStore", PATH_TO_KEY_STORE);
    }/*from  w  w  w .ja va  2  s  .  c o m*/
    // get the CN
    String keyDn = getCn(siteBean, loginName);

    try {
        if (keyDn != null) {
            trace.add("Using keyDn >" + keyDn + "<");
            // Set up the environment for creating the initial context
            Hashtable<String, String> env = new Hashtable<String, String>(11);
            env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
            env.put(Context.PROVIDER_URL, siteBean.getLdapServerURL());
            env.put(Context.SECURITY_AUTHENTICATION, "simple");
            env.put(Context.SECURITY_PRINCIPAL, keyDn);
            env.put(Context.SECURITY_CREDENTIALS, ppassword);
            // Create initial context
            DirContext itest = new InitialDirContext(env);
            itest.close();
            // user was validated
            userIsOK = true;
        }
        return userIsOK;
    } catch (NamingException e) {
        for (String msg : trace) {
            LOGGER.warn(msg);
        }
        throw e;
    }
}

From source file:com.softlayer.messaging.messagequeue.client.QueueClient.java

/**
 * //w w  w  . j a v a 2  s  . c  om
 * removes the designated queue
 * 
 * @param queueName
 *            the name of the queue to delete
 * @param force
 *            boolean value to force a delete
 * @return a response message notifying of pending delete
 * 
 * @throws IOException
 * @throws JSONException
 * @throws UnexpectedReplyTypeException
 */
public QueueResponse delete(String queueName, boolean force)
        throws IOException, JSONException, UnexpectedReplyTypeException {
    Hashtable<String, String> headers = super.createHeaderToken();
    Hashtable<String, String> params = new Hashtable<String, String>();
    if (force) {

        params.put(FORCE, String.valueOf(force));
    }
    String url = Client.baseurl + QUEUESURL + "/" + queueName;
    JSONObject result = super.delete(headers, params, url);
    QueueResponse response = gson.fromJson(result.toString(), QueueResponse.class);

    return response;
}

From source file:Controller.ControllerImageCustomer.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from   ww w.  j a  v a2  s .co m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    if (!isMultipart) {

    } else {
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        List items = null;
        try {
            items = upload.parseRequest(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Iterator iter = items.iterator();
        Hashtable params = new Hashtable();
        String fileName = null;
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            if (item.isFormField()) {
                params.put(item.getFieldName(), item.getString());
            } else {

                try {
                    String itemName = item.getName();
                    fileName = itemName.substring(itemName.lastIndexOf("\\") + 1);
                    System.out.println("path" + fileName);
                    String RealPath = getServletContext().getRealPath("/") + "upload\\" + fileName;
                    System.out.println("Rpath" + RealPath);
                    File savedFile = new File(RealPath);
                    item.write(savedFile);
                    String username = (String) params.get("txtusername");
                    String password = (String) params.get("txpassword");
                    String hoten = (String) params.get("txthoten");
                    String gioitinh = (String) params.get("txtgioitinh");
                    String email = (String) params.get("txtemail");
                    String role = "false";
                    String Register = (String) params.get("Register");
                    String url = "CustomerDao.jsp";
                    if (Register.equals("Register")) {
                        url = "index.jsp";
                    }
                    Customer cus = new Customer(username, password, hoten, gioitinh, email, role,
                            "upload\\" + fileName);
                    CustomerDAO.ThemKhachHang(cus);
                    RequestDispatcher rd = request.getRequestDispatcher(url);
                    rd.forward(request, response);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }

    }

}

From source file:edu.vt.middleware.ldap.handler.AbstractConnectionHandler.java

/** {@inheritDoc} */
public void connect(final String dn, final Object credential) throws NamingException {
    NamingException lastThrown = null;
    final String[] urls = this.parseLdapUrl(this.config.getLdapUrl(), this.connectionStrategy);
    for (String url : urls) {
        final Hashtable<String, Object> env = new Hashtable<String, Object>(this.config.getEnvironment());
        env.put(LdapConstants.PROVIDER_URL, url);
        try {//from  w  w  w  .java 2  s  . com
            if (this.logger.isTraceEnabled()) {
                this.logger.trace("{" + this.connectionCount + "} Attempting connection to " + url
                        + " for strategy " + this.connectionStrategy);
            }
            this.connectInternal(this.config.getAuthtype(), dn, credential, env);
            this.connectionCount.incrementCount();
            lastThrown = null;
            break;
        } catch (NamingException e) {
            lastThrown = e;
            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Error connecting to LDAP URL: " + url, e);
            }

            boolean ignoreException = false;
            if (this.connectionRetryExceptions != null && this.connectionRetryExceptions.length > 0) {
                for (Class<?> ne : this.connectionRetryExceptions) {
                    if (ne.isInstance(e)) {
                        ignoreException = true;
                        break;
                    }
                }
            }
            if (!ignoreException) {
                break;
            }
        }
    }
    if (lastThrown != null) {
        throw lastThrown;
    }
}

From source file:gov.pnnl.goss.gridappsd.ConfigurationManagerComponentTests.java

@Test
public void configPropertiesSetWhen_configManagerUpdated() {
    ArgumentCaptor<String> argCaptor = ArgumentCaptor.forClass(String.class);
    ConfigurationManagerImpl configManager = new ConfigurationManagerImpl(statusReporter, dataManager);
    configManager.start();//from   w w w. j  ava 2s . c  om

    final String FNCS_PATH_PROP = "fncs.path";
    final String FNCS_PATH_VAL = "fncs_broker";
    final String GRIDLABD_PATH_PROP = "gridlabd.path";
    final String GRIDLABD_PATH_VAL = "gridlabd";
    final String GRIDAPPSD_PATH_PROP = "gridappsd.temp.path";
    final String GRIDAPPSD_PATH_VAL = "\\tmp\\gridappsd_tmp";
    final String FNCS_BRIDGE_PATH_PROP = "fncs.bridge.path";
    final String FNCS_BRIDGE_PATH_VAL = ".\\scripts\\goss_fncs_bridge.py";

    Hashtable<String, String> props = new Hashtable<String, String>();
    props.put(FNCS_PATH_PROP, FNCS_PATH_VAL);
    props.put(GRIDLABD_PATH_PROP, GRIDLABD_PATH_VAL);
    props.put(GRIDAPPSD_PATH_PROP, GRIDAPPSD_PATH_VAL);
    props.put(FNCS_BRIDGE_PATH_PROP, FNCS_BRIDGE_PATH_VAL);
    configManager.updated(props);

    assertEquals(FNCS_PATH_VAL, configManager.getConfigurationProperty(FNCS_PATH_PROP));
    assertEquals(GRIDLABD_PATH_VAL, configManager.getConfigurationProperty(GRIDLABD_PATH_PROP));
    assertEquals(GRIDAPPSD_PATH_VAL, configManager.getConfigurationProperty(GRIDAPPSD_PATH_PROP));
    assertEquals(FNCS_BRIDGE_PATH_VAL, configManager.getConfigurationProperty(FNCS_BRIDGE_PATH_PROP));
}

From source file:com.softlayer.messaging.messagequeue.client.QueueClient.java

/**
 * /*from w  w w  .  j  a v a 2 s . c o  m*/
 * 
 * retreives messages for the given queue
 * 
 * @param queueName
 *            the queue to get messages from
 * @param limit
 *            the maximum number of messages to retrieve
 * @return an array of message data
 * 
 * @throws IOException
 * @throws JSONException
 * @throws UnexpectedReplyTypeException
 */

public Message[] getMessages(String queueName, int limit)
        throws IOException, JSONException, UnexpectedReplyTypeException {
    Hashtable<String, String> headers = super.createHeaderToken();
    Hashtable<String, String> params = new Hashtable<String, String>();
    if (limit != -1)
        params.put(QUEUELIMIT, String.valueOf(limit));
    String url = baseurl + QUEUESURL + "/" + queueName + MESSAGES;
    JSONObject json = super.get(headers, params, url);
    MessageResponse msg = gson.fromJson(json.toString(), MessageResponse.class);
    return msg.getItems().toArray(new Message[0]);

}