List of usage examples for javax.naming InitialContext lookup
public Object lookup(Name name) throws NamingException
From source file:eu.learnpad.simulator.mon.manager.GlimpseManager.java
public void setupConnection(TopicConnectionFactory connectionFact, InitialContext initConn) { try {//ww w .j av a2s . c o m DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Creating connection object "); connection = connectionFact.createTopicConnection(); DebugMessages.ok(); DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Creating public session object "); publishSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); DebugMessages.ok(); DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Creating subscribe object"); subscribeSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); DebugMessages.ok(); DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Setting up destination topic "); connectionTopic = (Topic) initConn.lookup(serviceTopic); tPub = publishSession.createPublisher(connectionTopic); DebugMessages.ok(); DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Setting up reading topic "); tSub = subscribeSession.createSubscriber(connectionTopic, "DESTINATION = 'monitor'", true); tSub.setMessageListener(this); DebugMessages.ok(); DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Creating response dispatcher "); responder = new ResponseDispatcher(initConn, connectionFact, requestMap, learnerAssessmentManager); if (responder != null) DebugMessages.ok(); } catch (JMSException e) { e.printStackTrace(); } catch (NamingException e) { e.printStackTrace(); } }
From source file:org.nuxeo.ecm.core.storage.sql.management.RepositoryStatus.java
protected List<RepositoryManagement> getRepositories() throws NamingException { List<RepositoryManagement> list = new LinkedList<RepositoryManagement>(); InitialContext context; ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(RepositoryStatus.class.getClassLoader()); try {//w w w . ja v a2 s. co m context = new InitialContext(); } finally { Thread.currentThread().setContextClassLoader(cl); } // we search both JBoss-like and Glassfish-like prefixes // @see NXCore#getRepository for (String prefix : new String[] { "java:NXRepository", "NXRepository" }) { NamingEnumeration<Binding> bindings; try { bindings = context.listBindings(prefix); } catch (NamingException e) { continue; } NamingEnumeration<Binding> e = null; try { for (e = bindings; e.hasMore();) { Binding binding = e.nextElement(); String name = binding.getName(); if (binding.isRelative()) { name = prefix + '/' + name; } Object object = context.lookup(name); if (!(object instanceof RepositoryManagement)) { continue; } list.add((RepositoryManagement) object); } } finally { if (e != null) { e.close(); } } } if (list.size() == 0) { List<Repository> repos = RepositoryResolver.getRepositories(); for (Repository repo : repos) { list.add(repo); } } return list; }
From source file:org.tolven.web.RegisterAction.java
public List<SelectItem> getRealms() { if (realms == null) { TolvenContext tolvenContext;// ww w. j a v a2 s . c o m try { InitialContext ictx = new InitialContext(); tolvenContext = (TolvenContext) ictx.lookup("tolvenContext"); } catch (Exception ex) { throw new RuntimeException("Could not lookup tolvenContext", ex); } realms = new ArrayList<SelectItem>(); for (String realmId : tolvenContext.getRealmIds()) { realms.add(new SelectItem(realmId)); } } return realms; }
From source file:de.mpg.escidoc.services.dataacquisition.DataHandlerBean.java
/** * Operation for fetching data of type TEXTUALDATA. * /*from ww w .j a va2 s . c o m*/ * @param identifier * @param format * @return itemXML * @throws IdentifierNotRecognisedException * @throws SourceNotAvailableException * @throws AccessException * @throws FormatNotSupportedException */ private String fetchTextualData(String identifier, String trgFormatName, String trgFormatType, String trgFormatEncoding) throws IdentifierNotRecognisedException, AccessException, SourceNotAvailableException, FormatNotAvailableException, FormatNotRecognisedException { String fetchedItem = null; String item = null; boolean supportedProtocol = false; ProtocolHandler protocolHandler = new ProtocolHandler(); try { MetadataVO md = this.util.getMdObjectToFetch(this.currentSource, trgFormatName, trgFormatType, trgFormatEncoding); if (md == null) { return null; } String decoded = java.net.URLDecoder.decode(md.getMdUrl().toString(), this.currentSource.getEncoding()); md.setMdUrl(new URL(decoded)); md.setMdUrl(new URL(md.getMdUrl().toString().replaceAll(this.regex, identifier.trim()))); this.currentSource = this.sourceHandler.updateMdEntry(this.currentSource, md); // Select harvesting method if (this.currentSource.getHarvestProtocol().equalsIgnoreCase("oai-pmh")) { this.logger.debug("Fetch OAI record from URL: " + md.getMdUrl()); item = fetchOAIRecord(md); // Check the record for error codes protocolHandler.checkOAIRecord(item); supportedProtocol = true; } if (this.currentSource.getHarvestProtocol().equalsIgnoreCase("ejb")) { this.logger.debug("Fetch record via EJB."); item = this.fetchEjbRecord(md, identifier); supportedProtocol = true; } if (this.currentSource.getHarvestProtocol().equalsIgnoreCase("http")) { this.logger.debug("Fetch record via http."); item = this.fetchHttpRecord(md); supportedProtocol = true; } if (!supportedProtocol) { this.logger .warn("Harvesting protocol " + this.currentSource.getHarvestProtocol() + " not supported."); throw new RuntimeException(); } fetchedItem = item; // Transform the itemXML if necessary if (item != null && !trgFormatName.trim().equalsIgnoreCase(md.getName().toLowerCase())) { TransformationBean transformer = new TransformationBean(); // Transform item metadata Format srcFormat = new Format(md.getName(), md.getMdFormat(), "*"); Format trgFormat = new Format(trgFormatName, trgFormatType, trgFormatEncoding); item = new String(transformer.transform(item.getBytes(this.enc), srcFormat, trgFormat, "escidoc"), this.enc); if (this.currentSource.getItemUrl() != null) { this.setItemUrl( new URL(this.currentSource.getItemUrl().toString().replace("GETID", identifier))); } try { // Create component if supported String name = trgFormatName.replace("item", "component"); Format trgFormatComponent = new Format(name, trgFormatType, trgFormatEncoding); if (transformer.checkTransformation(srcFormat, trgFormatComponent)) { byte[] componentBytes = transformer.transform(fetchedItem.getBytes(this.enc), srcFormat, trgFormatComponent, "escidoc"); if (componentBytes != null) { String componentXml = new String(componentBytes, this.enc); InitialContext initialContext = new InitialContext(); XmlTransforming xmlTransforming = (XmlTransforming) initialContext .lookup(XmlTransforming.SERVICE_NAME); this.componentVO = xmlTransforming.transformToFileVO(componentXml); } } } catch (Exception e) { this.logger.info("No component was created from external sources metadata"); } } this.setContentType(trgFormatType); } catch (AccessException e) { this.logger.error("Access denied.", e); throw new AccessException(this.currentSource.getName()); } catch (IdentifierNotRecognisedException e) { this.logger.error("The Identifier " + identifier + "was not recognized by source " + this.currentSource.getName() + ".", e); throw new IdentifierNotRecognisedException(e); } catch (BadArgumentException e) { this.logger.error("The request contained illegal arguments", e); throw new RuntimeException(e); } catch (FormatNotRecognisedException e) { this.logger.error("The requested format was not recognised by the import source", e); throw new FormatNotRecognisedException(e); } catch (Exception e) { throw new RuntimeException(e); } return item; }
From source file:org.jahia.services.content.JCRStoreProvider.java
protected Repository getRepositoryByJNDI() { Repository instance = null;//from w w w.j a v a 2 s. com try { Hashtable<String, String> env = new Hashtable<String, String>(); InitialContext initctx = new InitialContext(env); instance = (Repository) initctx.lookup(repositoryName); logger.info("Repository {} acquired via JNDI", getKey()); } catch (NamingException e) { logger.error("Cannot get by JNDI", e); } return instance; }
From source file:jdao.JDAO.java
public static Context retrieveContext(String jndi_path) { InitialContext jndiContext = null; Context env = null;/*from w w w .ja v a 2 s .c om*/ try { log("INFO: resolving " + jndi_path); env = jndiContext = new InitialContext(); env = (Context) jndiContext.lookup(jndi_path); } catch (Exception xe) { try { Name jname = jndiContext.getNameParser(jndi_path).parse(jndi_path); Enumeration<String> en = jname.getAll(); while (en.hasMoreElements()) { String name = en.nextElement(); Context tmp = null; try { tmp = (Context) env.lookup(name); env = (Context) env.lookup(name); } catch (NameNotFoundException nnf) { log("INFO: creating " + name); env = env.createSubcontext(name); } } } catch (Exception xe2) { log("ERROR: resolving " + jndi_path, xe2); } } return env; }
From source file:de.mpg.mpdl.inge.dataacquisition.DataHandlerBean.java
/** * Operation for fetching data of type TEXTUALDATA. * /* www. j av a2 s . c o m*/ * @param identifier * @param format * @return itemXML * @throws IdentifierNotRecognisedException * @throws SourceNotAvailableException * @throws AccessException * @throws FormatNotSupportedException */ private String fetchTextualData(String identifier, String trgFormatName, String trgFormatType, String trgFormatEncoding) throws IdentifierNotRecognisedException, AccessException, SourceNotAvailableException, FormatNotAvailableException, FormatNotRecognisedException { String fetchedItem = null; String item = null; boolean supportedProtocol = false; ProtocolHandler protocolHandler = new ProtocolHandler(); try { MetadataVO md = this.util.getMdObjectToFetch(this.currentSource, trgFormatName, trgFormatType, trgFormatEncoding); if (md == null) { return null; } String decoded = java.net.URLDecoder.decode(md.getMdUrl().toString(), this.currentSource.getEncoding()); md.setMdUrl(new URL(decoded)); md.setMdUrl(new URL(md.getMdUrl().toString().replaceAll(this.regex, identifier.trim()))); this.currentSource = this.sourceHandler.updateMdEntry(this.currentSource, md); // Select harvesting method if (this.currentSource.getHarvestProtocol().equalsIgnoreCase("oai-pmh")) { this.logger.debug("Fetch OAI record from URL: " + md.getMdUrl()); item = fetchOAIRecord(md); // Check the record for error codes protocolHandler.checkOAIRecord(item); supportedProtocol = true; } if (this.currentSource.getHarvestProtocol().equalsIgnoreCase("ejb")) { this.logger.debug("Fetch record via EJB."); item = this.fetchEjbRecord(md, identifier); supportedProtocol = true; } if (this.currentSource.getHarvestProtocol().equalsIgnoreCase("http")) { this.logger.debug("Fetch record via http."); item = this.fetchHttpRecord(md); supportedProtocol = true; } if (!supportedProtocol) { this.logger .warn("Harvesting protocol " + this.currentSource.getHarvestProtocol() + " not supported."); throw new RuntimeException(); } fetchedItem = item; // Transform the itemXML if necessary if (item != null && !trgFormatName.trim().equalsIgnoreCase(md.getName().toLowerCase())) { TransformationBean transformer = new TransformationBean(); // Transform item metadata Format srcFormat = new Format(md.getName(), md.getMdFormat(), "*"); Format trgFormat = new Format(trgFormatName, trgFormatType, trgFormatEncoding); item = new String(transformer.transform(item.getBytes(this.enc), srcFormat, trgFormat, "escidoc"), this.enc); if (this.currentSource.getItemUrl() != null) { this.setItemUrl( new URL(this.currentSource.getItemUrl().toString().replace("GETID", identifier))); } try { // Create component if supported String name = trgFormatName.replace("item", "component"); Format trgFormatComponent = new Format(name, trgFormatType, trgFormatEncoding); if (transformer.checkTransformation(srcFormat, trgFormatComponent)) { byte[] componentBytes = transformer.transform(fetchedItem.getBytes(this.enc), srcFormat, trgFormatComponent, "escidoc"); if (componentBytes != null) { String componentXml = new String(componentBytes, this.enc); InitialContext initialContext = new InitialContext(); de.mpg.mpdl.inge.xmltransforming.XmlTransforming xmlTransforming = (de.mpg.mpdl.inge.xmltransforming.XmlTransforming) initialContext .lookup(de.mpg.mpdl.inge.xmltransforming.XmlTransforming.SERVICE_NAME); this.componentVO = xmlTransforming.transformToFileVO(componentXml); } } } catch (Exception e) { this.logger.info("No component was created from external sources metadata"); } } this.setContentType(trgFormatType); } catch (AccessException e) { this.logger.error("Access denied.", e); throw new AccessException(this.currentSource.getName()); } catch (IdentifierNotRecognisedException e) { this.logger.error("The Identifier " + identifier + "was not recognized by source " + this.currentSource.getName() + ".", e); throw new IdentifierNotRecognisedException(e); } catch (BadArgumentException e) { this.logger.error("The request contained illegal arguments", e); throw new RuntimeException(e); } catch (FormatNotRecognisedException e) { this.logger.error("The requested format was not recognised by the import source", e); throw new FormatNotRecognisedException(e); } catch (Exception e) { throw new RuntimeException(e); } return item; }
From source file:br.org.indt.ndg.server.survey.SurveyHandlerBean.java
public void sendSlicedSurvey(NdgUser userLogged, String idSurvey, ArrayList<String> listOfDevices) throws MSMApplicationException, MSMSystemException { for (String deviceNumber : listOfDevices) { SurveySmsSlicer surveySMSSlicer = new SurveySmsSlicer(userLogged.getUserAdmin(), idSurvey, deviceNumber);/* w w w.j a v a 2 s . c o m*/ ArrayList<SMSMessageVO> arrayOfSMS = surveySMSSlicer.getSlicedSurvey(); for (SMSMessageVO smsMessageVO : arrayOfSMS) { smsMessageVO.port = SMSModemHandler.SMS_NDG_PORT; businessDelegate.sendSMS(smsMessageVO); } TransactionLogVO tl = new TransactionLogVO(); tl.setDtLog(new Timestamp(System.currentTimeMillis())); InitialContext initialContext = null; IMEIManager imeiManager = null; try { initialContext = new InitialContext(); imeiManager = (IMEIManager) initialContext.lookup("ndg-core/IMEIManagerBean/remote"); } catch (NamingException e) { e.printStackTrace(); } ImeiVO imeivo = imeiManager.findImeiByMsisdn(deviceNumber); tl.setUser(userLogged.getUsername()); tl.setImei(imeivo.getImei()); tl.setSurveyId(idSurvey); tl.setStatus(TransactionLogVO.STATUS_SUCCESS); tl.setTransactionType(TransactionLogVO.TYPE_SEND_SURVEY); tl.setTransmissionMode(TransactionLogVO.MODE_SMS); // log the transaction status, as SUCCESS, when sending a survey by SMS TransactionLogManager transactionlogManager = null; try { transactionlogManager = (TransactionLogManager) initialContext .lookup("ndg-core/TransactionLogManagerBean/remote"); } catch (NamingException e) { e.printStackTrace(); } if (transactionlogManager != null) { transactionlogManager.logTransaction(tl); } } }
From source file:br.org.indt.ndg.server.survey.SurveyHandlerBean.java
@Override public ArrayList<String> rationSurveybyGPRS(NdgUser userlogged, String idSurvey, ArrayList<String> listOfDevices) throws MSMApplicationException, MSMSystemException { ArrayList<String> devicesToGetNewSurvey = new ArrayList<String>(); for (Iterator<String> iterator = listOfDevices.iterator(); iterator.hasNext();) { String deviceIMEI = iterator.next(); InitialContext initialContext = null; TransactionLogManager transactionlogManager = null; try {/*from w w w . ja v a 2 s . c o m*/ initialContext = new InitialContext(); transactionlogManager = (TransactionLogManager) initialContext .lookup("ndg-core/TransactionLogManagerBean/remote"); } catch (NamingException e) { new SurveyRationException(); } if (!transactionlogManager.existTransactionLog(TransactionLogVO.TYPE_SEND_SURVEY, idSurvey, TransactionLogVO.STATUS_AVAILABLE, TransactionLogVO.MODE_GPRS, deviceIMEI)) { TransactionLogVO t = new TransactionLogVO(); t.setUser(userlogged.getUsername()); t.setDtLog(new Timestamp(System.currentTimeMillis())); t.setTransmissionMode(TransactionLogVO.MODE_GPRS); t.setStatus(TransactionLogVO.STATUS_AVAILABLE); t.setTransactionType(TransactionLogVO.TYPE_SEND_SURVEY); t.setImei(deviceIMEI); t.setSurveyId(idSurvey); if (transactionlogManager != null) { transactionlogManager.logTransaction(t); } devicesToGetNewSurvey.add(deviceIMEI); } } return devicesToGetNewSurvey; }
From source file:br.org.indt.ndg.server.survey.SurveyHandlerBean.java
public void saveSurveyFromEditorToServer(String userName, String surveyContent) throws MSMApplicationException { SurveyParser parser = new SurveyParser(); StringBuffer buffer = new StringBuffer(surveyContent); InitialContext initialContext = null; UserManager userManager = null;/* ww w .j a va2 s . c o m*/ NdgUser user = null; SurveyXML survey = null; try { initialContext = new InitialContext(); userManager = (UserManager) initialContext.lookup("ndg-core/UserManagerBean/remote"); if (userManager != null) { user = userManager.findNdgUserByName(userName); } survey = parser.parseSurvey(buffer, "UTF-8"); } catch (NamingException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); throw new SurveyNotParsedException(); } catch (ParserConfigurationException e) { e.printStackTrace(); throw new SurveyNotParsedException(); } catch (IOException e) { e.printStackTrace(); throw new SurveyNotParsedException(); } if ((survey != null) && (user != null)) { try { if (MD5.checkMD5Survey(buffer, survey.getChecksum())) { Survey currentSurvey = manager.find(Survey.class, survey.getId()); if (currentSurvey != null) { updateSurvey(user, survey, buffer); } else { persistSurvey(user, survey, buffer); } } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw new SurveyNotParsedException(); } catch (IOException e) { e.printStackTrace(); throw new SurveyNotParsedException(); } } else { throw new SurveyNotRecordedException(); } }