List of usage examples for javax.naming InitialContext lookup
public Object lookup(Name name) throws NamingException
From source file:quickforms.controller.PutLookup.java
/** * Handles the HTTP/* ww w .j a v a 2 s . c o m*/ * <code>POST</code> method. * * @param request servlet request * @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("text/html;charset=UTF-8"); String application = ""; String field = ""; System.out.println("Saving Lookup"); Database db = null; String json = null; ArrayList<LookupPair> filter = null; PrintWriter out = response.getWriter(); try { List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : items) { if (item.getFieldName().equals("app")) { application = item.getString(); InitialContext cxt = new InitialContext(); DataSource ds = (DataSource) cxt.lookup("java:/comp/env/jdbc/" + application); db = new Database(ds); } else if (item.getFieldName().equals("field")) { field = item.getString(); } else if (item.getFieldName().equals("filter")) { filter = GetMultiData.getFilterList(item.getString()); } } for (FileItem item : items) { System.out.println("Item " + item); if (!item.isFormField()) { File csv = saveFile(item); db.updateLookup(application, field, parseLookup(csv, field), filter); } } } catch (Exception e) { Logger.log(application, e); out.append("Error : " + e.toString()); db.disconnect(); } out.close(); }
From source file:br.ufc.ivela.servlets.ChallengeSolver.java
private ChallengeRemote getChallengeRemote() { ChallengeRemote challengeRemote = null; try {/* w w w .j a v a 2 s . c om*/ InitialContext initialContext = new InitialContext(); java.lang.Object ejbRemoteRef = initialContext .lookup("ChallengeBean#br.ufc.ivela.ejb.interfaces.ChallengeRemote"); challengeRemote = (ChallengeRemote) javax.rmi.PortableRemoteObject.narrow(ejbRemoteRef, ChallengeRemote.class); } catch (NamingException e) { log.error("Error Retrieving Challenge Remote", e); } return challengeRemote; }
From source file:org.dspace.services.email.EmailServiceImpl.java
@Override public void init() { // See if there is already a Session in our environment String sessionName = cfg.getProperty("mail.session.name"); if (null == sessionName) { sessionName = "Session"; }/* w ww . j a va2s . c o m*/ try { InitialContext ctx = new InitialContext(null); session = (Session) ctx.lookup("java:comp/env/mail/" + sessionName); } catch (NamingException ex) { logger.warn("Couldn't get an email session from environment: {}", ex.getMessage()); } if (null != session) { logger.info("Email session retrieved from environment."); } else { // No Session provided, so create one logger.info("Initializing an email session from configuration."); Properties props = new Properties(); props.put("mail.transport.protocol", "smtp"); String host = cfg.getProperty("mail.server"); if (null != host) { props.put("mail.host", cfg.getProperty("mail.server")); } String port = cfg.getProperty("mail.server.port"); if (null != port) { props.put("mail.smtp.port", port); } if (null == cfg.getProperty("mail.server.username")) { session = Session.getInstance(props); } else { props.put("mail.smtp.auth", "true"); session = Session.getInstance(props, this); } // Set extra configuration properties String extras = cfg.getProperty("mail.extraproperties"); if ((extras != null) && (!"".equals(extras.trim()))) { String arguments[] = extras.split(","); String key, value; for (String argument : arguments) { key = argument.substring(0, argument.indexOf('=')).trim(); value = argument.substring(argument.indexOf('=') + 1).trim(); props.put(key, value); } } } }
From source file:org.openamf.invoker.EJBServiceInvoker.java
private Object getHome(ServiceRequest request) throws Exception { InitialContext context = new InitialContext(); if (home == null) { home = context.lookup(request.getServiceName()); }/*from w w w.java 2 s . co m*/ return home; }
From source file:com.ikon.util.MailUtils.java
/** * /*from w ww .j a v a2s. c om*/ */ private static Session getMailSession() { Session mailSession = null; try { InitialContext initialContext = new InitialContext(); Object obj = initialContext.lookup(Config.JNDI_BASE + "mail/openkm"); mailSession = (Session) PortableRemoteObject.narrow(obj, Session.class); } catch (javax.naming.NamingException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return mailSession; }
From source file:org.apache.jackrabbit.standalone.cli.ext.ConnectToJNDIServer.java
/** * {@inheritDoc}//from w ww .ja v a 2 s .co m */ public boolean execute(Context ctx) throws Exception { String url = (String) ctx.get(this.urlKey); if (log.isDebugEnabled()) { log.debug("connecting to jndi server at " + url); } InitialContext iCtx = new InitialContext(); ClientAdapterFactory adapter = new ClientAdapterFactory(); RemoteRepository remote = (RemoteRepository) iCtx.lookup(url); Repository repo = adapter.getRepository(remote); CommandHelper.setRepository(ctx, repo, "jndi " + url); return false; }
From source file:org.jetbrains.webdemo.servlet.AuthorizationServlet.java
@Override public void init() { try {//from w w w . j ava 2 s . c o m InitialContext initialContext = new InitialContext(); NamingContext envCtx = (NamingContext) initialContext.lookup("java:comp/env"); CommandRunner.setServerSettingFromTomcatConfig("google_key", (String) envCtx.lookup("google_key")); CommandRunner.setServerSettingFromTomcatConfig("google_secret", (String) envCtx.lookup("google_secret")); CommandRunner.setServerSettingFromTomcatConfig("twitter_key", (String) envCtx.lookup("twitter_key")); CommandRunner.setServerSettingFromTomcatConfig("twitter_secret", (String) envCtx.lookup("twitter_secret")); CommandRunner.setServerSettingFromTomcatConfig("facebook_key", (String) envCtx.lookup("facebook_key")); CommandRunner.setServerSettingFromTomcatConfig("facebook_secret", (String) envCtx.lookup("facebook_secret")); CommandRunner.setServerSettingFromTomcatConfig("github_key", (String) envCtx.lookup("github_key")); CommandRunner.setServerSettingFromTomcatConfig("github_secret", (String) envCtx.lookup("github_secret")); CommandRunner.setServerSettingFromTomcatConfig("jba_secret", (String) envCtx.lookup("jba_secret")); } catch (Throwable e) { log.fatal("Can't initialize authorization servlet", e); } }
From source file:org.mobicents.servlet.sip.example.JSleeSipsInteropServlet.java
@Override protected void doInvite(SipServletRequest req) throws ServletException, IOException { logger.info("Got Invite = " + req); try {/* w w w .j a va 2 s . co m*/ InitialContext ctx = new InitialContext(); CallManager callManagerRef = (CallManager) ctx.lookup("jslee-sips/CallManagerBean/local"); //saving the reference to the EJB ref for latter use to avoid doing jndi lookup calls req.getSession().setAttribute("callManagerRef", callManagerRef); logger.info("Calling out call manager"); callManagerRef.initMediaConnection(req); } catch (NamingException e) { logger.error("An exception occured while retrieving the EJB OrderApproval", e); } }
From source file:org.andromda.timetracker.service.test.SecurityServiceTest.java
@Test public void testGetUserDetails() throws Exception { try {//from w w w . ja v a 2 s. c o m final InitialContext initialContext = this.getInitialContext(); final SecurityServiceRemote securityService = (SecurityServiceRemote) initialContext .lookup("java:app/core/SecurityServiceBean/remote"); Assert.assertNotNull(securityService); SecurityServiceTest.logger.debug("Service : " + securityService.toString()); } catch (Exception e) { SecurityServiceTest.logger.warn("Failed test SecurityServiceBean", e); Assert.fail(); } }
From source file:org.hippoecm.repository.BootstrapHippoRepository.java
public synchronized void close() { if (backingRepository != null) { try {// w ww .ja va2 s . c o m InitialContext ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup(location); Connection conn = ds.getConnection(); { Statement stmt = conn.createStatement(); stmt.executeUpdate("DELETE FROM hippotbl"); stmt.close(); } conn.close(); } catch (SQLException ex) { log.error("bootstrap database failure: " + ex.getMessage()); } catch (NamingException ex) { log.error("bootstrap database name lookup failure: " + ex.getMessage()); } try { backingRepository.shutdown(); backingRepository = null; } catch (Exception ex) { // ignore } } repository = null; super.close(); }