SOAPMonitorpublic class SOAPMonitor extends JFrame implements ActionListener, ChangeListenerThis is a SOAP Monitor Application class. This class provides
the user interface for deploying the SOAP monitor service and
displaying data from the service. |
Fields Summary |
---|
private JPanel | main_panelPrivate data | private JTabbedPane | tabbed_paneField tabbed_pane | private JTabbedPane | top_paneField top_pane | private int | portField port | private String | axisHostField axisHost | private int | axisPortField axisPort | private String | axisURLField axisURL | private Vector | pagesField pages | private final String | titleStrField titleStr | private JPanel | set_panelField set_panel | private JLabel | titleLabelField titleLabel | private JButton | add_btnField add_btn | private JButton | del_btnField del_btn | private JButton | save_btnField save_btn | private JButton | login_btnField login_btn | private DefaultListModel | model1Field model1 | private DefaultListModel | model2Field model2 | private JList | list1Field list1 | private JList | list2Field list2 | private HashMap | serviceMapField serviceMap | private Document | originalDocField originalDoc | private static String | axisUserField axisUser | private static String | axisPassField axisPass | private org.apache.axis.client.AdminClient | adminClientField adminClient |
Constructors Summary |
---|
public SOAPMonitor()Constructor
setTitle("SOAP Monitor Application");
Dimension d = getToolkit().getScreenSize();
setSize(640, 480);
setLocation((d.width - getWidth()) / 2, (d.height - getHeight()) / 2);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
addWindowListener(new MyWindowAdapter());
// Try to use the system look and feel
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
}
// Create main panel to hold notebook
main_panel = new JPanel();
main_panel.setBackground(Color.white);
main_panel.setLayout(new BorderLayout());
top_pane = new JTabbedPane();
set_panel = new JPanel();
// label for NORTH panel to display the pain title
titleLabel = new JLabel(titleStr);
titleLabel.setFont(new Font("Serif", Font.BOLD, 18));
// list control for WEST panel to list NOT monitored services
model1 = new DefaultListModel();
list1 = new JList(model1);
list1.setFixedCellWidth(250);
JScrollPane scroll1 = new JScrollPane(list1);
// list control for EAST panel to list monitored services
model2 = new DefaultListModel();
list2 = new JList(model2);
list2.setFixedCellWidth(250);
JScrollPane scroll2 = new JScrollPane(list2);
// buttons for CENTER panel to chage the monitoring state
add_btn = new JButton("Turn On [ >> ]");
del_btn = new JButton("[ << ] Turn Off");
JPanel center_panel = new JPanel();
GridBagLayout layout = new GridBagLayout();
center_panel.setLayout(layout);
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(10, 10, 10, 10);
layout.setConstraints(add_btn, c);
center_panel.add(add_btn);
c.gridx = 0;
c.gridy = 1;
c.insets = new Insets(10, 10, 10, 10);
layout.setConstraints(del_btn, c);
center_panel.add(del_btn);
// buttons for SOUTH panel
save_btn = new JButton("Save changes");
login_btn = new JButton("Change server");
JPanel south_panel = new JPanel();
layout = new GridBagLayout();
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(10, 10, 10, 10);
layout.setConstraints(save_btn, c);
south_panel.add(save_btn);
c.gridx = 1;
c.gridy = 0;
c.insets = new Insets(10, 10, 10, 10);
layout.setConstraints(login_btn, c);
south_panel.add(login_btn);
// set all controls to the border layout
set_panel.setLayout(new BorderLayout(5, 5));
set_panel.add(titleLabel, BorderLayout.NORTH);
set_panel.add(south_panel, BorderLayout.SOUTH);
set_panel.add(scroll1, BorderLayout.WEST);
set_panel.add(scroll2, BorderLayout.EAST);
set_panel.add(center_panel, BorderLayout.CENTER);
// register the Action Listener
add_btn.addActionListener(this);
del_btn.addActionListener(this);
save_btn.addActionListener(this);
login_btn.addActionListener(this);
// set default button state as 'false'
add_btn.setEnabled(false);
del_btn.setEnabled(false);
save_btn.setEnabled(false);
login_btn.setEnabled(false);
top_pane.add("Setting", set_panel);
top_pane.add("Monitoring", main_panel);
getContentPane().add(top_pane);
// Create the notebook
tabbed_pane = new JTabbedPane(JTabbedPane.TOP);
main_panel.add(tabbed_pane, BorderLayout.CENTER);
top_pane.addChangeListener(this);
top_pane.setEnabled(false);
setVisible(true);
|
Methods Summary |
---|
public void | actionPerformed(java.awt.event.ActionEvent e)Listener to handle button actions
Object obj = e.getSource();
if (obj == add_btn) {
int selected[] = list1.getSelectedIndices();
int len = selected.length - 1;
for (int i = len; i >= 0; i--) {
model2.addElement(model1.getElementAt(selected[i]));
model1.remove(selected[i]);
}
if (model1.size() == 0) {
add_btn.setEnabled(false);
}
if (model2.size() > 0) {
del_btn.setEnabled(true);
}
} else if (obj == del_btn) {
int selected[] = list2.getSelectedIndices();
int len = selected.length - 1;
for (int i = len; i >= 0; i--) {
model1.addElement(model2.getElementAt(selected[i]));
model2.remove(selected[i]);
}
if (model2.size() == 0) {
del_btn.setEnabled(false);
}
if (model1.size() > 0) {
add_btn.setEnabled(true);
}
} else if (obj == login_btn) {
if (doLogin()) {
delPage();
addPage(new SOAPMonitorPage(axisHost));
start();
} else {
add_btn.setEnabled(false);
del_btn.setEnabled(false);
}
} else if (obj == save_btn) {
String service = null;
Node node = null;
Node impNode = null;
Document wsdd = null;
JOptionPane pane = null;
JDialog dlg = null;
String msg = null;
final String title = "Deployment status";
final String deploy = "<deployment name=\"SOAPMonitor\""
+ " xmlns=\"http://xml.apache.org/axis/wsdd/\""
+ " xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\">\n"
+ " <handler name=\"soapmonitor\""
+ " type=\"java:org.apache.axis.handlers.SOAPMonitorHandler\" />\n"
+ " </deployment>";
// Create a new wsdd document
try {
wsdd = XMLUtils.newDocument(
new ByteArrayInputStream(deploy.getBytes()));
} catch (Exception ex) {
ex.printStackTrace();
}
Collection col = serviceMap.keySet();
Iterator ite = col.iterator();
// Add all of service nodes to the new wsdd
while (ite.hasNext()) {
service = (String) ite.next();
node = (Node) serviceMap.get(service);
if (model2.contains(service)) {
if (isMonitored(node)) { // It's already been monitored
impNode = wsdd.importNode(node, true);
} else { // It's to be monitored
impNode = wsdd.importNode(addMonitor(node), true);
}
} else {
if (isMonitored(node)) { // It's not to be monitored
impNode = wsdd.importNode(delMonitor(node), true);
} else { // It's not already been monitored
impNode = wsdd.importNode(node, true);
}
}
if (service.equals("AdminService")) {
// Add "SimpleAuthenticationHandler" and "allowedRoles" parameter
// with "admin" as a user account
impNode = wsdd.importNode(addAuthenticate(impNode), true);
}
wsdd.getDocumentElement().appendChild(impNode);
}
// Show the result of deployment
pane = new JOptionPane();
if (doDeploy(wsdd)) {
msg = "The deploy was successful.";
pane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
} else {
msg = "The deploy was NOT successful.";
pane.setMessageType(JOptionPane.WARNING_MESSAGE);
}
pane.setOptions(new String[]{"OK"});
pane.setMessage(msg);
dlg = pane.createDialog(null, title);
dlg.setVisible(true);
}
| private org.w3c.dom.Node | addAuthenticate(org.w3c.dom.Node target)Add a few nodes for authentification
TODO: support JAX-RPC type definition (i.e. )
Document doc = null;
Node node = null;
Node newNode = null;
String ret = null;
NodeList nl = null;
final String reqFlow = "requestFlow";
final String handler = "handler";
final String type = "type";
final String authentication =
"java:org.apache.axis.handlers.SimpleAuthenticationHandler";
final String authorization =
"java:org.apache.axis.handlers.SimpleAuthorizationHandler";
final String param = "parameter";
final String name = "name";
final String role = "allowedRoles";
final String value = "value";
final String admin = "admin";
boolean authNode = false;
boolean roleNode = false;
doc = getNewDocumentAsNode(target);
// Add "requestFlow" node
nl = doc.getElementsByTagName(reqFlow);
if (nl.getLength() == 0) {
node = doc.getDocumentElement().getFirstChild();
newNode = doc.createElement(reqFlow);
doc.getDocumentElement().insertBefore(newNode, node);
}
// Add "SimpleAuthorizationHandler"
// (i.e. <handler type="java:org.apache.axis.handlers.SimpleAuthorizationHandler"/>)
nl = doc.getElementsByTagName(handler);
for (int i = 0; i < nl.getLength(); i++) {
node = nl.item(i);
NamedNodeMap map = node.getAttributes();
ret = map.getNamedItem(type).getNodeValue();
if (ret.equals(authorization)) {
authNode = true;
break;
}
}
if (!authNode) {
nl = doc.getElementsByTagName(reqFlow);
node = nl.item(0).getFirstChild();
newNode = doc.createElement(handler);
((Element) newNode).setAttribute(type, authorization);
nl.item(0).insertBefore(newNode, node);
}
// Add "SimpleAuthenticationHandler"
// (i.e. <handler type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>)
authNode = false;
nl = doc.getElementsByTagName(handler);
for (int i = 0; i < nl.getLength(); i++) {
node = nl.item(i);
NamedNodeMap map = node.getAttributes();
ret = map.getNamedItem(type).getNodeValue();
if (ret.equals(authentication)) {
authNode = true;
break;
}
}
if (!authNode) {
nl = doc.getElementsByTagName(reqFlow);
node = nl.item(0).getFirstChild();
newNode = doc.createElement(handler);
((Element) newNode).setAttribute(type, authentication);
nl.item(0).insertBefore(newNode, node);
}
// Add "allowedRoles" (i.e. <parameter name="allowedRoles" value="admin"/> )
nl = doc.getElementsByTagName(param);
for (int i = 0; i < nl.getLength(); i++) {
node = nl.item(i);
NamedNodeMap map = node.getAttributes();
node = map.getNamedItem(name);
if (node != null) {
ret = node.getNodeValue();
if (ret.equals(role)) {
roleNode = true;
break;
}
}
}
if (!roleNode) {
nl = doc.getElementsByTagName(param);
newNode = doc.createElement(param);
((Element) newNode).setAttribute(name, role);
((Element) newNode).setAttribute(value, admin);
doc.getDocumentElement().insertBefore(newNode, nl.item(0));
}
return (Node) doc.getDocumentElement();
| private org.w3c.dom.Node | addMonitor(org.w3c.dom.Node target)Add needed nodes for monitoring to the specified node
TODO: support JAX-RPC type definition (i.e. )
Document doc = null;
Node node = null;
Node newNode = null;
String ret = null;
NodeList nl = null;
final String reqFlow = "requestFlow";
final String resFlow = "responseFlow";
final String monitor = "soapmonitor";
final String handler = "handler";
final String type = "type";
doc = getNewDocumentAsNode(target);
// Add "responseFlow node
nl = doc.getElementsByTagName(resFlow);
if (nl.getLength() == 0) {
node = doc.getDocumentElement().getFirstChild();
newNode = doc.createElement(resFlow);
doc.getDocumentElement().insertBefore(newNode, node);
}
// Add "requestFlow" node
nl = doc.getElementsByTagName(reqFlow);
if (nl.getLength() == 0) {
node = doc.getDocumentElement().getFirstChild();
newNode = doc.createElement(reqFlow);
doc.getDocumentElement().insertBefore(newNode, node);
}
// Add "handler" node and "soapmonitor" attribute for "requestFlow"
nl = doc.getElementsByTagName(reqFlow);
node = nl.item(0).getFirstChild();
newNode = doc.createElement(handler);
((Element) newNode).setAttribute(type, monitor);
nl.item(0).insertBefore(newNode, node);
// Add "handler" node and "soapmonitor" attribute for "responseFlow"
nl = doc.getElementsByTagName(resFlow);
node = nl.item(0).getFirstChild();
newNode = doc.createElement(handler);
((Element) newNode).setAttribute(type, monitor);
nl.item(0).insertBefore(newNode, node);
return (Node) doc.getDocumentElement();
| private void | addPage(org.apache.axis.utils.SOAPMonitor$SOAPMonitorPage pg)Add a page to the notebook
tabbed_pane.addTab(" " + pg.getHost() + " ", pg);
pages.addElement(pg);
| private org.w3c.dom.Node | delMonitor(org.w3c.dom.Node target)Remove a few nodes for stoping monitor from the specified node
TODO: support JAX-RPC type definition (i.e. )
Document doc = null;
Node node = null;
Node newNode = null;
String ret = null;
NodeList nl = null;
final String reqFlow = "requestFlow";
final String resFlow = "responseFlow";
final String monitor = "soapmonitor";
final String handler = "handler";
final String type = "type";
doc = getNewDocumentAsNode(target);
nl = doc.getElementsByTagName(handler);
int size;
size = nl.getLength();
Node[] removeNode = new Node[size];
if (size > 0) {
newNode = nl.item(0).getParentNode();
}
for (int i = 0; i < size; i++) {
node = nl.item(i);
NamedNodeMap map = node.getAttributes();
ret = map.getNamedItem(type).getNodeValue();
if (ret.equals(monitor)) {
removeNode[i] = node;
}
}
for (int i = 0; i < size; i++) {
Node child = removeNode[i];
if (child != null) {
child.getParentNode().removeChild(child);
}
}
return (Node) doc.getDocumentElement();
| private void | delPage()Del all pages to the notebook
tabbed_pane.removeAll();
pages.removeAllElements();
| private boolean | doDeploy(org.w3c.dom.Document wsdd)Deploy the specified wsdd to change the monitoring state
String deploy = null;
Options opt = null;
deploy = XMLUtils.DocumentToString(wsdd);
try {
String[] param = new String[]{"-u" + axisUser, "-w" + axisPass,
"-l " + axisURL, ""};
opt = new Options(param);
adminClient.process(opt,
new ByteArrayInputStream(deploy.getBytes()));
} catch (Exception e) {
return false;
}
return true;
| private boolean | doLogin()Do login process
Dimension d = null;
// Login
LoginDlg login = new LoginDlg();
login.show();
if (!login.isLogin()) {
login_btn.setEnabled(true);
return false;
}
login.dispose();
save_btn.setEnabled(false);
login_btn.setEnabled(false);
// Get the axisHost & axisPort to be used
String url_str = login.getURL();
try {
URL url = new URL(url_str);
axisHost = url.getHost();
axisPort = url.getPort();
if (axisPort == -1) {
axisPort = 8080;
}
String axisPath = url.getPath();
axisURL = "http://" + axisHost + ":" + axisPort + axisPath;
} catch (MalformedURLException e) {
JOptionPane pane = new JOptionPane();
String msg = e.toString();
pane.setMessageType(JOptionPane.WARNING_MESSAGE);
pane.setMessage(msg);
pane.setOptions(new String[]{"OK"});
JDialog dlg = pane.createDialog(null, "Login status");
dlg.setVisible(true);
login_btn.setEnabled(true);
return false;
}
titleLabel.setText(titleStr + " for [" + axisHost + ":" + axisPort
+ "]");
final JProgressBar progressBar = new JProgressBar(0, 100);
BarThread stepper = new BarThread(progressBar);
stepper.start();
JFrame progress = new JFrame();
d = new Dimension(250, 50);
progress.setSize(d);
d = getToolkit().getScreenSize();
progress.getContentPane().add(progressBar);
progress.setTitle("Now loading data ...");
progress.setLocation((d.width - progress.getWidth()) / 2,
(d.height - progress.getHeight()) / 2);
progress.show();
// Add notebook page for default host connection
pages = new Vector();
addPage(new SOAPMonitorPage(axisHost));
serviceMap = new HashMap();
originalDoc = getServerWSDD();
model1.clear();
model2.clear();
if (originalDoc != null) {
String ret = null;
NodeList nl = originalDoc.getElementsByTagName("service");
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
NamedNodeMap map = node.getAttributes();
ret = map.getNamedItem("name").getNodeValue();
serviceMap.put(ret, node);
if (!isMonitored(node)) {
model1.addElement((String) ret);
} else {
model2.addElement((String) ret);
}
}
if (model1.size() > 0) {
add_btn.setEnabled(true);
}
if (model2.size() > 0) {
del_btn.setEnabled(true);
}
progress.dispose();
save_btn.setEnabled(true);
login_btn.setEnabled(true);
top_pane.setEnabled(true);
return true;
} else {
progress.dispose();
login_btn.setEnabled(true);
return false;
}
| private org.w3c.dom.Document | getNewDocumentAsNode(org.w3c.dom.Node target)Get a new document which has the specified node as the document root
Document doc = null;
Node node = null;
try {
doc = XMLUtils.newDocument();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
node = doc.importNode(target, true);
doc.appendChild(node);
return doc;
| private org.w3c.dom.Document | getServerWSDD()Get the server-config.wsdd as a document to retrieve deployed services
Document doc = null;
try {
String[] param = new String[]{"-u" + axisUser, "-w" + axisPass,
"-l " + axisURL, "list"};
String ret = adminClient.process(param);
doc = XMLUtils.newDocument(
new ByteArrayInputStream(ret.getBytes()));
} catch (Exception e) {
JOptionPane pane = new JOptionPane();
String msg = e.toString();
pane.setMessageType(JOptionPane.WARNING_MESSAGE);
pane.setMessage(msg);
pane.setOptions(new String[]{"OK"});
JDialog dlg = pane.createDialog(null, "Login status");
dlg.setVisible(true);
}
return doc;
| private boolean | isMonitored(org.w3c.dom.Node target)Get a boolean value whether the specified node is monitoring or not
Document doc = null;
Node node = null;
String ret = null;
NodeList nl = null;
final String monitor = "soapmonitor";
final String handler = "handler";
final String type = "type";
doc = getNewDocumentAsNode(target);
nl = doc.getElementsByTagName(handler);
for (int i = 0; i < nl.getLength(); i++) {
node = nl.item(i);
NamedNodeMap map = node.getAttributes();
ret = map.getNamedItem(type).getNodeValue();
if (ret.equals(monitor)) {
return true;
} else {
return false;
}
}
return false;
| public static void | main(java.lang.String[] args)Main method for this class
SOAPMonitor soapMonitor = null;
Options opts = new Options(args);
if (opts.isFlagSet('?") > 0) {
System.out.println(
"Usage: SOAPMonitor [-l<url>] [-u<user>] [-w<password>] [-?]");
System.exit(0);
}
// Create an instance
soapMonitor = new SOAPMonitor();
// GET Axis URL.
// The default is "http://localhost:8080/axis/servlet/AxisServlet"
soapMonitor.axisURL = opts.getURL();
URL url = new URL(soapMonitor.axisURL);
soapMonitor.axisHost = url.getHost();
// GET User name & Password
axisUser = opts.getUser();
axisPass = opts.getPassword();
// Login and start application
soapMonitor.doLogin();
| public void | start()Frame is being displayed
// Tell all pages to start talking to the server
Enumeration e = pages.elements();
while (e.hasMoreElements()) {
SOAPMonitorPage pg = (SOAPMonitorPage) e.nextElement();
if (pg != null) {
pg.start();
}
}
| public void | stateChanged(javax.swing.event.ChangeEvent e)ChangeListener to handle tab actions
JTabbedPane tab = (JTabbedPane)e.getSource();
int item = tab.getSelectedIndex();
if (item==1) { // "Monitoring" tab is selected.
start();
} else { // "Setting" tab is selected.
stop();
}
| public void | stop()Method stop
// Tell all pages to stop talking to the server
Enumeration e = pages.elements();
while (e.hasMoreElements()) {
SOAPMonitorPage pg = (SOAPMonitorPage) e.nextElement();
if (pg != null) {
pg.stop();
}
}
|
|