public void GetNameParserAndParseStringName_Success()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "Java2NetPort.JNDI.ServiceProviders.InMemoryServiceProvider.InitialInMemoryContextFactory");

            IContext ctx = new InitialContext(env);

            INameParser np = ctx.GetNameParser("");

            Assert.IsNotNull(np);

            Assert.IsTrue(np is InMemoryHierarchicalNameParser);

            IName n = np.Parse("itemA;itemB;itemC");

            IEnumerable <string> r          = n.GetAll();
            IEnumerator <string> enumerator = r.GetEnumerator();

            enumerator.MoveNext();
            Assert.AreEqual("itemA", enumerator.Current);

            enumerator.MoveNext();
            Assert.AreEqual("itemB", enumerator.Current);

            enumerator.MoveNext();
            Assert.AreEqual("itemC", enumerator.Current);

            Assert.IsFalse(enumerator.MoveNext());
        }
示例#2
0
        /// <summary>
        /// determine the ee application name based on information obtained from JNDI.
        /// </summary>
        protected internal virtual string lookupEeApplicationName()
        {
            try
            {
                InitialContext initialContext = new InitialContext();

                string appName    = (string)initialContext.lookup(JAVA_APP_APP_NAME_PATH);
                string moduleName = (string)initialContext.lookup(MODULE_NAME_PATH);

                // make sure that if an EAR carries multiple PAs, they are correctly
                // identified by appName + moduleName
                if (!string.ReferenceEquals(moduleName, null) && !moduleName.Equals(appName))
                {
                    return(appName + "/" + moduleName);
                }
                else
                {
                    return(appName);
                }
            }
            catch (NamingException e)
            {
                throw LOG.ejbPaCannotAutodetectName(e);
            }
        }
        public void RebindByName_Ok()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "Java2NetPort.JNDI.ServiceProviders.InMemoryServiceProvider.InitialInMemoryContextFactory");

            IContext ctx = new InitialContext(env);

            IName name = ctx.GetNameParser("").Parse("stringItem");

            ctx.Bind(name, "stringItemValue");
            object returnedObj = ctx.Lookup("stringItem");

            Assert.IsNotNull(returnedObj);
            Assert.IsTrue(returnedObj is string);
            Assert.IsTrue(returnedObj.ToString() == "stringItemValue");



            ctx.Rebind(name, "stringItemValueChanged");
            returnedObj = ctx.Lookup(name);

            Assert.IsNotNull(returnedObj);
            Assert.IsTrue(returnedObj is string);
            Assert.AreEqual("stringItemValueChanged", returnedObj.ToString());
        }
示例#4
0
 private void unbind()
 {
     initialContext = null;
     try
     {
         initialContext = new InitialContext();
         Util.unbind(initialContext, this.sessionFactoryName);
         Util.unbind(initialContext, "hibernate/Configuration");
     }
     catch (NamingException namingException)
     {
         throw new HibernateException("Unable to unbind SessionFactory from JNDI", namingException);
     }
     finally
     {
         if (initialContext != null)
         {
             try
             {
                 initialContext.close();
             }
             catch (Exception)
             {
             }
         }
     }
 }
        public void remove_Success()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "Java2NetPort.JNDI.ServiceProviders.InMemoryServiceProvider.InitialInMemoryContextFactory");

            IContext ctx = new InitialContext(env);

            INameParser np = ctx.GetNameParser("");

            IName n = np.Parse("item1;item2;item3");

            string rez = n.Remove(1);

            Assert.AreEqual("item2", rez);

            IEnumerable <string> r          = n.GetAll();
            IEnumerator <string> enumerator = r.GetEnumerator();

            enumerator.MoveNext();
            Assert.AreEqual("item1", enumerator.Current);

            enumerator.MoveNext();
            Assert.AreEqual("item3", enumerator.Current);


            Assert.IsFalse(enumerator.MoveNext());
        }
