Example usage for javax.naming NamingException getMessage

List of usage examples for javax.naming NamingException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:TestDSBind.java

public static void main(String args[]) throws SQLException, NamingException {

    // For this to work you will need to create the
    // directories /JNDI/JDBC on your file system first
    Context ctx = null;/*from   w w w.  j av  a  2  s.  com*/
    try {
        Properties prop = new Properties();
        prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
        prop.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC");
        ctx = new InitialContext(prop);
    } catch (NamingException ne) {
        System.err.println(ne.getMessage());
    }

    OracleDataSource ds = new OracleDataSource();
    ds.setDriverType("thin");
    ds.setServerName("dssw2k01");
    ds.setPortNumber(1521);
    ds.setDatabaseName("orcl");
    ds.setUser("scott");
    ds.setPassword("tiger");

    ctx.bind("joe", ds);
}

From source file:TestDSLookUp.java

public static void main(String[] args) throws SQLException, NamingException {

    Context ctx = null;/*  ww w  . j  a  v a 2 s  .  c om*/
    try {
        Properties prop = new Properties();
        prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
        prop.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC");
        ctx = new InitialContext(prop);
    } catch (NamingException ne) {
        System.err.println(ne.getMessage());
    }

    DataSource ds = (DataSource) ctx.lookup("joe");
    Connection conn = ds.getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery(
            "select 'Hello Thin driver data source tester '||" + "initcap(USER)||'!' result from dual");
    if (rset.next())
        System.out.println(rset.getString(1));
    rset.close();
    stmt.close();
    conn.close();
}

From source file:org.sdnmq.jms_demoapps.FilteringPacketInSubscriber.java

public static void main(String[] args) {
    // Standard JMS setup.

    try {/*from   w  ww.  j a v  a2 s  .co m*/
        // Uses settings from file jndi.properties if file is in CLASSPATH.
        ctx = new InitialContext();
    } catch (NamingException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        queueFactory = (TopicConnectionFactory) ctx.lookup("TopicConnectionFactory");
    } catch (NamingException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        connection = queueFactory.createTopicConnection();
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        packetinTopic = (Topic) ctx.lookup(PACKETIN_TOPIC_NAME);
    } catch (NameNotFoundException e) {
        System.err.println(e.getMessage());
        die(-1);
    } catch (NamingException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        // This selector filters messages from the IPv4 source address 10.0.0.1.
        //
        // For a full list of filter attributes, cf. class MessageFilterAttributes.
        //
        // For a description of the JMS selector concept, the WebSphere MQ documentation below gives a good overview:
        // http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/index.jsp?topic=%2Fcom.ibm.mq.csqzaw.doc%2Fuj25420_.htm
        //
        // Hint: You can use the binary address attributes NW_SRC_BINARY and NW_DST_BINARY
        // together with the LIKE operator to match a subnet prefix as used by CIDR.
        String selector = MessageFilterAttributes.Keys.DL_TYPE.toFilterName() + "=" + IPV4_ETHERTYPE + " AND "
                + MessageFilterAttributes.Keys.NW_SRC.toFilterName() + "='10.0.0.1'";
        subscriber = session.createSubscriber(packetinTopic, selector, false);
        // The listener implements the callback function onMessage(),
        // which is called whenever a message is received.
        subscriber.setMessageListener(new FilteringPacketInSubscriber());
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        connection.start();
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    // Message handling is done asynchronously in the onMessage() callback.
    // The main thread can sleep meanwhile.

    while (true) {
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
        }
    }
}

From source file:org.sdnmq.jms_demoapps.SimplePacketInSubscriber.java

