Java Code Examples for javax.naming.NamingException

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project agile, under directory /agile-framework/src/main/java/org/apache/naming/.

Source file: ContextBindings.java

  31 
vote

/** 
 * Binds a naming context to a thread.
 * @param name Name of the context
 * @param token Security token
 */
public static void bindThread(Object name,Object token) throws NamingException {
  if (ContextAccessController.checkSecurityToken(name,token)) {
    Context context=(Context)contextNameBindings.get(name);
    if (context == null)     throw new NamingException(sm.getString("contextBindings.unknownContext",name));
    threadBindings.put(Thread.currentThread(),context);
    threadNameBindings.put(Thread.currentThread(),name);
  }
}
 

Example 2

From project arquillian-core, under directory /testenrichers/ejb/src/main/java/org/jboss/arquillian/testenricher/ejb/.

Source file: EJBInjectionEnricher.java

  31 
vote

protected Object lookupEJB(String[] jndiNames) throws Exception {
  Context initcontext=createContext();
  for (  String jndiName : jndiNames) {
    try {
      return initcontext.lookup(jndiName);
    }
 catch (    NamingException e) {
    }
  }
  throw new NamingException("No EJB found in JNDI, tried the following names: " + joinJndiNames(jndiNames));
}
 

Example 3

From project arquillian_deprecated, under directory /testenrichers/ejb/src/main/java/org/jboss/arquillian/testenricher/ejb/.

Source file: EJBInjectionEnricher.java

  30 
vote

protected Object lookupEJB(Class<?> fieldType,String mappedName) throws Exception {
  InitialContext initcontext=createContext();
  String[] jndiNames={"java:global/test.ear/test/" + fieldType.getSimpleName() + "Bean","java:global/test.ear/test/" + fieldType.getSimpleName(),"java:global/test/" + fieldType.getSimpleName(),"java:global/test/" + fieldType.getSimpleName() + "Bean","java:global/test/" + fieldType.getSimpleName() + "/no-interface","test/" + fieldType.getSimpleName() + "Bean/local","test/" + fieldType.getSimpleName() + "Bean/remote","test/" + fieldType.getSimpleName() + "/no-interface",fieldType.getSimpleName() + "Bean/local",fieldType.getSimpleName() + "Bean/remote",fieldType.getSimpleName() + "/no-interface"};
  if ((mappedName != null) && (!mappedName.equals(""))) {
    jndiNames=new String[]{mappedName};
  }
  for (  String jndiName : jndiNames) {
    try {
      return initcontext.lookup(jndiName);
    }
 catch (    NamingException e) {
    }
  }
  throw new NamingException("No EJB found in JNDI, tried the following names: " + joinJndiNames(jndiNames));
}
 

Example 4

From project activejdbc, under directory /activejdbc/src/test/java/org/javalite/activejdbc/.

Source file: ConnectionSpecTest.java

  29 
vote

@Test public void testJndi() throws NamingException, SQLException {
  ConnectionJndiSpec spec=new ConnectionJndiSpec("java/jdbc/DefaultDS");
  DB db=new DB("default");
  db.open(spec);
  a(db.connection()).shouldNotBeNull();
  db.close();
  DBException e=null;
  try {
    db.connection();
  }
 catch (  DBException ex) {
    e=ex;
  }
  a(e).shouldNotBeNull();
}
 

Example 5

From project activemq-apollo, under directory /apollo-itests/src/test/java/org/apache/activemq/apollo/joramtests/.

Source file: ApolloAdmin.java

  29 
vote

public void createQueue(String name){
  try {
    context.bind(name,base.protocol.createQueue(name));
  }
 catch (  NamingException e) {
    throw new RuntimeException(e);
  }
}
 

Example 6

From project AdServing, under directory /modules/server/adserver/src/main/java/net/mad/ads/server/utils/listener/configuration/.

Source file: AdServerModule.java

  29 
vote

private void initTracking(BaseContext context){
  try {
    String classname=RuntimeContext.getProperties().getProperty(AdServerConstants.CONFIG.PROPERTIES.TRACKINGSERVICE_CLASS,"");
    TrackingService trackService=(TrackingService)Class.forName(classname).newInstance();
    if (trackService instanceof H2TrackingService) {
      Context ctx=new InitialContext();
      ctx=(Context)ctx.lookup("java:comp/env");
      DataSource ds=(DataSource)ctx.lookup("jdbc/trackingds");
      context.put(TrackingContextKeys.EMBEDDED_TRACKING_DATASOURCE,ds);
    }
    trackService.open(context);
    bind(TrackingService.class).toInstance(trackService);
  }
 catch (  NamingException se) {
    logger.error("",se);
  }
catch (  ClassCastException cce) {
    logger.error("",cce);
  }
catch (  ServiceException e) {
    logger.error("",e);
  }
catch (  InstantiationException e) {
    logger.error("",e);
  }
catch (  IllegalAccessException e) {
    logger.error("",e);
  }
catch (  ClassNotFoundException e) {
    logger.error("",e);
  }
}
 

Example 7

From project agileBase, under directory /gtpb_server/src/com/gtwm/pb/servlets/.

Source file: AppController.java

  29 
vote

/** 
 * init() is called once automatically by the servlet container (e.g. Tomcat) at servlet startup. We use it to initialise various things, namely: a) create the DatabaseDefn object which is the top level application object. The DatabaseDefn object will load the list of tables & reports into memory when it is constructed. It will also configure and load the object database b) create a DataSource object here to pass to the DatabaseDefn. This data source then acts as a pool of connections from which a connection to the relational database can be called up whenever needed.
 */
public void init() throws ServletException {
  logger.info("Initialising " + AppProperties.applicationName);
  ServletContext servletContext=getServletContext();
  this.webAppRoot=servletContext.getRealPath("/");
  DataSource relationalDataSource=null;
  InitialContext initialContext=null;
  try {
    initialContext=new InitialContext();
    relationalDataSource=(DataSource)initialContext.lookup("java:comp/env/jdbc/agileBaseData");
    if (relationalDataSource == null) {
      throw new ServletException("Can't get data source");
    }
    this.relationalDataSource=relationalDataSource;
    this.databaseDefn=new DatabaseDefn(relationalDataSource,this.webAppRoot);
    servletContext.setAttribute("com.gtwm.pb.servlets.databaseDefn",this.databaseDefn);
    servletContext.setAttribute("com.gtwm.pb.servlets.relationalDataSource",this.relationalDataSource);
  }
 catch (  NullPointerException npex) {
    ServletUtilMethods.logException(npex,"Error initialising controller servlet");
    throw new ServletException("Error initialising controller servlet",npex);
  }
catch (  SQLException sqlex) {
    ServletUtilMethods.logException(sqlex,"Database error loading schema");
    throw new ServletException("Database error loading schema",sqlex);
  }
catch (  NamingException neex) {
    ServletUtilMethods.logException(neex,"Can't get initial context");
    throw new ServletException("Can't get initial context");
  }
catch (  RuntimeException rtex) {
    ServletUtilMethods.logException(rtex,"Runtime initialisation error");
    throw new ServletException("Runtime initialisation error",rtex);
  }
catch (  Exception ex) {
    ServletUtilMethods.logException(ex,"General initialisation error");
    throw new ServletException("General initialisation error",ex);
  }
  logger.info("Application fully loaded");
}
 

Example 8

From project ANNIS, under directory /annis-gui/src/main/java/annis/security/.

Source file: SimpleSecurityManager.java

  29 
vote