示例#6
0
        private void initLdapConfig()
        {
            InitialContext initialContext = new InitialContext();
            DataSource     dataSource     = (DataSource)initialContext.lookup(this.dsJndiName);

            connection = null;
            PreparedStatement preparedStatement = null;

            resultSet = null;
            try
            {
                connection        = dataSource.Connection;
                preparedStatement = connection.prepareStatement(this.ldapCongigQuery);
                resultSet         = preparedStatement.executeQuery();
                if (resultSet.next())
                {
                    this.ldapEnabled  = resultSet.getBoolean(1);
                    this.ldapHostname = resultSet.getString(2);
                    this.ldapPort     = "" + resultSet.getInt(3);
                    this.ldapBaseDN   = resultSet.getString(4);
                    this.ldapBindDN   = resultSet.getString(5);
                    this.ldapPassword = decodeLdapPsw(resultSet.getString(6));
                    this.ldapSSL      = resultSet.getBoolean(7);
                }
                else
                {
                    this.ldapEnabled  = false;
                    this.ldapHostname = null;
                    this.ldapPort     = null;
                    this.ldapBaseDN   = null;
                    this.ldapBindDN   = null;
                    this.ldapPassword = null;
                    this.ldapSSL      = false;
                }
            }
            catch (Exception exception)
            {
                if (resultSet != null)
                {
                    resultSet.close();
                }
                if (connection != null)
                {
                    connection.close();
                }
                throw exception;
            }
            finally
            {
                if (resultSet != null)
                {
                    resultSet.close();
                }
                if (connection != null)
                {
                    connection.close();
                }
            }
        }
        public void CreateInMemoryServiceProvider_Ok()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "Java2NetPort.JNDI.ServiceProviders.InMemoryServiceProvider.InitialInMemoryContextFactory");

            IContext ctx = new InitialContext(env);
        }
        public void CreateNonExistingServiceProvider()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "notExisting");

            IContext ctx = new InitialContext(env);
        }
示例#9
0
        private string getAuthType(string paramString)
        {
            PreparedStatement preparedStatement = null;
            ResultSet         resultSet         = null;
            Connection        connection        = null;
            string            str = null;

            try
            {
                InitialContext initialContext = new InitialContext();
                DataSource     dataSource     = (DataSource)initialContext.lookup(this.dsJndiName);
                connection        = dataSource.Connection;
                preparedStatement = connection.prepareStatement("SELECT AUTHTYPE FROM PRINCIPALS WHERE ENBL = 1 AND PRINCIPALID = ? COLLATE SQL_Latin1_General_CP1_CS_AS");
                preparedStatement.setString(1, paramString);
                resultSet = preparedStatement.executeQuery();
                if (resultSet.next())
                {
                    str = resultSet.getString(1);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
                Console.Write(exception.StackTrace);
            }
            if (resultSet != null)
            {
                try
                {
                    resultSet.close();
                }
                catch (SQLException)
                {
                }
            }
            if (preparedStatement != null)
            {
                try
                {
                    preparedStatement.close();
                }
                catch (SQLException)
                {
                }
            }
            if (connection != null)
            {
                try
                {
                    connection.close();
                }
                catch (SQLException)
                {
                }
            }
            return(str);
        }
        public void RenameNameThatDoesNotExists_NameNotFoundException()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "Java2NetPort.JNDI.ServiceProviders.InMemoryServiceProvider.InitialInMemoryContextFactory");

            IContext ctx = new InitialContext(env);

            ctx.Rename("notExistingName", "notExistingName");
        }
示例#11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void lookupBpmPlatformXml() throws javax.naming.NamingException, java.net.MalformedURLException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        public virtual void lookupBpmPlatformXml()
        {
            Context context = new InitialContext();

            context.bind("java:comp/env/" + BPM_PLATFORM_XML_LOCATION, BPM_PLATFORM_XML_FILE_ABSOLUTE_LOCATION);

            URL url = (new TomcatParseBpmPlatformXmlStep()).lookupBpmPlatformXml();

            assertEquals((new File(BPM_PLATFORM_XML_FILE_ABSOLUTE_LOCATION)).toURI().toURL(), url);
        }
        public void LookupNonExistingItemByStringName_ThrowNamingException()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "Java2NetPort.JNDI.ServiceProviders.InMemoryServiceProvider.InitialInMemoryContextFactory");

            IContext ctx = new InitialContext(env);

            ctx.Lookup("itemNotExisting");
        }
示例#13
0
        // Start is called before the first frame update
        void Start()
        {
            var context = new InitialContext();

            var serviceLocator = new ServiceLocator(context);

            var bluetoothService = serviceLocator.GetService("bluetooth");

            bluetoothService.Execute();
        }
        public void BindWithEmptyNameString_InvalidNameException()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "Java2NetPort.JNDI.ServiceProviders.InMemoryServiceProvider.InitialInMemoryContextFactory");

            IContext ctx = new InitialContext(env);

            ctx.Bind("", "stringItemValue");
        }
示例#15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testProcessEngineServiceBinding()
        public virtual void testProcessEngineServiceBinding()
        {
            try
            {
                InitialContext.doLookup(testConstants.EngineService);
            }
            catch (NamingException e)
            {
                Assert.fail("Failed to lookup ProcessEngineService '" + TestConstants.PROCESS_ENGINE_SERVICE_JNDI_NAME + "'. Reason: " + e);
            }
        }
示例#16
0
 protected internal virtual WorkManager lookupWorkMananger()
 {
     try
     {
         InitialContext initialContext = new InitialContext();
         return((WorkManager)initialContext.lookup(commonJWorkManagerName));
     }
     catch (Exception e)
     {
         throw new Exception("Error while starting JobExecutor: could not look up CommonJ WorkManager in Jndi: " + e.Message, e);
     }
 }
示例#17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testDefaultProcessEngineBindingCreated()
        public virtual void testDefaultProcessEngineBindingCreated()
        {
            try
            {
                ProcessEngine processEngine = InitialContext.doLookup("java:global/camunda-bpm-platform/process-engine/default");
                Assert.assertNotNull("Process engine must not be null", processEngine);
            }
            catch (Exception)
            {
                Assert.fail("Process Engine not bound in JNDI.");
            }
        }
示例#18
0
 /// <summary>
 /// lookup a proxy object representing the invoked business view of this component.
 /// </summary>
 protected internal virtual ProcessApplicationInterface lookupSelfReference()
 {
     try
     {
         InitialContext ic         = new InitialContext();
         SessionContext sctxLookup = (SessionContext)ic.lookup(EJB_CONTEXT_PATH);
         return(sctxLookup.getBusinessObject(BusinessInterface));
     }
     catch (NamingException e)
     {
         throw LOG.ejbPaCannotLookupSelfReference(e);
     }
 }
        public void RenameToAlreadyExistingName_NameAlreadyBoundException()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "Java2NetPort.JNDI.ServiceProviders.InMemoryServiceProvider.InitialInMemoryContextFactory");

            IContext ctx = new InitialContext(env);

            ctx.Bind("stringItem1", "stringItem1Value");
            ctx.Bind("stringItem2", "stringItem2Value");

            ctx.Rename("stringItem1", "stringItem2");
        }
        public void LookupEmptyStringName_ShouldReturnContext()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "Java2NetPort.JNDI.ServiceProviders.InMemoryServiceProvider.InitialInMemoryContextFactory");

            IContext ctx = new InitialContext(env);

            object result = ctx.Lookup(string.Empty);

            Assert.IsTrue(result is IContext);
            Assert.IsTrue(result is InMemoryNamingServiceProvider);
        }
示例#21
0
        /// <summary>   gets connection to the datasource specified through the configuration
        /// parameters.
        /// *
        /// </summary>
        /// <returns>connection
        ///
        /// </returns>
        private System.Data.OleDb.OleDbConnection openDbConnection()
        {
            if (ctx == null)
            {
                ctx = new InitialContext();
            }

            if (dataSource == null)
            {
                dataSource = (DataSource)ctx.lookup(dataSourceName);
            }

            return(dataSource.Connection);
        }
        public void UnbindByString_ThrowNameNotFoundExceptionOnLookup()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "Java2NetPort.JNDI.ServiceProviders.InMemoryServiceProvider.InitialInMemoryContextFactory");

            IContext ctx = new InitialContext(env);

            ctx.Bind("stringItem", "stringItemValue");

            ctx.Unbind("stringItem");

            object returnedObj = ctx.Lookup("stringItem");
        }
        public static IService GetService(string jndiName)
        {
            var service = cache.GetService(jndiName);

            if (service != null)
            {
                return(service);
            }
            var context  = new InitialContext();
            var service1 = context.Lookup(jndiName) as IService;

            cache.AddService(service1);
            return(service1);
        }
        public void GetNameParserFromContext_Ok()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "Java2NetPort.JNDI.ServiceProviders.InMemoryServiceProvider.InitialInMemoryContextFactory");

            IContext ctx = new InitialContext(env);

            INameParser np = ctx.GetNameParser(string.Empty);

            Assert.IsNotNull(np);

            Assert.IsTrue(np is InMemoryHierarchicalNameParser);
        }
示例#25
0
        public static IService getService(String jndiName)
        {
            IService service = cache.getService(jndiName);

            if (service != null)
            {
                return(service);
            }

            InitialContext context  = new InitialContext();
            IService       service1 = (IService)context.lookup(jndiName);

            cache.addService(service1);
            return(service1);
        }
示例#26
0
        internal StatechartDefinition <ECMAScriptContext> AsStatechartDefinition()
        {
            var initialContext = InitialContext.ValueOr(new ECMAScriptContext(new Engine()));
            var rootStateNode  = new TestCompoundStatenodeDefinition(
                Name.ValueOr("root"),
                null,
                null,
                null,
                null,
                Statenodes,
                new InitialCompoundTransitionDefinition(new ChildTarget(InitialStateNodeName.ValueOr(Statenodes.First().Name))),
                Option.None <DoneTransitionDefinition>());

            return(new StatechartDefinition <ECMAScriptContext>(initialContext, rootStateNode));
        }
        public void MultipleCreationOfInitialContext_ShouldReturnTheSameContext()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "Java2NetPort.JNDI.ServiceProviders.InMemoryServiceProvider.InitialInMemoryContextFactory");

            IContext ctx = new InitialContext(env);

            ctx.Bind("item1", "item1Value");

            IContext ctx2   = new InitialContext(env);
            object   result = ctx2.Lookup("item1");

            Assert.AreSame("item1Value", result.ToString());
        }
        public static IService GetService(string jndiName)
        {
            IService service = _cache.GetService(jndiName);

            if (service != null)
            {
                return(service);
            }

            InitialContext context  = new InitialContext();
            IService       service1 = (IService)context.LookUp(jndiName);

            _cache.AddService(service1);
            return(service1);
        }
        public void LookupExistingItemByStringName_Ok()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "Java2NetPort.JNDI.ServiceProviders.InMemoryServiceProvider.InitialInMemoryContextFactory");

            IContext ctx = new InitialContext(env);

            ctx.Bind("stringItem", "stringItemValue");

            object returnedObj = ctx.Lookup("stringItem");

            Assert.IsNotNull(returnedObj);
            Assert.IsTrue(returnedObj is string);
            Assert.AreEqual("stringItemValue", returnedObj.ToString());
        }
  /// <p>
  /// Looks up a {@link DataSource} by name from JNDI. "java:comp/env/" is prepended to the argument before
  /// looking up the name in JNDI.
  /// </p>
  /// 
  /// @param dataSourceName
  ///          JNDI name where a {@link DataSource} is bound (e.g. "jdbc/taste")
  /// @return {@link DataSource} under that JNDI name
  /// @throws TasteException
  ///           if a JNDI error occurs
 public static DataSource lookupDataSource(String dataSourceName) {
   Context context = null;
   try {
     context = new InitialContext();
     return (DataSource) context.lookup("java:comp/env/" + dataSourceName);
   } catch (NamingException ne) {
     throw new TasteException(ne);
   } finally {
     if (context != null) {
       try {
         context.close();
       } catch (NamingException ne) {
         log.warn("Error while closing Context; continuing...", ne);
       }
     }
   }
 }
        public void RenameByString_Ok()
        {
            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add(Context.INITIAL_CONTEXT_FACTORY, "Java2NetPort.JNDI.ServiceProviders.InMemoryServiceProvider.InitialInMemoryContextFactory");

            IContext ctx = new InitialContext(env);

            ctx.Bind("stringItem1", "stringItem1Value");

            ctx.Rename("stringItem1", "stringItem2");

            object obj = ctx.Lookup("stringItem2");

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj is string);
            Assert.IsTrue(obj.ToString() == "stringItem1Value");
        }
			internal DataSource GetDataSource(string dataSourceName,string namingProviderUrl,string namingFactoryInitial) {
				Hashtable cache = Cache;

				DataSource ds = cache[dataSourceName] as DataSource;

				if (ds != null) {
					return ds;
				}

				Context ctx = null;
				
				java.util.Properties properties = new java.util.Properties();

				if ((namingProviderUrl != null) && (namingProviderUrl.Length > 0)) {
					properties.put("java.naming.provider.url",namingProviderUrl);
				}
				
				if ((namingFactoryInitial != null) && (namingFactoryInitial.Length > 0)) {
					properties.put("java.naming.factory.initial",namingFactoryInitial);
				}

				ctx = new InitialContext(properties);
 
				try {
					ds = (DataSource)ctx.lookup(dataSourceName);
				}
				catch(javax.naming.NameNotFoundException e) {
					// possible that is a Tomcat bug,
					// so try to lookup for jndi datasource with "java:comp/env/" appended
					ds = (DataSource)ctx.lookup("java:comp/env/" + dataSourceName);
				}

				cache[dataSourceName] = ds;
				return ds;
			}
	/// <summary>   gets connection to the datasource specified through the configuration
	/// parameters.
	/// *
	/// </summary>
	/// <returns>connection
	///
	/// </returns>
	private System.Data.OleDb.OleDbConnection openDbConnection() {
	    if (ctx == null) {
		ctx = new InitialContext();
	    }

	    if (dataSource == null) {
		dataSource = (DataSource) ctx.lookup(dataSourceName);
	    }

	    return dataSource.Connection;
	}