FileDocCategorySizeDatePackage
SOAPMonitor.javaAPI DocApache Axis 1.493420Sat Apr 22 18:57:28 BST 2006org.apache.axis.utils

SOAPMonitor

public class SOAPMonitor extends JFrame implements ActionListener, ChangeListener
This is a SOAP Monitor Application class. This class provides the user interface for deploying the SOAP monitor service and displaying data from the service.
author
Toshiyuki Kimura (toshi@apache.org)
author
Brian Price (pricebe@us.ibm.com)

Fields Summary
private JPanel
main_panel
Private data
private JTabbedPane
tabbed_pane
Field tabbed_pane
private JTabbedPane
top_pane
Field top_pane
private int
port
Field port
private String
axisHost
Field axisHost
private int
axisPort
Field axisPort
private String
axisURL
Field axisURL
private Vector
pages
Field pages
private final String
titleStr
Field titleStr
private JPanel
set_panel
Field set_panel
private JLabel
titleLabel
Field titleLabel
private JButton
add_btn
Field add_btn
private JButton
del_btn
Field del_btn
private JButton
save_btn
Field save_btn
private JButton
login_btn
Field login_btn
private DefaultListModel
model1
Field model1
private DefaultListModel
model2
Field model2
private JList
list1
Field list1
private JList
list2
Field list2
private HashMap
serviceMap
Field serviceMap
private Document
originalDoc
Field originalDoc
private static String
axisUser
Field axisUser
private static String
axisPass
Field axisPass
private org.apache.axis.client.AdminClient
adminClient
Field 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 voidactionPerformed(java.awt.event.ActionEvent e)
Listener to handle button actions

param
e

        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.NodeaddAuthenticate(org.w3c.dom.Node target)
Add a few nodes for authentification

TODO: support JAX-RPC type definition (i.e. )

param
target
return

        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.NodeaddMonitor(org.w3c.dom.Node target)
Add needed nodes for monitoring to the specified node

TODO: support JAX-RPC type definition (i.e. )

param
target
return

        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 voidaddPage(org.apache.axis.utils.SOAPMonitor$SOAPMonitorPage pg)
Add a page to the notebook

param
pg

        tabbed_pane.addTab("  " + pg.getHost() + "  ", pg);
        pages.addElement(pg);
    
private org.w3c.dom.NodedelMonitor(org.w3c.dom.Node target)
Remove a few nodes for stoping monitor from the specified node

TODO: support JAX-RPC type definition (i.e. )

param
target
return

        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 voiddelPage()
Del all pages to the notebook

        tabbed_pane.removeAll();
        pages.removeAllElements();
    
private booleandoDeploy(org.w3c.dom.Document wsdd)
Deploy the specified wsdd to change the monitoring state

param
wsdd
return

        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 booleandoLogin()
Do login process

return

        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.DocumentgetNewDocumentAsNode(org.w3c.dom.Node target)
Get a new document which has the specified node as the document root

param
target
return

        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.DocumentgetServerWSDD()
Get the server-config.wsdd as a document to retrieve deployed services

return

        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 booleanisMonitored(org.w3c.dom.Node target)
Get a boolean value whether the specified node is monitoring or not

param
target
return

        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 voidmain(java.lang.String[] args)
Main method for this class

param
args
throws
Exception


                     
           
        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 voidstart()
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 voidstateChanged(javax.swing.event.ChangeEvent e)
ChangeListener to handle tab actions

param
e

        JTabbedPane tab = (JTabbedPane)e.getSource();
        int item = tab.getSelectedIndex();
        if (item==1) { // "Monitoring" tab is selected.
            start();
        } else {       // "Setting" tab is selected.
            stop();
        }
    
public voidstop()
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();
            }
        }