📄 soapmonitor.java
字号:
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; } } /** * This class is a thred for a JProgressBar. */ class BarThread extends Thread { /** * Field wait */ private int wait = 100; /** * Field progressBar */ JProgressBar progressBar = null; /** * Constructor BarThread * * @param bar */ public BarThread(JProgressBar bar) { progressBar = bar; } /** * Method run */ public void run() { int min = progressBar.getMinimum(); int max = progressBar.getMaximum(); Runnable runner = new Runnable() { public void run() { int val = progressBar.getValue(); progressBar.setValue(val + 1); } }; for (int i = min; i < max; i++) { try { SwingUtilities.invokeAndWait(runner); Thread.sleep(wait); } catch (InterruptedException ignoredException) { } catch (InvocationTargetException ignoredException) { } } } } /** * Get the server-config.wsdd as a document to retrieve deployed services * * @return */ private Document getServerWSDD() { 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; } /** * Deploy the specified wsdd to change the monitoring state * * @param wsdd * @return */ private boolean doDeploy(Document wsdd) { 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; } /** * Get a new document which has the specified node as the document root * * @param target * @return */ private Document getNewDocumentAsNode(Node target) { 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; } /** * Add needed nodes for monitoring to the specified node * <p/> * TODO: support JAX-RPC type definition (i.e. <handlerInfoChain/>) * * @param target * @return */ private Node addMonitor(Node target) { 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(); } /** * Remove a few nodes for stoping monitor from the specified node * <p/> * TODO: support JAX-RPC type definition (i.e. <handlerInfoChain/>) * * @param target * @return */ private Node delMonitor(Node target) { 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(); } /** * Get a boolean value whether the specified node is monitoring or not * * @param target * @return */ private boolean isMonitored(Node target) { 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; } /** * Add a few nodes for authentification * <p/> * TODO: support JAX-RPC type definition (i.e. <handlerInfoChain/>) * * @param target * @return */ private Node addAuthenticate(Node target) { 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(); } /** * Handle the window close event */ class MyWindowAdapter extends WindowAdapter { /** * Method windowClosing * * @param e */ public void windowClosing(WindowEvent e) { System.exit(0); } } /** * Add a page to the notebook * * @param pg */ private void addPage(SOAPMonitorPage pg) { tabbed_pane.addTab(" " + pg.getHost() + " ", pg); pages.addElement(pg); } /** * Del all pages to the notebook */ private void delPage() { tabbed_pane.removeAll(); pages.removeAllElements(); } /** * Frame is being displayed */ public void start() { // 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(); } } } /* * Frame is no longer displayed
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -