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

📄 mainframe.java

📁 webservice压力测试模拟器,可以并发的同时测试多台服务器的性能.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
					JPanel p = new JPanel();
					p.setLayout(new FlowLayout(FlowLayout.LEFT));
					p.setBorder(new EtchedBorder());
					p.add(new JLabel("Param " + (i + 1) + ":"));
					JTextField tf = new JTextField("", 10);
					tf.setEditable(false);
					tf.setText(para.getQName().getLocalPart());
					p.add(tf);
					p.add(new JLabel("Type:"));
					tf = new JTextField("", 10);
					tf.setEditable(false);

					String wsdlType = para.getType().getQName().getLocalPart();
					String mode = invoker[0].getParameterModeString(para);
					tf.setText(mode + " " + wsdlType);
					p.add(tf);
					if (para.getMode() != Parameter.OUT) {
						// for IN and INOUT parameters
						p.add(new JLabel("Value:"));
						txtParameterValues[i] = new JTextField("", 10);
						p.add(txtParameterValues[i]);
						JButton btnChoose = new JButton("...");
						btnChoose
								.addActionListener(new MainFrame_btnChoose_actionAdapter(
										this, i));
						p.add(btnChoose);
					} else {
						txtParameterValues[i] = null;
					}
					paneCenter.add(p);
				}
			}
			validate();
			repaint();
		} catch (Exception ex) {
			JOptionPane.showMessageDialog(this, ex.getClass().getName() + ": "
					+ ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
		}
	}

	void btnTest_actionPerformed(ActionEvent e) {
		// Begin invoking or testing
		if (invoker == null || serviceName == null || portName == null
				|| operationName == null || parameters == null) {
			JOptionPane.showMessageDialog(this,
					"Please specify location/service/operation and "
							+ "assign values to all the parameters "
							+ "before invoking/testing.", "WARNING",
					JOptionPane.WARNING_MESSAGE);
			return;
		}
		if (chbModel.isSelected()) {// 用户选择的是直接传送内容
			MainFrame_btnTest_Thread runnable = new MainFrame_btnTest_Thread();
			Thread thread = new Thread(runnable);
			thread.start();
		} else {// 用户选择的是单个文件或者是整个目录
			int threads = 0;
            try
            {
                threads = Integer.parseInt(txtLocation.getText());
            }
            catch(NumberFormatException ex1)
            {
                threads = 0;
            }
            if(threads <= 0)
            {
                JOptionPane.showMessageDialog(null, "Invoke threads must be larger than zero.", "WARNING", 2);
                return;
            }
            runFD(threads);
		}
	}

	class MainFrame_btnTest_Thread implements Runnable {
		public void run() {
			// 判断调用的次数是否符合逻辑,必须大于0.
			int times = 0;
			try {
				times = Integer.parseInt(txtTimes.getText());
			} catch (NumberFormatException ex1) {
				times = 0;
			}
			if (times <= 0) {
				JOptionPane.showMessageDialog(null,
						"Invoke times must be larger than zero.", "WARNING",
						JOptionPane.WARNING_MESSAGE);
				return;
			}

			// getParameterValues(times);
			Vector parameterValues = new Vector();
			Vector v = parameters.list;
			int paraNumbers = v.size();

			// if (chbModel.isSelected()) {// 用户选择的是直接传送内容
			if (txtParameterValues != null)// 当此服务有参数时
				for (int i = 0; i < paraNumbers; i++) {
					if (txtParameterValues[i] != null) {
						String value = txtParameterValues[i].getText();
						if (value == null
								|| (value = value.trim()).length() == 0) {
							JOptionPane.showMessageDialog(null,
									"Please assign a value to paramter "
											+ (i + 1), "WARNING",
									JOptionPane.WARNING_MESSAGE);
							return;
						}
						parameterValues.addElement(value);
					}
				}
			try {
				Map outputs = null;
				long begin = Calendar.getInstance().getTime().getTime();
				for (int i = 0; i < times; i++) {
					outputs = invoker[0].invoke(serviceName, portName,
							operationName, parameterValues);
				}
				long end = Calendar.getInstance().getTime().getTime();
				long span = end - begin;
				boolean isSave = false;
				if (chb.isSelected()) {
					isSave = true;
				}
				ResultDialog dlg = new ResultDialog(null, "RESULT", outputs,

				span, times, isSave);
				dlg.setVisible(true);
			}// end try
			catch (Exception ex) {
				JOptionPane.showMessageDialog(null, ex.getClass().getName()
						+ ": " + ex.getMessage(), "ERROR",
						JOptionPane.ERROR_MESSAGE);
			}
		}// end run
	}// end class MainFrame_btnTest_Thread

	void runFD(int threads) {
		for (int i = 0; i < threads; i++) {
			GetFDContentThread getFDContentThread = new GetFDContentThread(
					threads);
			Thread thread = new Thread(getFDContentThread);
			thread.start();
		}
	}

	class GetFDContentThread implements Runnable {
		private int threads;

		public GetFDContentThread(int threads) {
			this.threads = threads;
		}

		public void run() {
			Iterator it = fileListContent.iterator();
			synchronized (fileListContent) {
				while (it.hasNext()) {
					fileNum++;
					Vector parameterValues = new Vector();
					parameterValues.addElement(it.next());
					try {
						Map outputs = null;
						if (chbAll.isSelected()) {
							for (int i = 0; i < invoker.length; i++) {
								outputs = invoker[i].invoke(serviceName,
										portName, operationName,
										parameterValues);
								boolean isSave = false;
								if (chb.isSelected()) {
									isSave = true;
								}
								ResultDialog dlg = new ResultDialog(null, "RESULT",
										outputs, 0, threads, isSave);
							}
						} else {
							int i = fileNum % invoker.length;
							outputs = invoker[i].invoke(serviceName, portName,
									operationName, parameterValues);
							boolean isSave = false;
							if (chb.isSelected())
								isSave = true;
							ResultDialog resultdialog1 = new ResultDialog(null,
									"RESULT", outputs, 0L, threads, isSave);
						}
						it.remove();
						// dlg.setVisible(true);
					}// end try
					catch (Exception ex) {
						JOptionPane.showMessageDialog(null, ex.getClass()
								.getName()
								+ ": " + ex.getMessage(), "ERROR",
								JOptionPane.ERROR_MESSAGE);
					}
				}
			}
		}
	}

	void btnChoose_actionPerformed(ActionEvent e, int i) {
		try {
			JFileChooser fc = new JFileChooser("...");
			fc.setFileSelectionMode(fc.FILES_AND_DIRECTORIES);
			fc.showOpenDialog(MainFrame.this);
			txtParameterValues[i].setText(fc.getSelectedFile().getPath());
			File file = new File(fc.getSelectedFile().getPath());
			if (file.isFile()) {
				fileListContent = new Vector();
				getFileContent(fc.getSelectedFile().getPath(), true,
						fileListContent);// 当选择的是单个文件
			} else {
				getDirectoryContent(fc.getSelectedFile().getPath());// 当选择的是一个目录
			}
		} catch (Exception ex) {
			JOptionPane.showMessageDialog(this, ex.getClass().getName() + ": "
					+ ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
		}
	}

	// by shanben 2007/04/18 读取指定的文件的内容
	// 参数的作用是用来标识是对一个文件的读取,还是对一个目录下的所有文件的读取。
	// 在这里只实现了只有一个参数的情况。如果有多个参数的话,此处还需要修改。
	void getFileContent(String filePath, boolean siglnFile,
			Collection fileListContent) {
		fileContent = "";
		//FileReader reader = null;
		BufferedReader br = null;
		FileInputStream reader = null;
		InputStreamReader isr = null;
		try {
			//reader = new FileReader(filePath);
			//br = new BufferedReader(reader);
			br = new BufferedReader(
					new InputStreamReader(
							new FileInputStream(filePath),"UTF-8"));
			String str = "";
			int intLength;
			while ((str = br.readLine()) != null) {
				if (siglnFile) {
					fileContent += str;
				} else {
					fileContent += str;
				}
			}
			fileListContent.add(fileContent);
			// 测试用
			 System.out.println("========" + fileContent + "========");
		} catch (IOException ex) {
			ex.printStackTrace();
		} finally {
			try {
				//reader.close();
				//isr.close();
				br.close();
			} catch (IOException ex1) {
				ex1.printStackTrace();
			}
		}
	}

	// by shanben 2007/04/18 读取一个目录下所有文件路径
	void getDirectoryContent(String DirectoryPath) {
		fileListContent = new Vector();
		File file = new File(DirectoryPath);
		fileList = file.listFiles();
		Collection fl = new ArrayList();
		for (int i = 0; i < fileList.length; i++) {
			if (fileList[i].isFile()) {
				fl.add(fileList[i]);
				// 测试用
				// System.out.println(fileList[i]);
			}
		}
		Iterator it = fl.iterator();
		while (it.hasNext()) {
			String content = it.next().toString();
			// System.out.println(content);
			getFileContent(content, false, fileListContent);
		}
		// 测试用的
		/*
		 * Iterator it1 = fileListContent.iterator(); while (it1.hasNext()) {
		 * System.out.println(it1.next()); }
		 */
	}

}

class MainFrame_btnExit_actionAdapter implements java.awt.event.ActionListener {
	MainFrame adaptee;

	MainFrame_btnExit_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.btnExit_actionPerformed(e);
	}
}

class MainFrame_btnAbout_actionAdapter implements java.awt.event.ActionListener {
	MainFrame adaptee;

	MainFrame_btnAbout_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.btnAbout_actionPerformed(e);
	}
}

class MainFrame_btnFind_actionAdapter implements java.awt.event.ActionListener {
	MainFrame adaptee;

	MainFrame_btnFind_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.btnFind_actionPerformed(e);
	}
}

class MainFrame_comboService_actionAdapter implements
		java.awt.event.ActionListener {
	MainFrame adaptee;

	MainFrame_comboService_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.comboService_actionPerformed(e);
	}
}

class MainFrame_comboOperation_actionAdapter implements
		java.awt.event.ActionListener {
	MainFrame adaptee;

	MainFrame_comboOperation_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.comboOperation_actionPerformed(e);
	}
}

class MainFrame_btnTest_actionAdapter implements java.awt.event.ActionListener {
	MainFrame adaptee;

	MainFrame_btnTest_actionAdapter(MainFrame adaptee) {
		this.adaptee = adaptee;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.btnTest_actionPerformed(e);
	}
}

class MainFrame_btnChoose_actionAdapter implements
		java.awt.event.ActionListener {
	MainFrame adaptee;

	private int i;

	MainFrame_btnChoose_actionAdapter(MainFrame adaptee, int i) {
		this.adaptee = adaptee;
		this.i = i;
	}

	public void actionPerformed(ActionEvent e) {
		adaptee.btnChoose_actionPerformed(e, i);
	}
}

⌨️ 快捷键说明

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