Example usage for javax.naming NamingException toString

List of usage examples for javax.naming NamingException toString

Introduction

In this page you can find the example usage for javax.naming NamingException toString.

Prototype

public String toString() 

Source Link

Document

Generates the string representation of this exception.

Usage

From source file:eu.planets_project.tb.impl.persistency.ExperimentPersistencyImpl.java

/**
 * A Factory method to build a reference to this interface.
 * @return//from w  w w  . j a va2  s .  co  m
 */
public static ExperimentPersistencyRemote getInstance() {
    try {
        Context jndiContext = getInitialContext();
        ExperimentPersistencyRemote dao_r = (ExperimentPersistencyRemote) PortableRemoteObject.narrow(
                jndiContext.lookup("testbed/ExperimentPersistencyImpl/remote"),
                ExperimentPersistencyRemote.class);
        return dao_r;
    } catch (NamingException e) {
        //TODO integrate message into logging mechanism
        System.out.println("Failure in getting PortableRemoteObject: " + e.toString());
        return null;
    }
}

From source file:mx.edu.ittepic.AEEcommerce.servlets.Login.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*www .jav  a  2 s .  c  o  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 {
    response.setContentType("application/json;charset=UTF-8");
    response.setHeader("Cache-Control", "no-store");
    PrintWriter out = response.getWriter();

    CartBean2Remoto ejb = (CartBean2Remoto) request.getSession().getAttribute("ejbsesion");
    String user = request.getParameter("usuario");
    String password = request.getParameter("password");
    System.out.println("password anterior:" + password);
    password = DigestUtils.md5Hex(password);
    System.out.println("password nueva:" + password);
    if (ejb == null) {
        try {
            InitialContext ic = new InitialContext();
            ejb = (CartBean2Remoto) ic.lookup("java:comp/env/ejbs/CartBean2");
            GsonBuilder builder = new GsonBuilder();
            Gson gson = builder.create();
            //password= DigestUtils.md5Hex(password);
            Message m = gson.fromJson(ejb.login(user, password), Message.class);
            if (m.getCode() == 200) {
                request.getSession().setAttribute("ejbsesion", ejb);

            }
            out.print(new GsonBuilder().create().toJson(m));
        } catch (NamingException e) {
            out.print(e.toString());
        }
    }
}

From source file:eu.planets_project.tb.impl.system.TestbedStatelessAdminBean.java

/**
 * Hook up to a local instance of the Planets Data Manager.
 * //from w  w w.j a  v a2s . co  m
 * NOTE Trying to get the remote DM and narrow it to the local one did not work.
 * 
 * TODO Switch to the DigitalObjectManager form.
 * 
 * @return A DataManagerLocal, as discovered via JNDI.
 */
public DataManagerLocal getPlanetsDataManagerAsAdmin() {
    try {
        Context jndiContext = new javax.naming.InitialContext();
        DataManagerLocal um = (DataManagerLocal) jndiContext.lookup("planets-project.eu/DataManager/local");
        return um;
    } catch (NamingException e) {
        log.error("Failure during lookup of the local DataManager: " + e.toString());
        return null;
    }
}

From source file:com.dominion.salud.nomenclator.configuration.NOMENCLATORJpaConfiguration.java

public DataSource JNDIDataSource() {
    DataSource dataSource = null;
    JndiTemplate jndi = new JndiTemplate();
    try {//from  w w w.jav  a 2  s  . c o  m
        logger.info("          jdbc.jndi: " + environment.getProperty("jdbc.jndi"));
        dataSource = (DataSource) jndi.lookup(environment.getRequiredProperty("jdbc.jndi"));
    } catch (NamingException e) {
        logger.error("No se ha podido establecer la conexion a base de datos: " + e.toString());
    }
    return dataSource;
}

From source file:com.netspective.axiom.policy.AnsiDatabasePolicy.java

public Object executeAndGetSingleValue(ConnectionContext cc, String sql) throws SQLException {
    Object value = null;//from w  w  w.j  a v  a2s  .c o  m
    Statement stmt = null;
    ResultSet rs = null;
    try {
        stmt = cc.getConnection().createStatement();
        try {
            rs = stmt.executeQuery(sql);
            if (rs.next())
                value = rs.getObject(1);
        } finally {
            if (rs != null)
                rs.close();
        }
    } catch (NamingException e) {
        throw new SQLException(e.toString() + " [" + sql + "]");
    } catch (SQLException e) {
        throw new SQLException(e.toString() + " [" + sql + "]");
    } finally {
        if (stmt != null)
            stmt.close();
    }
    return value;
}

From source file:it.infn.ct.ParallelSemanticSearch_portlet.java

private void testLookup() {
    //ThreadPoolExecutor tp=null;
    try {//from   w ww  .  j a va 2  s  .  c om

        tp = InitialContext.<ThreadPoolExecutor>doLookup("SemanticSearch-Pool");//("concurrency/TP");SemanticSearch-Pool
        // tp = InitialContext.<ThreadPoolExecutor>doLookup("concurrency/TP");
        System.out.println("ThreadPoolExecutor from lookup: " + tp);

    } catch (NamingException e) {
        System.out.println("Exception: error in thread-pool inizialization! " + e.toString());
    }

}

From source file:ome.logic.LdapImpl.java

/**
 * Creates the initial context with no connection request controls in order
 * to check authentication. If authentication fails, this method throws
 * a {@link SecurityViolation}./*from   ww  w . ja  v a  2 s.  c  om*/
 *
 * @return {@link javax.naming.ldap.LdapContext}
 */
@SuppressWarnings("unchecked")
private void isAuthContext(String username, String password) {

    Hashtable<String, String> env = new Hashtable<String, String>(5, 0.75f);
    try {
        env = (Hashtable<String, String>) ctx.getReadOnlyContext().getEnvironment();

        if (username != null && !username.equals("")) {
            env.put(Context.SECURITY_PRINCIPAL, username);
            if (password != null) {
                env.put(Context.SECURITY_CREDENTIALS, password);
            }
        }
        new InitialLdapContext(env, null);
    } catch (AuthenticationException authEx) {
        throw new SecurityViolation("Authentication falilure! " + authEx.toString());
    } catch (NamingException e) {
        throw new SecurityViolation("Naming exception! " + e.toString());
    }
}

From source file:ome.logic.LdapImpl.java

private String getBase() {
    String base = null;//from w  w w  .j  ava 2  s .  c  o  m
    try {
        base = ctx.getReadOnlyContext().getNameInNamespace();
    } catch (NamingException e) {
        throw new ApiUsageException("Cannot get BASE from ContextSource. Naming exception! " + e.toString());
    }
    return base;

}

From source file:org.apache.activemq.demo.SimpleQueueSender.java

/**
 * Main method./* ww  w  . j  av a2  s .  co  m*/
 *
 * @param args the queue used by the example and, optionally, the number of
 *                messages to send
 */
public static void main(String[] args) {
    String queueName = null;
    Context jndiContext = null;
    QueueConnectionFactory queueConnectionFactory = null;
    QueueConnection queueConnection = null;
    QueueSession queueSession = null;
    Queue queue = null;
    QueueSender queueSender = null;
    TextMessage message = null;
    final int numMsgs;

    if ((args.length < 1) || (args.length > 2)) {
        LOG.info("Usage: java SimpleQueueSender " + "<queue-name> [<number-of-messages>]");
        System.exit(1);
    }
    queueName = args[0];
    LOG.info("Queue name is " + queueName);
    if (args.length == 2) {
        numMsgs = (new Integer(args[1])).intValue();
    } else {
        numMsgs = 1;
    }

    /*
     * Create a JNDI API InitialContext object if none exists yet.
     */
    try {
        jndiContext = new InitialContext();
    } catch (NamingException e) {
        LOG.info("Could not create JNDI API context: " + e.toString());
        System.exit(1);
    }

    /*
     * Look up connection factory and queue. If either does not exist, exit.
     */
    try {
        queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("QueueConnectionFactory");
        queue = (Queue) jndiContext.lookup(queueName);
    } catch (NamingException e) {
        LOG.info("JNDI API lookup failed: " + e);
        System.exit(1);
    }

    /*
     * Create connection. Create session from connection; false means
     * session is not transacted. Create sender and text message. Send
     * messages, varying text slightly. Send end-of-messages message.
     * Finally, close connection.
     */
    try {
        queueConnection = queueConnectionFactory.createQueueConnection();
        queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        queueSender = queueSession.createSender(queue);
        message = queueSession.createTextMessage();
        for (int i = 0; i < numMsgs; i++) {
            message.setText("This is message " + (i + 1));
            LOG.info("Sending message: " + message.getText());
            queueSender.send(message);
        }

        /*
         * Send a non-text control message indicating end of messages.
         */
        queueSender.send(queueSession.createMessage());
    } catch (JMSException e) {
        LOG.info("Exception occurred: " + e.toString());
    } finally {
        if (queueConnection != null) {
            try {
                queueConnection.close();
            } catch (JMSException e) {
            }
        }
    }
}

From source file:org.apache.activemq.demo.SimpleConsumer.java

/**
 * @param args the queue used by the example
 *///w w w .j  a  va2s .c o  m
public static void main(String[] args) {
    String destinationName = null;
    Context jndiContext = null;
    ConnectionFactory connectionFactory = null;
    Connection connection = null;
    Session session = null;
    Destination destination = null;
    MessageConsumer consumer = null;

    /*
     * Read destination name from command line and display it.
     */
    if (args.length != 1) {
        LOG.info("Usage: java SimpleConsumer <destination-name>");
        System.exit(1);
    }
    destinationName = args[0];
    LOG.info("Destination name is " + destinationName);

    /*
     * Create a JNDI API InitialContext object
     */
    try {
        jndiContext = new InitialContext();
    } catch (NamingException e) {
        LOG.info("Could not create JNDI API " + "context: " + e.toString());
        System.exit(1);
    }

    /*
     * Look up connection factory and destination.
     */
    try {
        connectionFactory = (ConnectionFactory) jndiContext.lookup("ConnectionFactory");
        destination = (Destination) jndiContext.lookup(destinationName);
    } catch (NamingException e) {
        LOG.info("JNDI API lookup failed: " + e.toString());
        System.exit(1);
    }

    /*
     * Create connection. Create session from connection; false means
     * session is not transacted. Create receiver, then start message
     * delivery. Receive all text messages from destination until a non-text
     * message is received indicating end of message stream. Close
     * connection.
     */
    try {
        connection = connectionFactory.createConnection();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        consumer = session.createConsumer(destination);
        connection.start();
        while (true) {
            Message m = consumer.receive(1);
            if (m != null) {
                if (m instanceof TextMessage) {
                    TextMessage message = (TextMessage) m;
                    LOG.info("Reading message: " + message.getText());
                } else {
                    break;
                }
            }
        }
    } catch (JMSException e) {
        LOG.info("Exception occurred: " + e);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
            }
        }
    }
}