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

📄 mainframe.java

📁 webservice压力测试模拟器,可以并发的同时测试多台服务器的性能.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.gpdi.www.ws.client;

import java.awt.*;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
import javax.swing.event.*;

import org.apache.axis.wsdl.symbolTable.*;

public class MainFrame extends JFrame {
	DynamicInvoker[] invoker = null;

	String location = null;

	String serviceName = null;

	String portName = null;

	String operationName = null;

	Parameters parameters = null;

	JTextField[] txtParameterValues = null;

	JPanel contentPane;

	Border border1;

	BorderLayout borderLayout1 = new BorderLayout();

	JPanel paneNorth = new JPanel();

	JPanel paneSouth = new JPanel();

	JButton btnExit = new JButton();

	JButton btnAbout = new JButton();

	JButton btnTest = new JButton();

	JLabel jLabel1 = new JLabel();

	JLabel jLabel2 = new JLabel();

	JLabel jLabel3 = new JLabel();

	JTextField txtLocation = new JTextField();

	JButton btnFind = new JButton();

	JScrollPane jScrollPane1 = new JScrollPane();

	Border border2;

	JLabel jLabel4 = new JLabel();

	JComboBox comboService = new JComboBox();

	JLabel jLabel5 = new JLabel();

	JLabel jLabel6 = new JLabel();

	JComboBox comboOperation = new JComboBox();

	JLabel jLabel7 = new JLabel();

	GridBagLayout gridBagLayout1 = new GridBagLayout();

	GridLayout gridLayout1 = new GridLayout();

	Border border3;

	JPanel paneCenter = new JPanel();

	GridLayout gridLayoutCenter = new GridLayout();

	Border border4;

	JTextField txtTimes = new JTextField();

	// 测试模式--选中是传送的是文件内容。不选则说明传送的是文件或一个目录下的所有文件。
	JCheckBox chbModel = new JCheckBox("by values");

	// 选中说明每个文件都需要传送室每台服务器;反之则说明一个文件只需要传送到一个服务器上即可。
	JCheckBox chbAll = new JCheckBox("All Files");

	// 是否保存返回的文件标记
	JCheckBox chb = new JCheckBox("save");

	// 当用户选择的是单个文件时的内容
	String fileContent = "";

	// 当用户选择的是一个目录时里面的所有文件集合
	File[] fileList = null;

	Collection fileListContent = null;

	// 用来标识当前发送的是第几个文件.
	private static int fileNum;

	// Construct the frame
	public MainFrame() {
		enableEvents(AWTEvent.WINDOW_EVENT_MASK);
		try {
			jbInit();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// Component initialization
	private void jbInit() throws Exception {
		contentPane = (JPanel) this.getContentPane();
		border1 = BorderFactory.createEmptyBorder(10, 10, 10, 10);
		border2 = BorderFactory.createEmptyBorder(5, 5, 5, 5);
		border3 = BorderFactory.createEmptyBorder(0, 3, 0, 5);
		border4 = BorderFactory.createEmptyBorder(5, 5, 5, 5);
		contentPane.setBorder(border2);
		contentPane.setMinimumSize(new Dimension(800, 600));
		contentPane.setPreferredSize(new Dimension(800, 600));
		contentPane.setLayout(borderLayout1);
		this.setContentPane(contentPane);
		this.setResizable(false);
		this.setSize(new Dimension(800, 600));
		this.setState(Frame.NORMAL);
		this.setTitle("SOAPClient");
		paneNorth.setLayout(gridBagLayout1);
		paneSouth.setLayout(gridLayout1);
		btnExit.setText("Exit");
		btnExit.addActionListener(new MainFrame_btnExit_actionAdapter(this));
		btnAbout.setText("About");
		btnAbout.addActionListener(new MainFrame_btnAbout_actionAdapter(this));
		btnTest.setText("Invoke");
		btnTest.addActionListener(new MainFrame_btnTest_actionAdapter(this));
		jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabel1.setText("Invoke Times:");
		jLabel2.setRequestFocusEnabled(true);
		jLabel2.setToolTipText("");
		jLabel2.setText("");
		jLabel3.setToolTipText("");
		jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel3.setText("Concurrent Threads:");
		txtLocation.setMinimumSize(new Dimension(350, 22));
		txtLocation.setPreferredSize(new Dimension(350, 22));
		txtLocation.setText("1");
		btnFind.setText("Set Servers");
		btnFind.addActionListener(new MainFrame_btnFind_actionAdapter(this));
		borderLayout1.setHgap(5);
		borderLayout1.setVgap(5);
		jLabel4.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel4.setText("Service:");
		comboService.setMinimumSize(new Dimension(350, 22));
		comboService.setPreferredSize(new Dimension(350, 22));
		comboService.setEditable(false);
		comboService
				.addActionListener(new MainFrame_comboService_actionAdapter(
						this));
		jLabel6.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel6.setText("Operation:");
		comboOperation.setMinimumSize(new Dimension(350, 22));
		comboOperation.setPreferredSize(new Dimension(350, 22));
		comboOperation.setEditable(false);
		comboOperation
				.addActionListener(new MainFrame_comboOperation_actionAdapter(
						this));
		jLabel5.setText("");
		jLabel7.setText("");
		gridLayout1.setColumns(7);
		gridLayout1.setHgap(10);
		paneCenter.setLayout(gridLayoutCenter);
		gridLayoutCenter.setColumns(1);
		gridLayoutCenter.setHgap(3);
		gridLayoutCenter.setRows(1);
		gridLayoutCenter.setVgap(3);
		paneCenter.setBackground(Color.white);
		paneCenter.setBorder(border4);
		txtTimes.setText("1");
		txtTimes.setHorizontalAlignment(SwingConstants.RIGHT);
		paneSouth.add(btnAbout, null);
		paneSouth.add(jLabel1, null);
		paneSouth.add(txtTimes, null);
		paneSouth.add(chb, null);
		paneSouth.add(btnTest, null);
		paneSouth.add(jLabel2, null);
		contentPane.add(paneNorth, BorderLayout.NORTH);
		contentPane.add(paneSouth, BorderLayout.SOUTH);
		contentPane.add(jScrollPane1, BorderLayout.CENTER);
		jScrollPane1.getViewport().add(paneCenter, null);
		paneNorth.add(jLabel3, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
						0, 0, 3), 30, 9));
		paneNorth.add(txtLocation, new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
				new Insets(0, 0, 5, 0), 400, 3));
		paneNorth.add(btnFind, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
						0, 5, 5, 5), 30, 0));
		paneNorth.add(jLabel4, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
						0, 0, 0), 30, 9));
		paneNorth.add(comboService, new GridBagConstraints(1, 1, 2, 1, 1.0,
				0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
				new Insets(0, 0, 5, 0), 400, 3));
		paneNorth.add(jLabel5, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
						0, 0, 1), 50, 25));
		paneNorth.add(jLabel6, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
						0, 0, 0), 30, 9));
		paneNorth.add(comboOperation, new GridBagConstraints(1, 2, 2, 1, 1.0,
				0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
				new Insets(0, 0, 0, 0), 400, 3));
		paneNorth.add(jLabel7, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
						0, 0, 1), 50, 25));
		paneNorth.add(chbModel, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
						0, 5, 5, 5), 30, 0));
		paneNorth.add(chbAll, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
				       0, 5, 5, 5), 30, 0));
		paneSouth.add(btnExit, null);
	}

	// Overridden so we can exit when window is closed
	protected void processWindowEvent(WindowEvent e) {
		super.processWindowEvent(e);
		if (e.getID() == WindowEvent.WINDOW_CLOSING) {
			System.exit(0);
		}
	}

	void btnExit_actionPerformed(ActionEvent e) {
		System.exit(0);
	}

	void btnAbout_actionPerformed(ActionEvent e) {
		MainFrame_AboutBox dlg = new MainFrame_AboutBox(this);
		dlg.setVisible(true);
	}

	void btnFind_actionPerformed(ActionEvent e) {
		try {
			Collection servers = getServers();
			Iterator it = servers.iterator();
			System.out.println(servers.size());
			invoker = new DynamicInvoker[servers.size()];
			int s = 0;
			while (it.hasNext()) {
				String string = (String) it.next();
				invoker[s] = new DynamicInvoker(string);
				s++;
				System.out.println(string);
			}
			Vector v = invoker[0].enumServiceNames();
			comboService.removeAllItems();
			comboOperation.removeAllItems();
			serviceName = portName = operationName = null;
			if (v.size() == 0) {
				JOptionPane.showMessageDialog(this,
						"No Service found at this location.", "WARNING",
						JOptionPane.WARNING_MESSAGE);
				return;
			}
			Object[] ss = v.toArray();
			Arrays.sort(ss);
			int len = ss.length;
			for (int i = 0; i < len; i++) {
				comboService.addItem((String) ss[i]);
			}
			comboService.setSelectedIndex(0);
		} catch (Exception ex) {
			JOptionPane.showMessageDialog(this, ex.getClass().getName() + ": "
					+ ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
		}
	}

	// by shanben 2007/04/20 读取服务器列表.
	private Collection getServers() {
		Collection result = new ArrayList();
		FileReader reader = null;
		BufferedReader br = null;
		try {
			reader = new FileReader("Servers.txt");
			br = new BufferedReader(reader);
			String str = "";
			while ((str = br.readLine()) != null) {
				result.add(str);
			}
		} catch (IOException ex) {
			ex.printStackTrace();
		} finally {
			try {
				reader.close();
				br.close();
			} catch (IOException ex1) {
				ex1.printStackTrace();
			}
		}
		return result;
	}

	private String selectEntry(Vector v, String entryName) {
		if (v.size() == 0) {
			return null;
		} else if (v.size() > 1) {
			SelectDialog dlg = new SelectDialog(this, entryName, v, "Select a "
					+ entryName + " from this list:");
			dlg.setVisible(true);
			return dlg.result;
		} else {
			return (String) v.elementAt(0);
		}
	}

	void comboService_actionPerformed(ActionEvent e) {
		try {
			serviceName = (String) comboService.getSelectedItem();
			if (serviceName == null) {
				return;
			}
			Vector v = invoker[0].enumPortNames(serviceName);

			portName = selectEntry(v, "Port");
			if (portName == null) {
				JOptionPane.showMessageDialog(this, "No port found in service "
						+ serviceName, "WARNING", JOptionPane.WARNING_MESSAGE);
				return;
			}
			v = invoker[0].enumOperationNames(serviceName, portName);
			comboOperation.removeAllItems();
			Object[] ss = v.toArray();
			Arrays.sort(ss);
			int len = ss.length;
			for (int i = 0; i < len; i++) {
				comboOperation.addItem((String) ss[i]);
			}
			comboOperation.setSelectedIndex(0);
		} catch (Exception ex) {
			JOptionPane.showMessageDialog(this, ex.getClass().getName() + ": "
					+ ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
		}
	}

	void comboOperation_actionPerformed(ActionEvent e) {
		try {
			operationName = (String) comboOperation.getSelectedItem();
			if (serviceName == null || operationName == null
					|| portName == null) {
				return;
			}
			parameters = invoker[0].enumParameters(serviceName, portName,
					operationName);
			if (parameters == null) {
				return;
			}
			Vector v = parameters.list;
			int size = v.size();
			if (size == 0) {
				paneCenter.removeAll();
				gridLayoutCenter.setRows(10);
				paneCenter.add(new JLabel("This operation has no parameter."));
			} else {
				paneCenter.removeAll();
				gridLayoutCenter.setRows(Math.max(size, 10));
				txtParameterValues = new JTextField[size];
				for (int i = 0; i < size; i++) {
					Parameter para = (Parameter) v.elementAt(i);

⌨️ 快捷键说明

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