public static void main(String[] args) {
    // Standard JMS setup.
    try {//from   w  w  w  . j a v  a2 s.c  om
        // Uses settings from file jndi.properties if file is in CLASSPATH.
        ctx = new InitialContext();
    } catch (NamingException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        queueFactory = (TopicConnectionFactory) ctx.lookup("TopicConnectionFactory");
    } catch (NamingException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        connection = queueFactory.createTopicConnection();
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        packetinTopic = (Topic) ctx.lookup(PACKETIN_TOPIC_NAME);
    } catch (NameNotFoundException e) {
        System.err.println(e.getMessage());
        die(-1);
    } catch (NamingException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        subscriber = session.createSubscriber(packetinTopic);
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        connection.start();
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    // Wait for packet-in events.

    while (true) {
        try {
            // Block until a packet-in event is received.
            // Another alternative is to define a callback function
            // (cf. example FilteringPacketInSubscriber).
            Message msg = subscriber.receive();
            if (msg instanceof TextMessage) {
                String messageStr = ((TextMessage) (msg)).getText();

                // Parse JSON message payload

                JSONObject json = null;
                try {
                    json = new JSONObject(messageStr);
                    // Print the JSON message to show how it looks like.
                    System.out.println(json.toString());
                    System.out.println();
                } catch (JSONException e) {
                    System.err.println(e.getMessage());
                    continue;
                }

                // Search for some packet attributes (for a list of all possible keys, see class PacketInAttributes).

                try {
                    int ethertype = json.getInt(PacketInAttributes.Keys.ETHERTYPE.toJSON());
                    System.out.println("Ethertype: " + ethertype);
                    String macSrcAddr = json.getString(PacketInAttributes.Keys.DL_SRC.toJSON());
                    System.out.println("Source MAC address: " + macSrcAddr);
                    if (json.has(PacketInAttributes.Keys.NW_SRC.toJSON())) {
                        InetAddress nwSrcAddr;
                        try {
                            nwSrcAddr = InetAddress.getByName(PacketInAttributes.Keys.NW_SRC.toJSON());
                            System.out.println(nwSrcAddr);
                        } catch (UnknownHostException e) {
                            System.err.println("Invalid source IP address: " + e.getMessage());
                        }
                    }
                    JSONObject nodeJson = json.getJSONObject(PacketInAttributes.Keys.NODE.toJSON());
                    String nodeId = nodeJson.getString(NodeAttributes.Keys.ID.toJSON());
                    System.out.println("Node (switch): " + nodeId);
                    String inport = json.getString(PacketInAttributes.Keys.INGRESS_PORT.toJSON());
                    System.out.println("Ingress port: " + inport);
                } catch (JSONException e) {
                    System.err.println(e.getMessage());
                }

                // If you want to use your own packet parser, you can also get
                // the raw packet data.

                String packetDataBase64 = json.getString(PacketInAttributes.Keys.PACKET.toJSON());
                byte[] packetData = DatatypeConverter.parseBase64Binary(packetDataBase64);
                // Add your own custom packet parsing here ... we just print the raw data here.
                for (int i = 0; i < packetData.length; i++) {
                    if (i % 16 == 0) {
                        System.out.println();
                    }
                    System.out.print(String.format("%02X ", packetData[i]) + " ");
                }
                System.out.println();
            }
        } catch (JMSException e) {
            System.err.println(e.getMessage());
        }
    }
}

From source file:org.sdnmq.jms_demoapps.SimplePacketSender.java

public static void main(String[] args) {
    // Standard JMS setup.
    try {/*from   ww w.  ja  v a  2 s.  com*/
        // Uses settings from file jndi.properties if file is in CLASSPATH.
        ctx = new InitialContext();
    } catch (NamingException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        queueFactory = (QueueConnectionFactory) ctx.lookup("QueueConnectionFactory");
    } catch (NamingException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        connection = queueFactory.createQueueConnection();
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        packetForwarderQueue = (Queue) ctx.lookup(PACKETFORWARDER_QUEUE_NAME);
    } catch (NameNotFoundException e) {
        System.err.println(e.getMessage());
        die(-1);
    } catch (NamingException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        sender = session.createSender(packetForwarderQueue);
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        connection.start();
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    // Create packet using OpenDaylight packet classes (or any other packet parser/constructor you like most)
    // In most use cases, you will not create the complete packet yourself from scratch
    // but rather use a packet received from a packet-in event as basis. Let's assume that
    // the received packet-in event looks like this (in JSON representation as delivered by
    // the packet-in handler):
    //
    // {"node":{"id":"00:00:00:00:00:00:00:01","type":"OF"},"ingressPort":"1","protocol":1,"etherType":2048,"nwDst":"10.0.0.2","packet":"Io6q62g3mn66JKnjCABFAABUAABAAEABJqcKAAABCgAAAggAGFlGXgABELmmUwAAAAAVaA4AAAAAABAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc=","dlDst":"22:8E:AA:EB:68:37","nwSrc":"10.0.0.1","dlSrc":"9A:7E:BA:24:A9:E3"}
    //
    // Thus, we can use the "packet" field to re-construct the raw packet data from Base64-encoding:
    String packetInBase64 = "Io6q62g3mn66JKnjCABFAABUAABAAEABJqcKAAABCgAAAggAGFlGXgABELmmUwAAAAAVaA4AAAAAABAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc=";
    byte[] packetData = DatatypeConverter.parseBase64Binary(packetInBase64);
    // Now we can use the OpenDaylight classes to get Java objects for this packet:
    Ethernet ethPkt = new Ethernet();
    try {
        ethPkt.deserialize(packetData, 0, packetData.length * 8);
    } catch (Exception e) {
        System.err.println("Failed to decode packet");
        die(-1);
    }
    if (ethPkt.getEtherType() == 0x800) {
        IPv4 ipv4Pkt = (IPv4) ethPkt.getPayload();
        // We could go on parsing layer by layer ... but you got the idea already I think.
        // So let's make some change to the packet to make it more interesting:
        InetAddress newDst = null;
        try {
            newDst = InetAddress.getByName("10.0.0.2");
        } catch (UnknownHostException e) {
            die(-1);
        }
        assert (newDst != null);
        ipv4Pkt.setDestinationAddress(newDst);
    }
    // Now we can get the binary data of the new packet to be forwarded.
    byte[] pktBinary = null;
    try {
        pktBinary = ethPkt.serialize();
    } catch (PacketException e1) {
        System.err.println("Failed to serialize packet");
        die(-1);
    }
    assert (pktBinary != null);

    // Encode packet to Base64 textual representation to be sent in JSON.
    String pktBase64 = DatatypeConverter.printBase64Binary(pktBinary);

    // We need to tell the packet forwarder, which node should forward the packet.
    // In OpenDaylight, a node is identified by node id and node type (like "OF" for OpenFlow).
    // For a list of all node attributes, cf. class NodeAttributes.
    // For a list of possible node types, cf. class NodeAttributes.TypeValues.
    JSONObject nodeJson = new JSONObject();
    String nodeId = "00:00:00:00:00:00:00:01";
    nodeJson.put(NodeAttributes.Keys.ID.toJSON(), nodeId);
    nodeJson.put(NodeAttributes.Keys.TYPE.toJSON(), NodeAttributes.TypeValues.OF.toJSON());

    // Create a packet forwarding request in JSON representation.
    // All attributes are described in class PacketForwarderRequestAttributes.
    JSONObject packetFwdRequestJson = new JSONObject();
    packetFwdRequestJson.put(PacketForwarderRequestAttributes.Keys.NODE.toJSON(), nodeJson);
    packetFwdRequestJson.put(PacketForwarderRequestAttributes.Keys.EGRESS_PORT.toJSON(), 1);
    packetFwdRequestJson.put(PacketForwarderRequestAttributes.Keys.PACKET.toJSON(), pktBase64);

    // Send the request by posting it to the packet forwarder queue.

    System.out.println("Sending packet forwarding request: ");
    System.out.println(packetFwdRequestJson.toString());

    try {
        TextMessage msg = session.createTextMessage();
        msg.setText(packetFwdRequestJson.toString());
        sender.send(msg);
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    die(0);
}

From source file:se.vgregion.service.barium.BariumRestClientIT.java

License:asdf

public static void main(String[] args) {

    try {//w ww  .ja v  a2 s  .  co  m
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "LDAP://my.ldap.server:389"); //replace with your server URL/IP
        //only DIGEST-MD5 works with our Windows Active Directory
        env.put(Context.SECURITY_AUTHENTICATION, "DIGEST-MD5"); //No other SALS worked with me
        env.put(Context.SECURITY_PRINCIPAL, "user1"); // specify the username ONLY to let Microsoft Happy
        env.put(Context.SECURITY_CREDENTIALS, "secret1"); //the password

        DirContext ctx = new InitialDirContext(env);

        ctx.close();

    } catch (NamingException ne) {
        System.out.println("Error authenticating user:");
        System.out.println(ne.getMessage());
        return;
    }

    //if no exception, the user is already authenticated.
    System.out.println("OK, successfully authenticating user");
}

From source file:org.sdnmq.jms_demoapps.SimpleStaticFlowProgrammer.java

public static void main(String[] args) {
    // Standard JMS setup.
    try {//w w  w .j av  a2  s . c o  m
        // Uses settings from file jndi.properties if file is in CLASSPATH.
        ctx = new InitialContext();
    } catch (NamingException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        queueFactory = (QueueConnectionFactory) ctx.lookup("QueueConnectionFactory");
    } catch (NamingException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        connection = queueFactory.createQueueConnection();
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        flowProgrammerQueue = (Queue) ctx.lookup(FLOWPROGRAMMER_QUEUE_NAME);
    } catch (NameNotFoundException e) {
        System.err.println(e.getMessage());
        die(-1);
    } catch (NamingException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        sender = session.createSender(flowProgrammerQueue);
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    try {
        connection.start();
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    // First, create the flow specification as JSON object.
    // A flow consists of a match, set of actions, and priority.        
    // The match: for a list of all possible match attributes, cf. class MatchAttributes.
    JSONObject matchJson = new JSONObject();
    String inPort = "1";
    matchJson.put(MatchAttributes.Keys.INGRESS_PORT.toJSON(), inPort);

    // The action: for a list of all possible action attributes, cf. class ActionAttributes. 
    JSONObject actionJson = new JSONObject();
    actionJson.put(ActionAttributes.Keys.ACTION.toJSON(), ActionAttributes.ActionTypeValues.DROP.toJSON());

    // A flow can have a list of different actions. We specify a list of actions
    // as JSON array (here, the array only contains one action).
    JSONArray actionsJson = new JSONArray();
    actionsJson.put(actionJson);

    // The flow consists of a match specification, action specification, and priority
    // (cf. class FlowAttributes)
    JSONObject flowJson = new JSONObject();
    flowJson.put(FlowAttributes.Keys.MATCH.toJSON(), matchJson);
    flowJson.put(FlowAttributes.Keys.ACTIONS.toJSON(), actionsJson);
    flowJson.put(FlowAttributes.Keys.PRIORITY.toJSON(), 0);

    // We need to tell the flow programmer, which node to program.
    // In OpenDaylight, a node is identified by node id and node type (like "OF" for OpenFlow).
    // For a list of all node attributes, cf. class NodeAttributes.
    // For a list of possible node types, cf. class NodeAttributes.TypeValues.

    JSONObject nodeJson = new JSONObject();
    String nodeId = "00:00:00:00:00:00:00:01";
    nodeJson.put(NodeAttributes.Keys.ID.toJSON(), nodeId);
    nodeJson.put(NodeAttributes.Keys.TYPE.toJSON(), NodeAttributes.TypeValues.OF.toJSON());

    // Create the FlowProgrammer request in JSON representation.
    // To add a flow, we need to specify the command, the flow, and the node to be programmed
    // (cf. class FlowProgrammerRequestAttributes).

    JSONObject addRequestJson = new JSONObject();
    // All possible commands are specified in FlowProgrammerRequestAttributes.CommandValues
    addRequestJson.put(FlowProgrammerRequestAttributes.Keys.COMMAND.toJSON(),
            FlowProgrammerRequestAttributes.CommandValues.ADD.toJSON());
    String flowName = "DemoFlow";
    addRequestJson.put(FlowProgrammerRequestAttributes.Keys.FLOW_NAME.toJSON(), flowName);
    addRequestJson.put(FlowProgrammerRequestAttributes.Keys.FLOW.toJSON(), flowJson);
    addRequestJson.put(FlowProgrammerRequestAttributes.Keys.NODE.toJSON(), nodeJson);

    // Program the flow by sending the request to the flow programmer queue.

    System.out.println("Programming flow with following request: ");
    System.out.println(addRequestJson.toString());

    try {
        TextMessage msg = session.createTextMessage();
        msg.setText(addRequestJson.toString());
        sender.send(msg);
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    // Delete the flow again after 10 s.

    System.out.println("Waiting 30 s ...");

    try {
        Thread.sleep(30000);
    } catch (InterruptedException e) {
    }

    // A delete request just contains the flow name to be deleted together with the delete command.

    JSONObject deleteRequestJson = new JSONObject();
    deleteRequestJson.put(FlowProgrammerRequestAttributes.Keys.COMMAND.toJSON(),
            FlowProgrammerRequestAttributes.CommandValues.DELETE.toJSON());
    deleteRequestJson.put(FlowProgrammerRequestAttributes.Keys.FLOW_NAME.toJSON(), flowName);

    // Delete the flow by sending the delete request to the flow programmer queue.

    System.out.println("Deleting flow with the following request: ");
    System.out.println(deleteRequestJson.toString());

    try {
        TextMessage msg = session.createTextMessage();
        msg.setText(deleteRequestJson.toString());
        sender.send(msg);
    } catch (JMSException e) {
        System.err.println(e.getMessage());
        die(-1);
    }

    die(0);
}

From source file:hermes.browser.HermesBrowser.java

public static void main(String[] args) {
    log.debug("Hermes Browser " + Hermes.VERSION + " starting...");
    log.debug("working directory: " + new File(".").getAbsolutePath());

    Hermes.events.addConnectionListener(new ConnectionListener() {
        public void onConnectionOpen(Hermes hermes) {
            log.debug("Connection " + hermes.getId() + " opened");
        }//from  w  w  w  .  j a  v a 2 s  .  co m

        public void onConnectionClosed(Hermes hermes) {
            log.debug("Connection " + hermes.getId() + " closed");
        }
    });

    //
    // Need to bootstrap objects into the singleton manager... hack for now.

    JVMUtils.forceInit(SingletonManager.class);
    JVMUtils.forceInit(ThreadPool.class);
    JVMUtils.forceInit(SimpleClassLoaderManager.class);

    //
    // Commented out as this is for debug use only.
    // RepaintManager.setCurrentManager(new ThreadCheckingRepaintManager());

    //
    // Note this is the license for the JIDE Framework, it is licenced
    // to Colin Crist and the Hermes project and should not be used for any
    // other purpose
    //

    Lm.verifyLicense("Colin Crist", "Hermes", "9vkNAfxF1lvVyW7uZXYjpxFskycSGLw1");

    //
    // See http://www.jidesoft.com for licensing terms.

    //
    // Register a converter from a String to a File with PropertyUtils.

    ConvertUtils.register(new Converter() {
        public Object convert(Class arg0, Object filename) {
            return new File((String) filename);
        }
    }, File.class);

    SplashScreen.create(IconCache.getIcon("hermes.splash"));
    SplashScreen.show();

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                ui = new HermesBrowser(HERMES_TITLE);

                ui.initJIDE();

                try {
                    ui.loadConfig();
                } catch (NamingException ex) {
                    log.fatal("cannot initialise hermes: " + ex.getMessage(), ex);

                    System.exit(1);
                } catch (HeadlessException ex) {
                    log.fatal("cannot initialise hermes browser, no head: " + ex.getMessage(), ex);
                    System.exit(1);
                }

                ui.initUI();
                ui.init();

                ui.getLayoutPersistence().setProfileKey(ui.getUserProfileName());
                ui.getLayoutPersistence().loadLayoutData();

                // This must be done after the layout has been set otherwise
                // the
                // frames are hidden.

                final ArrayList<WatchConfig> tmpList = new ArrayList<WatchConfig>(ui.getConfig().getWatch());

                ui.getLoader().getConfig().getWatch().clear();

                for (WatchConfig wConfig : tmpList) {
                    ui.createWatch(wConfig);
                }

                ui.firstLoad = false;
            } catch (Exception ex) {
                log.fatal("cannot initialise hermes browser: " + ex.getMessage(), ex);
            }
        }
    });
}

From source file:gsn.storage.DataSources.java

public static BasicDataSource getDataSource(DBConnectionInfo dci) {
    BasicDataSource ds = null;/*from w  w w.  j a  v a 2s .  c o  m*/
    try {
        ds = (BasicDataSource) GSNContext.getMainContext().lookup(Integer.toString(dci.hashCode()));
        if (ds == null) {
            ds = new BasicDataSource();
            ds.setDriverClassName(dci.getDriverClass());
            ds.setUsername(dci.getUserName());
            ds.setPassword(dci.getPassword());
            ds.setUrl(dci.getUrl());
            //ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
            //ds.setAccessToUnderlyingConnectionAllowed(true); 
            GSNContext.getMainContext().bind(Integer.toString(dci.hashCode()), ds);
            logger.warn("Created a DataSource to: " + ds.getUrl());
        }
    } catch (NamingException e) {
        logger.error(e.getMessage(), e);
    }
    return ds;
}

From source file:be.fedict.hsm.model.security.AdministratorSecurityBean.java

public static AdministratorSecurityBean getInstance() {
    try {//from  ww  w. j  ava 2  s . c om
        InitialContext initialContext = new InitialContext();
        return (AdministratorSecurityBean) initialContext.lookup(JNDI_NAME);
    } catch (NamingException e) {
        throw new RuntimeException("JNDI error: " + e.getMessage(), e);
    }
}