@Override public void storeUserProperties(AnnisUser user) throws NamingException, AuthenticationException, IOException {
  File configDir=new File(properties.getProperty(CONFIG_PATH));
  if (configDir.isDirectory()) {
    File usersDir=new File(configDir.getAbsolutePath() + "/users/");
    File fileOfUser=new File(usersDir.getAbsolutePath() + "/" + user.getUserName());
    if (fileOfUser.isFile()) {
      try {
        user.store(new FileOutputStream(fileOfUser,false),"");
      }
 catch (      IOException ex) {
        log.error("",ex);
      }
    }
  }
}
 

Example 9

From project api, under directory /weld-spi/src/main/java/org/jboss/weld/injection/spi/helpers/.

Source file: AbstractResourceServices.java

  29 
vote

public Object resolveResource(InjectionPoint injectionPoint){
  if (!injectionPoint.getAnnotated().isAnnotationPresent(Resource.class)) {
    throw new IllegalArgumentException("No @Resource annotation found on injection point " + injectionPoint);
  }
  if (injectionPoint.getMember() instanceof Method && ((Method)injectionPoint.getMember()).getParameterTypes().length != 1) {
    throw new IllegalArgumentException("Injection point represents a method which doesn't follow JavaBean conventions (must have exactly one parameter) " + injectionPoint);
  }
  String name=getResourceName(injectionPoint);
  try {
    return getContext().lookup(name);
  }
 catch (  NamingException e) {
    throw new RuntimeException("Error looking up " + name + " in JNDI",e);
  }
}
 

Example 10

From project arquillian-container-jbossas, under directory /jbossas-managed-4.2/src/main/java/org/jboss/arquillian/container/jbossas/managed_4_2/.

Source file: JBossASLocalContainer.java

  29 
vote

private Context createContext(Server server) throws NamingException {
  if (contextInst.get() == null) {
    contextInst.set(server.getNamingContext());
  }
  return contextInst.get();
}
 

Example 11

From project arquillian-extension-persistence, under directory /impl/src/main/java/org/jboss/arquillian/persistence/core/lifecycle/.

Source file: PersistenceTestTrigger.java

  29 
vote

private DataSource loadDataSource(String dataSourceName){
  try {
    final Context context=contextInstance.get();
    if (context == null) {
      throw new ContextNotAvailableException("No Naming Context available.");
    }
    return (DataSource)context.lookup(dataSourceName);
  }
 catch (  NamingException e) {
    throw new DataSourceNotFoundException("Unable to find data source for given name: " + dataSourceName,e);
  }
}
 

Example 12

From project autopatch, under directory /src/test/java/com/tacitknowledge/util/migration/jdbc/.

Source file: WebAppServletContextFactoryTest.java

  29 
vote

/** 
 * Tests that the new mechanism for configuring a launcher from a  servlet context works.
 * @throws NamingException a problem with the test
 */
public void testConfiguredContext() throws NamingException {
  JdbcMigrationLauncherFactory launcherFactory=new JdbcMigrationLauncherFactory();
  MockServletContext sc=new MockServletContext();
  String dbType="mysql";
  String sysName="testSystem";
  sc.setInitParameter("migration.systemname",sysName);
  sc.setInitParameter("migration.readonly","true");
  sc.setInitParameter("migration.databasetype",dbType);
  sc.setInitParameter("migration.patchpath","patches");
  sc.setInitParameter("migration.datasource","jdbc/testsource");
  MockDataSource ds=new MockDataSource();
  InitialContext context=new InitialContext();
  context.bind("java:comp/env/jdbc/testsource",ds);
  ServletContextEvent sce=new ServletContextEvent(sc);
  JdbcMigrationLauncher launcher=null;
  try {
    launcher=launcherFactory.createMigrationLauncher(sce);
  }
 catch (  MigrationException e) {
    e.printStackTrace();
    fail("There should not have been an exception");
  }
  JdbcMigrationContext jdbcContext=(JdbcMigrationContext)launcher.getContexts().keySet().iterator().next();
  assertEquals(dbType,jdbcContext.getDatabaseType().getDatabaseType());
  assertEquals(sysName,jdbcContext.getSystemName());
  assertEquals(true,launcher.isReadOnly());
}
 

Example 13

From project blacktie, under directory /jatmibroker-xatmi/src/main/java/org/jboss/narayana/blacktie/jatmibroker/core/transport/.

Source file: JtsTransactionImple.java

  29 
vote

private static boolean hasTransactionManager(){
  try {
    return (getTransactionManager() != null);
  }
 catch (  NamingException e) {
    return false;
  }
}
 

Example 14

From project bonecp, under directory /bonecp-benchmark/src/main/java/com/jolbox/benchmark/.

Source file: BenchmarkMain.java

  29 
vote

/** 
 * @param args
 * @throws ClassNotFoundException 
 * @throws PropertyVetoException 
 * @throws SQLException 
 * @throws NoSuchMethodException 
 * @throws InvocationTargetException 
 * @throws IllegalAccessException 
 * @throws InterruptedException 
 * @throws SecurityException 
 * @throws IllegalArgumentException 
 * @throws NamingException 
 * @throws ParseException 
 */
public static void main(String[] args) throws ClassNotFoundException, SQLException, PropertyVetoException, IllegalArgumentException, SecurityException, InterruptedException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NamingException, ParseException {
  Options options=new Options();
  options.addOption("t","threads",true,"Max number of threads");
  options.addOption("s","stepping",true,"Stepping of threads");
  options.addOption("p","poolsize",true,"Pool size");
  options.addOption("h","help",false,"Help");
  CommandLineParser parser=new PosixParser();
  CommandLine cmd=parser.parse(options,args);
  if (cmd.hasOption("h")) {
    HelpFormatter formatter=new HelpFormatter();
    formatter.printHelp("benchmark.jar",options);
    System.exit(1);
  }
  Class.forName("com.jolbox.bonecp.MockJDBCDriver");
  new MockJDBCDriver();
  BenchmarkTests tests=new BenchmarkTests();
  BenchmarkTests.threads=200;
  BenchmarkTests.stepping=20;
  BenchmarkTests.pool_size=200;
  System.out.println("JIT warm up");
  tests.testMultiThreadedConstantDelay(0);
  BenchmarkTests.threads=200;
  BenchmarkTests.stepping=5;
  BenchmarkTests.pool_size=100;
  if (cmd.hasOption("t")) {
    BenchmarkTests.threads=Integer.parseInt(cmd.getOptionValue("t","400"));
  }
  if (cmd.hasOption("s")) {
    BenchmarkTests.stepping=Integer.parseInt(cmd.getOptionValue("s","20"));
  }
  if (cmd.hasOption("p")) {
    BenchmarkTests.pool_size=Integer.parseInt(cmd.getOptionValue("p","200"));
  }
  System.out.println("Starting benchmark tests with " + BenchmarkTests.threads + " threads (stepping "+ BenchmarkTests.stepping+ ") using pool size of "+ BenchmarkTests.pool_size+ " connections");
  System.out.println("Starting tests");
  plotLineGraph(tests.testMultiThreadedConstantDelay(0),0,false);
  plotBarGraph("Single Thread","bonecp-singlethread-poolsize-" + BenchmarkTests.pool_size + "-threads-"+ BenchmarkTests.threads+ ".png",tests.testSingleThread());
  plotBarGraph("Prepared Statement\nSingle Threaded","bonecp-preparedstatement-single-poolsize-" + BenchmarkTests.pool_size + "-threads-"+ BenchmarkTests.threads+ ".png",tests.testPreparedStatementSingleThread());
}
 

Example 15

From project c3p0, under directory /src/java/com/mchange/v2/c3p0/jboss/.

Source file: C3P0PooledDataSource.java

  29 
vote

private void rebind(String unbindName) throws NamingException {
  InitialContext ictx=new InitialContext();
  if (unbindName != null)   ictx.unbind(unbindName);
  if (jndiName != null) {
    Name name=ictx.getNameParser(jndiName).parse(jndiName);
    Context ctx=ictx;
    for (int i=0, max=name.size() - 1; i < max; i++) {
      try {
        ctx=ctx.createSubcontext(name.get(i));
      }
 catch (      NameAlreadyBoundException ignore) {
        ctx=(Context)ctx.lookup(name.get(i));
      }
    }
    ictx.rebind(jndiName,combods);
  }
}
 

Example 16

From project camelpe, under directory /examples/loan-broker-jboss7/src/main/java/net/camelpe/examples/jboss7/loanbroker/queue/.

Source file: JBoss7CamelContextConfiguration.java

  29 
vote

private synchronized InitialContext getInitialContext() throws NamingException {
  if (this.initialContext == null) {
    this.initialContext=new InitialContext();
  }
  return this.initialContext;
}
 

Example 17

From project capedwarf-blue, under directory /appidentity/src/main/java/org/jboss/capedwarf/appidentity/.

Source file: CDIListener.java

  29 
vote

protected BeanManager getBeanManager(){
  Context nc=null;
  try {
    nc=new InitialContext();
    return (BeanManager)nc.lookup(STANDARD_BEAN_MANAGER_JNDI_NAME);
  }
 catch (  Exception e) {
    log.warning("Cannot find BeanManager: " + e);
    return null;
  }
 finally {
    if (nc != null) {
      try {
        nc.close();
      }
 catch (      NamingException ignored) {
      }
    }
  }
}
 

Example 18

From project capedwarf-green, under directory /javax-cache/src/main/java/org/jboss/capedwarf/cache/infinispan/.

Source file: InfinispanCacheFactory.java

  29 
vote

protected EmbeddedCacheManager checkDefaultNames(Context ctx) throws IOException {
  for (  String jndiName : defaultJndiNames) {
    try {
      return (EmbeddedCacheManager)ctx.lookup(jndiName);
    }
 catch (    NamingException ne) {
      String msg="Unable to retrieve CacheManager from JNDI [" + jndiName + "]";
      log.fine(msg + ": " + ne);
    }
  }
  throw new IOException("Cannot find default JNDI cache manager: " + Arrays.toString(defaultJndiNames));
}
 

Example 19

From project cas, under directory /cas-server-support-ldap/src/main/java/org/jasig/cas/adaptors/ldap/remote/.

Source file: RemoteIpLookupCredentialsToPrincipalResolver.java

  29 
vote

protected String extractPrincipalId(final Credentials credentials){
  final RemoteAddressCredentials c=(RemoteAddressCredentials)credentials;
  final String formattedIpAddress=getFormattedIpAddress(c.getRemoteAddress().trim());
  if (!StringUtils.hasText(formattedIpAddress)) {
    return null;
  }
  if (log.isDebugEnabled()) {
    log.debug("Original IP address: " + c.getRemoteAddress());
    log.debug("Formatted IP address: " + formattedIpAddress);
  }
  final String attributeId=getAttributeIds()[0];
  final List principalList=this.getLdapTemplate().search(getSearchBase(),LdapUtils.getFilterWithValues(getFilter(),formattedIpAddress),getSearchControls(),new AttributesMapper(){
    public Object mapFromAttributes(    final Attributes attrs) throws NamingException {
      final Attribute attribute=attrs.get(attributeId);
      return attribute == null ? null : attribute.get();
    }
  }
);
  if (principalList.isEmpty()) {
    log.debug("LDAP search returned zero results.");
    return null;
  }
  if (principalList.size() > 1) {
    log.error("LDAP search returned multiple results " + "for filter \"" + getFilter() + "\", "+ "which is not allowed.");
    return null;
  }
  return (String)principalList.get(0);
}
 

Example 20

From project cdi-extension-showcase, under directory /src/main/java/com/acme/wicketint/.

Source file: BeanWebApplicationFactory.java

  29 
vote

public WebApplication createApplication(WicketFilter filter){
  BeanManager bm;
  try {
    System.out.println("Trying java:comp/BeanManager...");
    bm=(BeanManager)new InitialContext().lookup("java:comp/BeanManager");
  }
 catch (  NamingException e) {
    try {
      System.out.println("Trying java:comp/env/BeanManager...");
      bm=(BeanManager)new InitialContext().lookup("java:comp/env/BeanManager");
    }
 catch (    NamingException e2) {
      throw new RuntimeException("Could not locate BeanManager in JNDI");
    }
  }
  Bean<WebApplicationBeanResolver> resolverBean=(Bean<WebApplicationBeanResolver>)bm.resolve(bm.getBeans(WebApplicationBeanResolver.class));
  CreationalContext<WebApplicationBeanResolver> cc=bm.createCreationalContext(resolverBean);
  WebApplicationBeanResolver resolver=(WebApplicationBeanResolver)bm.getReference(resolverBean,WebApplicationBeanResolver.class,cc);
  WebApplication webapp=resolver.resolveWebApplication();
  cc.release();
  return webapp;
}
 

Example 21

From project clutter, under directory /src/clutter/.

Source file: SMTPClient.java

  29 
vote

private List<String> getMX(String hostName) throws NamingException {
  Hashtable<String,String> env=new Hashtable<String,String>();
  env.put("java.naming.factory.initial","com.sun.jndi.dns.DnsContextFactory");
  DirContext ictx=new InitialDirContext(env);
  Attributes attrs=ictx.getAttributes(hostName,new String[]{"MX"});
  Attribute attr=attrs.get("MX");
  List<String> mailHosts=new ArrayList<String>();
  if ((attr == null) || (attr.size() == 0)) {
    return mailHosts;
  }
  NamingEnumeration en=attr.getAll();
  while (en.hasMore()) {
    String mailhost;
    String x=(String)en.next();
    String split[]=x.split(" ");
    if (split.length == 1) {
      mailhost=split[0];
    }
 else     if (split[1].endsWith(".")) {
      mailhost=split[1].substring(0,(split[1].length() - 1));
    }
 else {
      mailhost=split[1];
    }
    mailHosts.add(mailhost);
  }
  return mailHosts;
}
 

Example 22

From project Coffee-Framework, under directory /coffeeframework-core/src/main/java/coffee/.

Source file: Cafeteria.java

  29 
vote

public static CoffeeApplicationContext getOrCreateApplicationContext(ServletContext servletContext){
  String contextPath=servletContext.getContextPath();
  CoffeeApplicationContext loader=applicationContexts.get(contextPath);
  if (loader == null) {
    try {
      loader=new CoffeeApplicationContext();
      loader.setServletContext(servletContext);
      applicationContexts.put(contextPath,loader);
    }
 catch (    NamingException e) {
      servletContext.log(e.getMessage());
    }
  }
  return loader;
}
 

Example 23

From project components, under directory /bean/src/main/java/org/switchyard/component/bean/deploy/.

Source file: BeanDeploymentMetaData.java

  29 
vote

/** 
 * Lookup the BeanDeploymentMetaData for the current deployment.
 * @return The BeanDeploymentMetaData.
 */
public static BeanDeploymentMetaData lookupBeanDeploymentMetaData(){
  try {
    BeanManager beanManager=getCDIBeanManager();
    Set<Bean<?>> beans=beanManager.getBeans(BeanDeploymentMetaData.class);
    if (beans.isEmpty()) {
      throw new SwitchYardException("Failed to lookup BeanDeploymentMetaData from BeanManager.  Must be bound into BeanManager.  Perhaps SwitchYard CDI Extensions not properly installed in container.");
    }
    if (beans.size() > 1) {
      throw new SwitchYardException("Failed to lookup BeanDeploymentMetaData from BeanManager.  Multiple beans resolved for type '" + BeanDeploymentMetaData.class.getName() + "'.");
    }
    BeanDeploymentMetaDataCDIBean bean=(BeanDeploymentMetaDataCDIBean)beans.iterator().next();
    return bean.getBeanMetaData();
  }
 catch (  NamingException e) {
    throw new SwitchYardException("Failed to lookup BeanManager.  Must be bound into java:comp as per CDI specification.",e);
  }
}
 

Example 24

From project core_1, under directory /test/src/main/java/org/switchyard/test/mixins/.

Source file: CDIMixIn.java

  29 
vote

@Override public void initialize(){
  super.initialize();
  _weld=new Weld();
  _weldContainer=_weld.initialize();
  _weldContainer.event().select(ContainerInitialized.class).fire(new ContainerInitialized());
  try {
    Context ctx=(Context)new InitialContext().lookup(BINDING_CONTEXT);
    ctx.rebind(BEAN_MANAGER_NAME,getBeanManager());
  }
 catch (  NamingException e) {
    e.printStackTrace();
    Assert.fail("Failed to bind BeanManager into '" + BINDING_CONTEXT + "'.");
  }
}
 

Example 25

From project core_4, under directory /impl/src/main/java/org/richfaces/application/configuration/.

Source file: ConfigurationServiceImpl.java

  29 
vote

private String getWebEnvironmentEntryValue(ConfigurationItem configurationItem){
  Context context=null;
  try {
    context=new InitialContext();
  }
 catch (  Throwable e) {
    if (!webEnvironmentUnavailableLogged.getAndSet(true)) {
      LOGGER.error(e.getMessage(),e);
    }
  }
  if (context != null) {
    for (    String envName : configurationItem.names()) {
      String qualifiedName;
      if (!envName.startsWith(JNDI_COMP_PREFIX)) {
        qualifiedName=JNDI_COMP_PREFIX + envName;
      }
 else {
        qualifiedName=envName;
      }
      String value=null;
      try {
        value=(String)context.lookup(qualifiedName);
      }
 catch (      NamingException e) {
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug(e.getMessage(),e);
        }
      }
      if (!Strings.isNullOrEmpty(value)) {
        return value;
      }
    }
  }
  return null;
}
 

Example 26

From project core_5, under directory /exo.core.component.database/src/main/java/org/exoplatform/services/database/jdbc/.

Source file: DBSchemaCreator.java

  29 
vote

public void createTables(String dsName,String script) throws NamingException, SQLException {
  InitialContext context=new InitialContext();
  DataSource ds=(DataSource)context.lookup(dsName);
  Connection conn=ds.getConnection();
  String sql="";
  try {
    String[] scripts=JDBCUtils.splitWithSQLDelimiter(script);
    for (    String scr : scripts) {
      String s=JDBCUtils.cleanWhitespaces(scr.trim());
      if (s.length() < 1)       continue;
      sql=s;
      if (LOG.isDebugEnabled())       LOG.debug("Execute script: \n[" + sql + "]");
      try {
        conn.setAutoCommit(false);
        conn.createStatement().executeUpdate(sql);
        conn.commit();
      }
 catch (      SQLException e) {
        conn.rollback();
        Matcher aeMatcher=pattern.matcher(e.getMessage().trim());
        if (!aeMatcher.matches())         throw e;
        if (LOG.isDebugEnabled())         LOG.debug(e.getMessage());
      }
    }
    LOG.info("DB schema of DataSource: '" + dsName + "' created succesfully. context "+ context);
  }
 catch (  SQLException e) {
    LOG.error("Could not create db schema of DataSource: '" + dsName + "'. Reason: "+ e.getMessage()+ "; "+ JDBCUtils.getFullMessage(e)+ ". Last command: "+ sql,e);
  }
 finally {
    conn.close();
  }
}
 

Example 27

From project crash, under directory /cmdline/src/main/java/org/crsh/cmdline/completers/.

Source file: JNDICompleter.java

  29 
vote

/** 
 * Search JNDI Path in Context and put the result in ValueCompletion.
 * @return ValueCompletion
 */
ValueCompletion getJndiList(String prefix){
  HashSet<String> contextNames=initJndicontextNames();
  if (prefix != null) {
    contextNames.add(prefix);
  }
  ValueCompletion completions=new ValueCompletion();
  for (  String contextName : contextNames) {
    if (!contextName.endsWith("/")) {
      contextName=contextName + "/";
    }
    try {
      InitialContext ctx=new InitialContext();
      NamingEnumeration<NameClassPair> list=ctx.list(contextName);
      while (list.hasMore()) {
        NameClassPair nc=list.next();
        if (null == nc) {
          continue;
        }
        String jndiPath=getJndiPath(contextName,nc.getName(),prefix);
        if (jndiPath != null) {
          completions.put(jndiPath,false);
        }
      }
    }
 catch (    NamingException e1) {
    }
  }
  return completions;
}
 

Example 28

From project datasalt-utils, under directory /src/contrib/java/org/apache/solr/core/.

Source file: SolrResourceLoader.java

  29 
vote

/** 
 * Finds the solrhome based on looking up the value in one of three places: <ol> <li>JNDI: via java:comp/env/solr/home</li> <li>The system property solr.solr.home</li> <li>Look in the current working directory for a solr/ directory</li>  </ol> The return value is normalized.  Normalization essentially means it ends in a trailing slash.
 * @return A normalized solrhome
 * @see #normalizeDir(String)
 */
public static String locateSolrHome(){
  String home=null;
  try {
    Context c=new InitialContext();
    home=(String)c.lookup("java:comp/env/" + project + "/home");
    log.info("Using JNDI solr.home: " + home);
  }
 catch (  NoInitialContextException e) {
    log.info("JNDI not configured for " + project + " (NoInitialContextEx)");
  }
catch (  NamingException e) {
    log.info("No /" + project + "/home in JNDI");
  }
catch (  RuntimeException ex) {
    log.warn("Odd RuntimeException while testing for JNDI: " + ex.getMessage());
  }
  if (home == null) {
    String prop=project + ".solr.home";
    home=System.getProperty(prop);
    if (home != null) {
      log.info("using system property " + prop + ": "+ home);
    }
  }
  if (home == null) {
    home=project + '/';
    log.info(project + " home defaulted to '" + home+ "' (could not find system property or JNDI)");
  }
  return normalizeDir(home);
}
 

Example 29

From project dcm4che, under directory /dcm4che-conf/dcm4che-conf-ldap/src/main/java/org/dcm4che/conf/ldap/.

Source file: ExtendedLdapDicomConfiguration.java

  29 
vote

@Override protected void loadFrom(Device device,Attributes attrs) throws NamingException, CertificateException {
  super.loadFrom(device,attrs);
  if (!hasObjectClass(attrs,"dcmDevice"))   return;
  device.setLimitOpenAssociations(intValue(attrs.get("dcmLimitOpenAssociations"),0));
  device.setTrustStoreURL(stringValue(attrs.get("dcmTrustStoreURL")));
  device.setTrustStoreType(stringValue(attrs.get("dcmTrustStoreType")));
  device.setTrustStorePin(stringValue(attrs.get("dcmTrustStorePin")));
  device.setTrustStorePinProperty(stringValue(attrs.get("dcmTrustStorePinProperty")));
  device.setKeyStoreURL(stringValue(attrs.get("dcmKeyStoreURL")));
  device.setKeyStoreType(stringValue(attrs.get("dcmKeyStoreType")));
  device.setKeyStorePin(stringValue(attrs.get("dcmKeyStorePin")));
  device.setKeyStorePinProperty(stringValue(attrs.get("dcmKeyStorePinProperty")));
  device.setKeyStoreKeyPin(stringValue(attrs.get("dcmKeyStoreKeyPin")));
  device.setKeyStoreKeyPinProperty(stringValue(attrs.get("dcmKeyStoreKeyPinProperty")));
}