⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testjndibulkops.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.ca.commons.jndi;


import java.util.*;
import java.util.logging.*;

import javax.naming.NamingException;

import com.ca.commons.cbutil.*;
import com.ca.commons.naming.DXEntry;



/**
*	Opens and reads the property file @see FILENAME.  Creates a BulkJndiTest
*	object and passes args[] and the property file to it.
*	Determines the options supplied by the user and sets these as global variables.
*	Reads the property file (BulkJndiTest.txt) to determine:
*	<p>
*			The computer name.
*			The port number.
*			The number of Threads to be used.
*			The number of times each Thread should run the jnditests on the LDIF data.
*			The names of the LDIF files to be used by each Thread.
*	</p>
*	Creates a new Test object for each Thread then starts the Thread.
*	@author Trudi.
*/

public class TestJNDIBulkOps
{
   /**
	*	The name of the property file that lists the LDIF files and which Threads they pertain to.
	*/
	
	final static String FILENAME = "BulkJndiTest.txt";
		
    private final static Logger log = Logger.getLogger(TestJNDIBulkOps.class.getName());

		
   /**
    *	Opens and reads the property file @see FILENAME.  Creates a BulkJndiTest
	*	object and passes args[] and the property file to it.
	*	@param args any options supplied by the user.  Can be
	*	<p>
	*       -d            debug (verbose) mode.										<br>
	*       -e            exit on error, returning -1.								<br>
	*       -h [subject]  this help message [full|changetype].						<br>
	*       -p password   an option password.										<br>
	*       -r referral   the jndi referral type [follow|ignore|throw].				<br>
	*       -t            set BER tracing on.										<br>
	*       -u userdn     an optional user dn.										<br>
	*       -v            set ldap version (default 3).								<br>
	*       -x            print stack trace. 										<br>	
	*	</p>
	*/
			
    public static void main (String args[]) 
    {
        log.addHandler(new ConsoleHandler());
        log.setLevel(Level.FINE);

		Properties properties = new Properties();

        properties = CBUtility.readPropertyFile(FILENAME);
        if (properties.size()==0) { log.warning("Can't find: " + FILENAME); return;}
	    	
		new TestJNDIBulkOps(args, properties);
    }
	
	
	
   /**
    *	Determines the options supplied by the user and sets these as global variables.
	*	Reads the property file (BulkJndiTest.txt) to determine:
	*	<p>
	*			The number of Threads to be used.
	*			The number of times each Thread should run the jnditests on the LDIF data.
	*			The names of the LDIF files to be used by each Thread.
	*	</p>
	*	Creates a new Test object for each Thread then starts the Thread.
	*	@param args any options supplied by the user.  Can be
	*	<p>
	*       -d            debug (verbose) mode.										<br>
	*       -e            exit on error, returning -1.								<br>
	*       -h [subject]  this help message [full|changetype].						<br>
	*       -p password   an option password.										<br>
	*       -r referral   the jndi referral type [follow|ignore|throw].				<br>
	*       -t            set BER tracing on.										<br>
	*       -u userdn     an optional user dn.										<br>
	*       -v            set ldap version (default 3).								<br>
	*       -x            print stack trace. 										<br>	
	*	</p>	
	*	@param properties the property file (BulkJndiTest.txt).
	*/
		
	public TestJNDIBulkOps(String args[], Properties properties)
	{
	    String url = null;
	    String user = null;
	    String pwd  = null;
	    String version = "3";
	    String referral = "follow";
	    boolean useSSL = false;
	    boolean tracing = false;
	    boolean debugFlag = false;
	    boolean terminateFlag = false;	
		boolean printstackFlag = false;
		
	    try
	    {	 
			int i=0;
			
	        while (i<args.length)
	        {
	            String arg = (args[i].charAt(0) != '-')?args[i]:args[i].substring(1);
	            switch(arg.charAt(0))
	            {
	                case '?':
	                case 'H':
	                case 'h': if (args.length>i+1) 
	                                System.out.println(args[i+1]);
	                          else
	                                return;                           
	                case 'D':
	                case 'd': debugFlag = true; break;	                
	                case 'E':
	                case 'e': terminateFlag = true; break;	                
	                case 'P':
	                case 'p': pwd = args[++i]; break;	                
	                case 'R':
	                case 'r': referral = args[++i]; break;	                
	                case 'S':
	                case 's': useSSL = true; break;	                
	                case 'T':
	                case 't': tracing = true; break;	                
	                case 'U':
	                case 'u': user = args[++i]; break;	                
	                case 'V':
	                case 'v': version = args[++i]; break;
	            	case 'X':
	            	case 'x': printstackFlag = true; break;
	                
	                default : System.out.println("\n\nInvalid command line argument: -" + arg);
	                                return; 
	            }
	            i++;               
	        }
	    }
	    catch (Exception e)
	    {
	        System.out.println("Error reading command line arguments.");
	        System.exit(-1);
	    }

		
		int numberOfThreads = -1;	//TE: the number of threads that the user wants to use.
		int numberOfIterations = -1;	//TE: the number of times the ldif data is tested per thread.
		
		try
		{	
			//TE: find out how many threads the user wants to use...
			numberOfThreads = Integer.parseInt(properties.getProperty("NumberOfThreads").toString());
			
			//TE: find out how many iterations per thread the user wants...
			numberOfIterations = Integer.parseInt(properties.getProperty("NumberOfIterations").toString());			
			
			//TE: sanity check...
			if(numberOfThreads <=0 || numberOfThreads > 20)
			{
				System.out.println("Problem accessing the number of threads you wish to run." +
								   "  Check the property file 'BulkJndiTest.txt' and make sure the" +
								   " 'NumberOfThreads' entry contains a valid integer between 1 and 10.");
				System.exit(-1);
			}			
		}
		catch(NumberFormatException  e)
		{
			System.out.println("Problem accessing the number of threads you wish to run." +
							   "  Check the property file 'BulkJndiTest.txt' and make sure the" +
							   "  'NumberOfThreads' entry contains a valid integer between 1 and 10." +
							   "  Also check that the 'NumberOfIterations' contains a valid integer.");
			System.exit(-1);
		}
		
		url = properties.getProperty("ComputerName").toString()+":"+properties.getProperty("Port").toString();		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -