public static void main(String[] args) { try { // Create and start connection InitialContext ctx = new InitialContext(); QueueConnectionFactory f = (QueueConnectionFactory) ctx.lookup("myQueueConnectionFactory"); QueueConnection con = f.createQueueConnection(); con.start(); // 2) create queue session QueueSession ses = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); // 3) get the Queue object Queue t = (Queue) ctx.lookup("myQueue"); // 4)create QueueSender object QueueSender sender = ses.createSender(t); // 5) create TextMessage object TextMessage msg = ses.createTextMessage(); // 6) write message BufferedReader b = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Enter Msg, end to terminate:"); String s = b.readLine(); if (s.equals("end")) break; msg.setText(s); // 7) send message sender.send(msg); System.out.println("Message successfully sent."); } // 8) connection close con.close(); } catch (Exception e) { System.out.println(e); } }
public String doSpellingSuggestion(java.lang.String key, java.lang.String phrase) throws RemoteException { System.out.println("GoogleServletImpl.doSpellingSuggestion() " + " called with " + phrase); if (!gotInit) { throw new RuntimeException("Got business method before init()"); } String returnValue = "spelling suggestion from web"; if (phrase.equals("forwardejb")) { System.out.println("Forwarding spelling suggestion to ejbendpoint"); Service genericServiceWithWSDL = null; try { InitialContext ic = new InitialContext(); Service service = (Service) ic.lookup("java:comp/env/service/EjbDIIReference"); doDynamicProxyTest(service); GoogleSearchPort ejbPort = (GoogleSearchPort) service.getPort(GoogleSearchPort.class); returnValue = ejbPort.doSpellingSuggestion(key, phrase); } catch (Exception e) { e.printStackTrace(); throw new RemoteException(e.getMessage(), e); } } System.out.println("GoogleServletImpl returning " + returnValue); return returnValue; }
public static void main(String[] argv) { try { String dmds_name = null; String cpds_name = null; String pbds_name = null; if (argv.length == 3) { dmds_name = argv[0]; cpds_name = argv[1]; pbds_name = argv[2]; } else usage(); InitialContext ctx = new InitialContext(); DataSource dmds = (DataSource) ctx.lookup(dmds_name); dmds.getConnection().close(); System.out.println( "DriverManagerDataSource " + dmds_name + " sucessfully looked up and checked."); ConnectionPoolDataSource cpds = (ConnectionPoolDataSource) ctx.lookup(cpds_name); cpds.getPooledConnection().close(); System.out.println( "ConnectionPoolDataSource " + cpds_name + " sucessfully looked up and checked."); DataSource pbds = (DataSource) ctx.lookup(pbds_name); pbds.getConnection().close(); System.out.println( "PoolBackedDataSource " + pbds_name + " sucessfully looked up and checked."); } catch (Exception e) { e.printStackTrace(); } }
public DigitalLibraryServer() { try { Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces"); properties.put(Context.PROVIDER_URL, "localhost"); InitialContext jndi = new InitialContext(properties); ConnectionFactory conFactory = (ConnectionFactory) jndi.lookup("XAConnectionFactory"); connection = conFactory.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); try { counterTopic = (Topic) jndi.lookup("counterTopic"); } catch (NamingException NE1) { System.out.println("NamingException: " + NE1 + " : Continuing anyway..."); } if (null == counterTopic) { counterTopic = session.createTopic("counterTopic"); jndi.bind("counterTopic", counterTopic); } consumer = session.createConsumer(counterTopic); consumer.setMessageListener(this); System.out.println("Server started waiting for client requests"); connection.start(); } catch (NamingException NE) { System.out.println("Naming Exception: " + NE); } catch (JMSException JMSE) { System.out.println("JMS Exception: " + JMSE); JMSE.printStackTrace(); } }
public Connection getConnection() throws Exception { InitialContext ctx = null; ctx = new InitialContext(); if (getDataSourceJndiName() == null) throw (new Exception("Data Source JNDI name is null. Check whether the JNDI name is null.")); DataSource ds = (javax.sql.DataSource) ctx.lookup(getDataSourceJndiName()); Connection conn = ds.getConnection(); return conn; }
public static MyService getService(String jndiName) { MyService service = cache.getService(jndiName); if (service != null) { return service; } InitialContext context = new InitialContext(); MyService myService = (MyService) context.lookup(jndiName); cache.addService(myService); return myService; }
public static Service getService(String jndiName) { Service service = cache.getService(jndiName); if (service != null) { return service; } InitialContext context = new InitialContext(); Service service1 = (Service) context.lookup(jndiName); cache.addService(service1); return service1; }
public String doTest() { stat.addDescription("This is to test connector 1.5 " + "contracts."); String res = "NOT RUN"; debug("doTest() ENTER..."); boolean pass = false; try { try { InitialContext ic = new InitialContext(); System.out.println( "appclient lookup of java:app/jdbc/app-level-ds : " + ic.lookup("java:app/jdbc/app-level-ds")); } catch (Exception e) { e.printStackTrace(); } res = "ALL TESTS PASSED"; int testCount = 1; while (!done()) { notifyAndWait(); if (!done()) { debug("Running..."); pass = checkResults(expectedResults()); debug("Got expected results = " + pass); // do not continue if one test failed if (!pass) { res = "SOME TESTS FAILED"; stat.addStatus("ID Connector 1.6 test - " + testCount, stat.FAIL); } else { stat.addStatus("ID Connector 1.6 test - " + testCount, stat.PASS); } } else { break; } testCount++; } } catch (Exception ex) { System.out.println("Importing transaction test failed."); ex.printStackTrace(); res = "TEST FAILED"; } stat.printSummary("connector1.6ID"); debug("EXITING... STATUS = " + res); return res; }
/** * Constructor encargado de iniciar el contexto y el objeto DataSource. * * @param dataSourceName Nombre del DataSource que se empleará * @throws Exception La excepción que puede arrojarse se debe a que no se cree el objeto * DataSource. */ public DbConnection(String dataSourceName) throws Exception { try { this.dataSourceName = dataSourceName; InitialContext iCtx = new InitialContext(); this.dataSource = (javax.sql.DataSource) iCtx.lookup(dataSourceName); } catch (Exception e) { // System.out.print("Error en constructor de DBConnection: "+e.getMessage()); StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String msg = sw.toString(); // System.out.print("Error en constructor de DBConnection: " + msg); e.printStackTrace(); } }
@Before public void setUp() { try { hello = (Hello) ic.lookup("HelloBean/remote"); } catch (NamingException e) { e.printStackTrace(); } }
public static void main(String[] args) throws Exception { SimpleReporterAdapter stat = new SimpleReporterAdapter(); String testSuite = "StatementWrapper "; InitialContext ic = new InitialContext(); Object objRef = ic.lookup("java:comp/env/ejb/SimpleBMPHome"); SimpleBMPHome simpleBMPHome = (SimpleBMPHome) javax.rmi.PortableRemoteObject.narrow(objRef, SimpleBMPHome.class); SimpleBMP simpleBMP = simpleBMPHome.create(); stat.addDescription("JDBC Statement Wrapper Tests"); if (simpleBMP.statementTest()) { stat.addStatus(testSuite + " statementTest : ", stat.PASS); } else { stat.addStatus(testSuite + " statementTest : ", stat.FAIL); } if (simpleBMP.preparedStatementTest()) { stat.addStatus(testSuite + " preparedStatementTest : ", stat.PASS); } else { stat.addStatus(testSuite + " preparedStatementTest : ", stat.FAIL); } if (simpleBMP.callableStatementTest()) { stat.addStatus(testSuite + " callableStatementTest : ", stat.PASS); } else { stat.addStatus(testSuite + " callableStatementTest : ", stat.FAIL); } if (simpleBMP.metaDataTest()) { stat.addStatus(testSuite + " metaDataTest : ", stat.PASS); } else { stat.addStatus(testSuite + " metaDataTest : ", stat.FAIL); } if (simpleBMP.resultSetTest()) { stat.addStatus(testSuite + " resultSetTest : ", stat.PASS); } else { stat.addStatus(testSuite + " resultSetTest : ", stat.FAIL); } stat.printSummary(); }
public static void main(String[] argv) throws Exception { SimpleReporterAdapter stat = new SimpleReporterAdapter(); String testSuite = "ReconfigMaxPoolSize "; InitialContext ic = new InitialContext(); Object objRef = ic.lookup("java:comp/env/ejb/SimpleBMPHome"); SimpleBMPHome simpleBMPHome = (SimpleBMPHome) javax.rmi.PortableRemoteObject.narrow(objRef, SimpleBMPHome.class); SimpleBMP simpleBMP = simpleBMPHome.create(); stat.addDescription("Reconfig MaxPoolSize tests"); /* * Tests 1,2 use non-xa pool - so the 3rd param "useXA" is false * Tests 3,4 use xa pool - so the 3rd param "useXA" is true */ if ("1".equals(argv[0])) { if (simpleBMP.test1(10, true, false)) { stat.addStatus(testSuite + " test1 : ", stat.PASS); } else { stat.addStatus(testSuite + " test1 : ", stat.FAIL); } } else if ("2".equals(argv[0])) { if (simpleBMP.test1(19, false, false)) { stat.addStatus(testSuite + " test2 : ", stat.PASS); } else { stat.addStatus(testSuite + " test2 : ", stat.FAIL); } } else if ("3".equals(argv[0])) { if (simpleBMP.test1(10, false, true)) { stat.addStatus(testSuite + " test3 : ", stat.PASS); } else { stat.addStatus(testSuite + " test3 : ", stat.FAIL); } } else if ("4".equals(argv[0])) { if (simpleBMP.test1(19, false, true)) { stat.addStatus(testSuite + " test4 : ", stat.PASS); } else { stat.addStatus(testSuite + " test4 : ", stat.FAIL); } } System.out.println("jdbc reconfig-maxpoolsize status: "); stat.printSummary(); }
public static void main(String[] args) { try { QueueConnectionFactory queueConnectionFactory; QueueConnection queueConnection; QueueSession queueSession; QueueReceiver queueReceiver; Queue queue; TextMessage msg; // JNDI InitialContextを作成します InitialContext ctx = new InitialContext(); // Connection FactoryとQueueをLook upします queueConnectionFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY); queue = (Queue) ctx.lookup(QUEUE); // コネクションを作成 queueConnection = queueConnectionFactory.createQueueConnection(); // セッションを作成 queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); // キューレシーバーを作成 queueReceiver = queueSession.createReceiver(queue); // メッセージの配送をスタート queueConnection.start(); // メッセージの受信 while (true) { Message m = queueReceiver.receive(1); if (m != null) { if (m instanceof TextMessage) { msg = (TextMessage) m; System.out.println(msg.getText()); } else { break; } } } // 接続を切断 queueReceiver.close(); queueSession.close(); queueConnection.close(); } catch (Exception e) { e.printStackTrace(); } }
public static void main(String[] args) throws Exception { SimpleReporterAdapter stat = new SimpleReporterAdapter(); String testSuite = "notxconn"; InitialContext ic = new InitialContext(); Object objRef = ic.lookup("java:comp/env/ejb/SimpleSessionHome"); SimpleSessionHome simpleSessionHome = (SimpleSessionHome) javax.rmi.PortableRemoteObject.narrow(objRef, SimpleSessionHome.class); stat.addDescription("Running notxops testSuite2 "); SimpleSession simpleSession = simpleSessionHome.create(); if (simpleSession.test1()) { stat.addStatus(testSuite + " test1 : ", stat.PASS); } else { stat.addStatus(testSuite + " test1 : ", stat.FAIL); } stat.printSummary(); }
public static void main(String[] args) { try { Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); p.put(Context.PROVIDER_URL, "10.10.10.13:1100,10.10.10.14:1100"); // p.put(Context.PROVIDER_URL, "localhost:1100"); p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); InitialContext ctx = new InitialContext(p); StatelessSessionHome statelessSessionHome = (StatelessSessionHome) ctx.lookup("nextgen.StatelessSession"); EnterpriseEntityHome cmpHome = (EnterpriseEntityHome) ctx.lookup("nextgen.EnterpriseEntity"); StatelessSession statelessSession = statelessSessionHome.create(); EnterpriseEntity cmp = null; try { cmp = cmpHome.findByPrimaryKey("bill"); } catch (Exception ex) { cmp = cmpHome.create("bill"); } int count = 0; while (true) { System.out.println(statelessSession.callBusinessMethodB()); try { cmp.setOtherField(count++); } catch (Exception ex) { System.out.println("exception, trying to create it: " + ex); cmp = cmpHome.create("bill"); cmp.setOtherField(count++); } System.out.println("Entity: " + cmp.getOtherField()); Thread.sleep(2000); } } catch (NamingException nex) { if (nex.getRootCause() != null) { nex.getRootCause().printStackTrace(); } } catch (Exception ex) { ex.printStackTrace(); } }
/** Tasks to be carried out in the STARTUP_EVENT. Logs a message */ private void onStartTask() { ctx.log("LifecycleTopic: STARTUP_EVENT"); // my code QueueSession qsession[] = new QueueSession[10]; Queue queue[] = new Queue[10]; try { for (int i = 0; i < 10; i++) { // Get initial context ctx.log("Get initial context"); InitialContext initialContext = new InitialContext(); // look up the connection factory from the object store ctx.log("Looking up the queue connection factory from JNDI"); QueueConnectionFactory factory = (QueueConnectionFactory) initialContext.lookup("jms/QCFactory"); // look up queue from the object store ctx.log("Create queue connection"); QueueConnection qconn = factory.createQueueConnection(); ctx.log("Create queue session"); qsession[i] = qconn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); ctx.log("Looking up the queue from JNDI"); queue[i] = (Queue) initialContext.lookup("jms/SampleQueue"); } updateDB(); } catch (Exception e) { ctx.log("Exception caught in test code"); e.printStackTrace(); } // end my code // my code // createAccount(); // end my code }
public ResultSet getPrefixName() throws SQLException, NamingException { String sql_PrefixName = "SELECT prefix_id,prefixname,abbreviation FROM hex.ref_prefixname"; ctx = new InitialContext(); ds = (DataSource) ctx.lookup("jdbc/HEX"); conn = ds.getConnection(); pstmt = conn.prepareStatement(sql_PrefixName); rs = pstmt.executeQuery(); return rs; }
public void deleteAdminObject(String jndiName) throws ConnectorRuntimeException { try { InitialContext ic = new InitialContext(); ic.unbind(jndiName); } catch (NamingException ne) { ResourcesUtil resutil = ResourcesUtil.createInstance(); if (resutil.adminObjectBelongsToSystemRar(jndiName)) { return; } if (ne instanceof NameNotFoundException) { _logger.log(Level.FINE, "rardeployment.admin_object_delete_failure", jndiName); _logger.log(Level.FINE, "", ne); return; } ConnectorRuntimeException cre = new ConnectorRuntimeException("Failed to delete admin object from jndi"); cre.initCause(ne); _logger.log(Level.SEVERE, "rardeployment.admin_object_delete_failure", jndiName); _logger.log(Level.SEVERE, "", cre); throw cre; } }
@AfterClass public static void tearDownClass() throws Exception { ic.close(); }
public void closeConnection() throws SQLException, NamingException { ctx.close(); pstmt.close(); rs.close(); conn.close(); }
/** * See <a href="http://e-docs.bea.com/wls/docs100/javadocs/weblogic/common/T3StartupDef.html"> * http://e-docs.bea.com/wls/docs100/javadocs/weblogic/common/T3StartupDef.html</a> for more * information. * * @param str Virtual name by which the class is registered as a {@code startupClass} in the * {@code config.xml} file * @param params A hashtable that is made up of the name-value pairs supplied from the {@code * startupArgs} property * @return Result string (log message). * @throws Exception Thrown if error occurred. */ @SuppressWarnings({"unchecked", "CatchGenericClass"}) @Override public String startup(String str, Hashtable params) throws Exception { GridLogger log = new GridJavaLogger(LoggingHelper.getServerLogger()); cfgFile = (String) params.get(cfgFilePathParam); if (cfgFile == null) { throw new IllegalArgumentException("Failed to read property: " + cfgFilePathParam); } String workMgrName = (String) params.get(workMgrParam); URL cfgUrl = U.resolveGridGainUrl(cfgFile); if (cfgUrl == null) throw new ServerLifecycleException( "Failed to find Spring configuration file (path provided should be " + "either absolute, relative to GRIDGAIN_HOME, or relative to META-INF folder): " + cfgFile); GenericApplicationContext springCtx; try { springCtx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(springCtx); xmlReader.loadBeanDefinitions(new UrlResource(cfgUrl)); springCtx.refresh(); } catch (BeansException e) { throw new ServerLifecycleException( "Failed to instantiate Spring XML application context: " + e.getMessage(), e); } Map cfgMap; try { // Note: Spring is not generics-friendly. cfgMap = springCtx.getBeansOfType(GridConfiguration.class); } catch (BeansException e) { throw new ServerLifecycleException( "Failed to instantiate bean [type=" + GridConfiguration.class + ", err=" + e.getMessage() + ']', e); } if (cfgMap == null) throw new ServerLifecycleException( "Failed to find a single grid factory configuration in: " + cfgUrl); if (cfgMap.isEmpty()) throw new ServerLifecycleException("Can't find grid factory configuration in: " + cfgUrl); try { ExecutorService execSvc = null; MBeanServer mbeanSrv = null; for (GridConfiguration cfg : (Collection<GridConfiguration>) cfgMap.values()) { assert cfg != null; GridConfigurationAdapter adapter = new GridConfigurationAdapter(cfg); // Set logger. if (cfg.getGridLogger() == null) adapter.setGridLogger(log); if (cfg.getExecutorService() == null) { if (execSvc == null) execSvc = workMgrName != null ? new GridThreadWorkManagerExecutor(workMgrName) : new GridThreadWorkManagerExecutor(J2EEWorkManager.getDefault()); adapter.setExecutorService(execSvc); } if (cfg.getMBeanServer() == null) { if (mbeanSrv == null) { InitialContext ctx = null; try { ctx = new InitialContext(); mbeanSrv = (MBeanServer) ctx.lookup("java:comp/jmx/runtime"); } catch (Exception e) { throw new IllegalArgumentException( "MBean server was not provided and failed to obtain " + "Weblogic MBean server.", e); } finally { if (ctx != null) ctx.close(); } } adapter.setMBeanServer(mbeanSrv); } Grid grid = G.start(adapter, springCtx); // Test if grid is not null - started properly. if (grid != null) gridNames.add(grid.name()); } return getClass().getSimpleName() + " started successfully."; } catch (GridException e) { // Stop started grids only. for (String name : gridNames) G.stop(name, true); throw new ServerLifecycleException("Failed to start GridGain.", e); } }
public static void main(String[] args) throws Exception { SimpleReporterAdapter stat = new SimpleReporterAdapter(); String testSuite = "CustomValidation "; InitialContext ic = new InitialContext(); Object objRef = ic.lookup("java:comp/env/ejb/SimpleBMPHome"); SimpleBMPHome convalBMPHome = (SimpleBMPHome) javax.rmi.PortableRemoteObject.narrow(objRef, SimpleBMPHome.class); SimpleBMP convalBMP = convalBMPHome.create(); stat.addDescription("Custom Validation Tests"); if (args != null && args.length > 0) { String param = args[0]; switch (Integer.parseInt(param)) { case 1: { if (convalBMP.test1()) { stat.addStatus(testSuite + "test-1 ", stat.PASS); } else { stat.addStatus(testSuite + "test-1 ", stat.FAIL); } break; } case 3: { if (convalBMP.test1()) { stat.addStatus(testSuite + "test-3 ", stat.PASS); System.out.println("test-3 returned true as validation is enabled "); } else { stat.addStatus(testSuite + "test-3 ", stat.FAIL); } break; } case 4: { if (convalBMP.test1()) { stat.addStatus(testSuite + "test-4 ", stat.PASS); System.out.println("test-4 returned true as validation is enabled "); } else { stat.addStatus(testSuite + "test-4 ", stat.FAIL); } break; } case 2: { try { if (convalBMP.test1()) { stat.addStatus(testSuite + "test-2 ", stat.FAIL); } else { stat.addStatus(testSuite + "test-2 ", stat.PASS); System.out.println("test-2 returned false as validation is not enabled "); } } catch (Exception e) { stat.addStatus(testSuite + "test1 ", stat.PASS); } break; } } stat.printSummary(); } }
public static Connection getConnect() throws SQLException, NamingException { InitialContext ic = new InitialContext(); DataSource ds = (DataSource) ic.lookup("java:/comp/env/jdbc/chatdb"); return ds.getConnection(); }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html;charset=UTF-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; _jspx_resourceInjector = (org.apache.jasper.runtime.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write(" "); DataSource ds = null; Connection con = null; PreparedStatement ps = null; InitialContext ic; try { ic = new InitialContext(); ds = (DataSource) ic.lookup("java:/jdbc/AVMS"); // ds = (DataSource)ic.lookup( "java:/jboss" ); con = ds.getConnection(); ps = con.prepareStatement("SELECT * FROM dbo.ROLE"); // pr = con.prepareStatement("SELECT * FROM dbo.JMS_USERS"); ResultSet rs = ps.executeQuery(); while (rs.next()) { out.println("<br> " + rs.getString("role_name") + " | " + rs.getString("role_desc")); // out.println("<br> " +rs.getString("USERID") + " | " +rs.getString("PASSWD")); } rs.close(); ps.close(); } catch (Exception e) { out.println("Exception thrown :: " + e); } finally { if (con != null) { con.close(); } } out.write('\n'); out.write('\n'); } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }