private NBFields getPluginList(String pluginName) throws ParserConfigurationException, SAXException, IOException, TransformerException { NBFields fields = new NBFields(); DOMConfigurator dom = new DOMConfigurator(ServerConfiguration.getConfigFile()); ArrayList<HashMap<String, String>> getPluginList = dom.getSubNodeListParamMap("server/plug-in-list"); ArrayList<NBFields> pluginList = new ArrayList<NBFields>(); for (int i = 0; i < getPluginList.size(); i++) { if (pluginName.equals("")) { NBFields pluginFields = new NBFields(); pluginFields.put("ID", getPluginList.get(i).get("id")); pluginFields.put("NAME", getPluginList.get(i).get("name")); pluginFields.put("TYPE", getPluginList.get(i).get("type")); pluginList.add(pluginFields); } else { if (getPluginList.get(i).get("id").contains(pluginName)) { NBFields pluginFields = new NBFields(); pluginFields.put("ID", getPluginList.get(i).get("id")); pluginFields.put("NAME", getPluginList.get(i).get("name")); pluginFields.put("TYPE", getPluginList.get(i).get("type")); pluginList.add(pluginFields); } } } fields.put("PLG_LST", pluginList); return fields; }
public void openInstanceView( String serverName, InstanceList instanceList, NBFields netFields, Server server) { try { ArrayList<Boolean> runStateList = new ArrayList<Boolean>(); if (netFields != null) { @SuppressWarnings("unchecked") ArrayList<NBFields> nList = (ArrayList<NBFields>) netFields.get("INSTANCE_LIST"); ArrayList<String> iList = new ArrayList<String>(); try { for (int i = 0; i < nList.size(); i++) { iList.add((String) nList.get(i).get("INSTANCE_NAME")); runStateList.add(((String) nList.get(i).get("RUNNING")).equals("true")); } instanceList.setList(iList); } catch (NullPointerException e) { } } IPCProtocol protocol = server.getConnect().getProtocol(); InstanceView instanceView = (InstanceView) getSite().getPage().showView(InstanceView.ID); instanceView.setProtocol(protocol); instanceView.setPartName(serverName); instanceView.setInstance(serverName, instanceList.getList(), runStateList); instanceView.setPartProperty("SERVER_NAME", serverName); instanceView.setServer(server); } catch (PartInitException e) { IMessageBox.Error(shell, NBLabel.get(0x0096)); } }
private boolean controlServer(int messageType, IPCProtocol protocol) { NBFields fields = new NBFields(); fields.put(IPC.NB_MSG_TYPE, messageType); fields.put(IPC.NB_LOAD_CLASS, "com.nabsys.management.server.ControlServer"); try { fields = protocol.execute(fields); if ((Integer) fields.get(IPC.NB_MSG_RETURN) == IPC.FAIL) { IMessageBox.Error(shell, (String) fields.get("RTN_MSG")); return false; } else { return true; } } catch (SocketClosedException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); return false; } catch (TimeoutException e) { IMessageBox.Error(shell, e.getMessage()); return false; } catch (NetException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); return false; } catch (UnsupportedEncodingException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); return false; } catch (NoSuchAlgorithmException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); return false; } catch (DataTypeException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); return false; } catch (ProtocolException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); return false; } }
private NBFields getServerConfigInfo(IPCProtocol protocol) { NBFields fields = new NBFields(); fields.put(IPC.NB_LOAD_CLASS, "com.nabsys.management.server.ServerConfig"); fields.put("CMD_CODE", "R"); try { fields = protocol.execute(fields); if ((Integer) fields.get(IPC.NB_MSG_RETURN) == IPC.FAIL) { IMessageBox.Error(shell, (String) fields.get("RTN_MSG")); } } catch (SocketClosedException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); fields = null; } catch (TimeoutException e) { IMessageBox.Error(shell, e.getMessage()); fields = null; } catch (NetException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); fields = null; } catch (UnsupportedEncodingException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); fields = null; } catch (NoSuchAlgorithmException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); fields = null; } catch (DataTypeException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); fields = null; } catch (ProtocolException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); fields = null; } return fields; }
private void setPlugin(NBFields actionInfo, DOMConfigurator dom) throws TransformerException { if (actionInfo.get("ACT").equals("U")) { dom.setParamByID( "server/plug-in-list/plug-in", (String) actionInfo.get("KEY"), ((String) actionInfo.get("FLD")).toLowerCase(), (String) actionInfo.get("VLU")); } else if (actionInfo.get("ACT").equals("D")) { dom.removeByID("server/plug-in-list", (String) actionInfo.get("KEY")); } }
private void setParameter(NBFields actionInfo, DOMConfigurator dom) throws TransformerException { ArrayList<String> idList = new ArrayList<String>(); idList.add((String) actionInfo.get("PID")); idList.add((String) actionInfo.get("KEY")); if (actionInfo.get("ACT").equals("U")) { dom.setProtocolParam( "server/plug-in-list/plug-in/param", (String) actionInfo.get("PID"), (String) actionInfo.get("KEY"), (String) actionInfo.get("FLD"), (String) actionInfo.get("VLU")); } else if (actionInfo.get("ACT").equals("D")) { dom.removeProtocolParam( "server/plug-in-list/plug-in/param", (String) actionInfo.get("PID"), (String) actionInfo.get("KEY")); } }
public boolean connectServer(HashMap<String, String> params) { ServerConnect connect = null; Server server = null; if (!treeViewer.getSelection().isEmpty()) { IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); if (selection.getFirstElement() instanceof Server) { server = (Server) selection.getFirstElement(); connect = server.getConnect(); } else { IMessageBox.Error(shell, NBLabel.get(0x0090)); return true; } if (params.containsKey("SAVE_FLAG") && params.get("SAVE_FLAG").equals("true")) connect.setPassword(params.get("PASSWORD")); params.put("IP_ADDRESS", connect.getHostAddr()); params.put("PORT", Integer.toString(connect.getHostPort())); params.put("ENCODING", connect.getServerEncoding()); } else if (params.containsKey("SERVER_NAME")) { String serverName = params.get("SERVER_NAME"); ArrayList<Model> children = ((Model) treeViewer.getInput()).getChildren(); for (int i = 0; i < children.size(); i++) { if (serverName.equals(children.get(i).getName())) { server = (Server) children.get(i); connect = ((Server) children.get(i)).getConnect(); } } } else { IMessageBox.Error(shell, NBLabel.get(0x0090)); return true; } try { Socket socket = new Socket(params.get("IP_ADDRESS"), Integer.parseInt(params.get("PORT")), 4096, 30); InstanceHeaderFields fields = new InstanceHeaderFields(); fields.put( "LENGTH", new TelegramFieldContext("LENGTH", "LENGTH", 0, 4, true, ' ', ' ', 'I', "")); fields.put( "MSG_TYPE", new TelegramFieldContext("MSG_TYPE", "MSG_TYPE", 1, 4, true, ' ', ' ', 'I', "")); fields.put( "RETURN", new TelegramFieldContext("RETURN", "RETURN", 2, 4, true, ' ', ' ', 'I', "")); fields.setLengthFieldIndex("LENGTH"); fields.setMsgTypeFieldIndex("MSG_TYPE"); fields.setReturnFieldIndex("RETURN"); IPCProtocol protocol = new IPCProtocol( socket, params.get("USER"), params.get("PASSWORD"), fields, params.get("ENCODING")); connect.setProtocol(protocol); NBFields netFields = new NBFields(); netFields.put(IPC.NB_LOAD_CLASS, "com.nabsys.management.instance.InstanceConfig"); netFields.put("CMD_CODE", "L"); netFields = protocol.execute(netFields); if (protocol.getUserAuthority().equals("Admin")) { new ServerConfig( server, NBLabel.get(0x0049), Activator.getImageDescriptor("/icons/config_obj.gif").createImage(display)); new UserList( server, NBLabel.get(0x009D), Activator.getImageDescriptor("/icons/user_view.gif").createImage(display)); new InstanceList( server, NBLabel.get(0x0093), Activator.getImageDescriptor("/icons/pview.gif").createImage(display)); terminateAction.setEnabled(true); } else if (protocol.getUserAuthority().equals("Operator")) { new UserList( server, NBLabel.get(0x009D), Activator.getImageDescriptor("/icons/user_view.gif").createImage(display)); new InstanceList( server, NBLabel.get(0x0093), Activator.getImageDescriptor("/icons/pview.gif").createImage(display)); } else if (protocol.getUserAuthority().equals("Developer")) { new InstanceList( server, NBLabel.get(0x0093), Activator.getImageDescriptor("/icons/pview.gif").createImage(display)); } server.setImage(Activator.getImageDescriptor("/icons/conserver.gif").createImage(display)); treeViewer.refresh(); connectAction.setEnabled(false); disconnectAction.setEnabled(true); treeViewer.expandToLevel(server, 1); openInstanceView(server.getName(), server.getInstance(), netFields, server); } catch (NumberFormatException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } catch (NetException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return false; } catch (SocketClosedException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } catch (ClassNotFoundException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } catch (TimeoutException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return false; } catch (UnsupportedEncodingException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } catch (NoSuchAlgorithmException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } catch (DataTypeException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } catch (ProtocolException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } catch (Exception e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } return true; }
public NBFields execute(ManagementContext context, long clientSequence) { NBFields fromClient = context.getFields(); NBFields toClient = new NBFields(); if (fromClient.get("CMD_CODE").equals("R")) { try { toClient = getServerConfig(); } catch (ParserConfigurationException e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "Fail to getting server information."); } catch (SAXException e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "Fail to getting server information."); } catch (IOException e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "Fail to getting server information."); } catch (TransformerException e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "Fail to getting server information."); } catch (NullPointerException e) { logger.error(e, "Null exception."); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "System error occurred."); } catch (Exception e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", e.getMessage()); } } else if (fromClient.get("CMD_CODE").equals("S")) { try { setServerConfig(fromClient, context); toClient.put(IPC.NB_MSG_RETURN, IPC.SUCCESS); } catch (ParserConfigurationException e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "Fail to setting server information."); } catch (SAXException e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "Fail to setting server information."); } catch (IOException e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "Fail to setting server information."); } catch (TransformerException e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "Fail to setting server information."); } catch (NullPointerException e) { logger.error(e, "Null exception."); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "System error occurred."); } catch (Exception e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", e.getMessage()); } } else if (fromClient.get("CMD_CODE").equals("P")) { try { toClient = getPluginList((String) fromClient.get("SCH")); } catch (ParserConfigurationException e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "Fail to getting server information."); } catch (SAXException e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "Fail to getting server information."); } catch (IOException e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "Fail to getting server information."); } catch (TransformerException e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "Fail to getting server information."); } catch (NullPointerException e) { logger.error(e, "Null exception."); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "System error occurred."); } catch (Exception e) { logger.error(e, e.getMessage()); toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", e.getMessage()); } } else { toClient.put(IPC.NB_MSG_RETURN, IPC.FAIL); toClient.put("RTN_MSG", "Unsuppored command code."); } return toClient; }
@SuppressWarnings("unchecked") private void setServerConfig(NBFields fields, ManagementContext context) throws ParserConfigurationException, SAXException, IOException, TransformerException { DOMConfigurator dom = new DOMConfigurator(ServerConfiguration.getConfigFile()); if (fields.containsKey("LICENSE")) { dom.setConf("server/license-key", (String) fields.get("LICENSE")); } if (fields.containsKey("CLASS_PATH")) { dom.setConf("server/default-file-path", (String) fields.get("CLASS_PATH")); } if (fields.containsKey("LOG4J_PATH")) { dom.setConf("server/log-properties", (String) fields.get("LOG4J_PATH")); } if (fields.containsKey("USER_PATH")) { dom.setConf("server/user-config-file", (String) fields.get("USER_PATH")); } if (fields.containsKey("INSTANCE_CONF_PATH")) { dom.setConf("server/instance-config-file", (String) fields.get("INSTANCE_CONF_PATH")); } if (fields.containsKey("LOCALE")) { dom.setConf("server/time-locale", (String) fields.get("LOCALE")); } if (fields.containsKey("ENCODING")) { dom.setConf("server/server-encoding", (String) fields.get("ENCODING")); } if (fields.containsKey("MAX_CLIENT")) { dom.setConf("server/network/max-client-num", (String) fields.get("MAX_CLIENT")); } if (fields.containsKey("SERVICE_PORT")) { dom.setConf("server/network/service-port", (String) fields.get("SERVICE_PORT")); } if (fields.containsKey("SOCK_BUFF_SIZE")) { dom.setConf("server/network/max-socket-buffer", (String) fields.get("SOCK_BUFF_SIZE")); } if (fields.containsKey("SOCK_TIME_OUT")) { dom.setConf("server/network/read-time-out", (String) fields.get("SOCK_TIME_OUT")); } if (fields.containsKey("ACT_LST")) { ArrayList<NBFields> actList = (ArrayList<NBFields>) fields.get("ACT_LST"); for (int i = 0; i < actList.size(); i++) { NBFields act = actList.get(i); if (act.get("CTG").equals("PCL")) { setProtocol(act, dom); } else if (act.get("CTG").equals("PLG")) { setPlugin(act, dom); } else if (act.get("CTG").equals("PRM")) { setParameter(act, dom); } } } logger.info( NLabel.get(0x008C) + " by " + context.getUser() + "(" + context.getClientAddress() + ")"); }
private NBFields getServerConfig() throws ParserConfigurationException, SAXException, IOException, TransformerException { NBFields fields = new NBFields(); DOMConfigurator dom = new DOMConfigurator(ServerConfiguration.getConfigFile()); fields.put("LICENSE", ""); fields.put("ROOT_PATH", dom.getConf("server/default-file-path")); fields.put("LOG4J_PATH", dom.getConf("server/log-properties")); fields.put("USER_PATH", dom.getConf("server/user-config-file")); fields.put("INSTANCE_CONF_PATH", dom.getConf("server/instance-config-file")); fields.put("LOCALE", dom.getConf("server/time-locale")); fields.put("ENCODING", dom.getConf("server/server-encoding")); fields.put("MAX_CLIENT", dom.getConf("server/network/max-client-num")); fields.put("SERVICE_PORT", dom.getConf("server/network/service-port")); fields.put("SOCK_BUFF_SIZE", dom.getConf("server/network/max-socket-buffer")); fields.put("SOCK_TIME_OUT", dom.getConf("server/network/read-time-out")); ArrayList<HashMap<String, String>> getProtocolList = dom.getSubNodeListParamMap("server/protocol-list"); ArrayList<NBFields> protocolList = new ArrayList<NBFields>(); for (int i = 0; i < getProtocolList.size(); i++) { NBFields protocolFields = new NBFields(); protocolFields.put("ID", getProtocolList.get(i).get("id")); protocolFields.put("NAME", getProtocolList.get(i).get("name")); protocolFields.put("CLASS", getProtocolList.get(i).get("class")); protocolList.add(protocolFields); } fields.put("PCL_LIST", protocolList); ArrayList<HashMap<String, String>> getPluginList = dom.getSubNodeListParamMap("server/plug-in-list"); ArrayList<NBFields> pluginList = new ArrayList<NBFields>(); for (int i = 0; i < getPluginList.size(); i++) { NBFields pluginFields = new NBFields(); pluginFields.put("ID", getPluginList.get(i).get("id")); pluginFields.put("NAME", getPluginList.get(i).get("name")); pluginFields.put("TYPE", getPluginList.get(i).get("type")); // Plugin param HashMap<String, String> paramMap = dom.getSubNodeListMapBySubNodeIDList( "server/plug-in-list", (String) pluginFields.get("ID")); Set<String> keyList = paramMap.keySet(); Iterator<String> itr = keyList.iterator(); while (itr.hasNext()) { String key = itr.next(); pluginFields.put("PRM__" + key, paramMap.get(key)); } pluginList.add(pluginFields); } fields.put("PLG_LIST", pluginList); return fields; }