📄 generate.java
字号:
/* ==================================================================== * The Vovida Software License, Version 1.0 * * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc. For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * *//** * Title: <p> * Description: <p> * Copyright: Copyright (c) <p> * Company: <p> * @author * @version 1.0 */package vocal.ugen;import java.util.Stack;import java.util.Vector;import java.util.Random;import java.util.Date;import java.io.IOException;import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.StringReader;import vocal.comm.VPPTransactionWrapper;import vocal.comm.VPPException;import vocal.comm.VPPTransaction;import vocal.data.XMLUtils;import vocal.data.ContactListGenerator;import vocal.data.CplGenerator;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NodeList;import org.w3c.dom.Node;import org.xml.sax.Attributes;import org.xml.sax.InputSource;import org.xml.sax.XMLReader;import org.xml.sax.helpers.DefaultHandler;import org.apache.xerces.parsers.DOMParser;import org.apache.xerces.parsers.SAXParser;public class Generate{ private static String host = "localhost"; private static int port = 6005; private static VPPTransactionWrapper connection; private static Vector fnabGroups = new Vector(); private static Vector cfaGroups = new Vector(); private static Vector csGroups = new Vector(); private static Vector clblGroups = new Vector(); private static Vector vmGroups = new Vector(); private static Vector callReturnGroups = new Vector(); private static Vector callerIdBlockGroups = new Vector(); private static DOMParser parser = new DOMParser(); private static boolean writeToLocalFile = true; private static boolean generateCplAndCl = true; private static Random random = new Random();// private static CplGenerator gen; private static final String ipaddr = "xxx.xxx.xxx.xxx"; private static final String fnaDestination = "1048"; private static final String cfbDestination = "1048"; private static final String cfaDestination = "1048"; private static final String failureCause = "unknown"; private static final boolean nineHundredBlocked = false; private static final boolean longDistanceBlocked = false; private static BufferedReader userXML = new BufferedReader( new StringReader( "<user><name>1000@vovida.com</name>" + "<password>6f7d5634f65192a3b9c8479cee3b655</password>" + //it's "vovida" "<ipaddr>" + ipaddr + "</ipaddr>" + "<marshalgroup>UserAgentGroup</marshalgroup>" + "<staticRegistration value=\"false\">" + "<terminatingContactList>" + "<contact value=\"UserAgentGroup\"></contact>" + "<contact value=\"xxx.xxx.xxx.xxx:yyyy\"></contact>" + "</terminatingContactList>" + "</staticRegistration>" + "<authenticationType value=\"None\">" + "<authenticationPassword value=\"password\"></authenticationPassword>" + "</authenticationType>" + "<failurecase>" + failureCause + "</failurecase>" + "<cfa enabled=\"false\"><setfeat>OFF</setfeat> " + "<featuregroup>ForwardAllCallsGroup</featuregroup>" + "<forwardto>" + cfaDestination + "</forwardto>" + "</cfa>" + "<fnab enabled=\"false\"><setfeat>OFF</setfeat>" + "<featuregroup>ForwardNoAnswerBusyGroup</featuregroup>" + "<fna set=\"false\">" + "<forwardto>" + fnaDestination +"</forwardto>" + "</fna>" + "<cfb set=\"false\">" + "<forwardto>1048</forwardto>" + "</cfb>" + "</fnab>" + "<cs enabled=\"false\"><setfeat>OFF</setfeat>" + "<featuregroup>CallScreeningGroup</featuregroup>" + "</cs>" + "<clbl enabled=\"false\"><setfeat>OFF</setfeat>" + "<featuregroup>CallBlockingGroup</featuregroup>" + "<nineHundredBlocked adminSet=\"false\" userSet=\"" + nineHundredBlocked + "\"></nineHundredBlocked>" + "<longDistanceBlocked adminSet=\"false\" userSet=\"" + longDistanceBlocked + "\"></longDistanceBlocked>" + "</clbl>"+ "<callReturn enabled=\"false\"><setfeat>OFF</setfeat>" + "<featuregroup>CallReturnGroup</featuregroup>" + "</callReturn>" + "<callerIdBlocking enabled=\"false\"><setfeat>OFF</setfeat>" + "<featuregroup>CallerIdBlockingGroup</featuregroup>" + "</callerIdBlocking>" + "<voicemail enabled =\"false\"><setfeat>OFF</setfeat>" + "<featuregroup>VoiceMailGroup</featuregroup>" + "</voicemail>" + "<aliases></aliases>" + "</user>")); public Generate() { } public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage: Generate host port"); return; } host = args[0]; port = Integer.parseInt(args[1]); try { connection = new VPPTransactionWrapper(host,port);// gen = new CplGenerator(connection); } catch (VPPException e) { VPPTransactionWrapper.showVPPException(e, "Failed to connect to " + host + ":" + port); return; } int numUsr = 1; int startNumber = 1000; int stopNumber = 1005; int digitCount = 4; try { System.out.print("Enter number to start user names at: "); String startAt = new BufferedReader(new InputStreamReader(System.in)).readLine(); System.out.print("Enter number to stop user names at: "); String stopAt = new BufferedReader(new InputStreamReader(System.in)).readLine(); startNumber = Integer.parseInt(startAt); stopNumber = Integer.parseInt(stopAt); numUsr = stopNumber - startNumber; digitCount = stopAt.length(); System.out.print("Write to local file? (y/n) "); String response = new BufferedReader(new InputStreamReader(System.in)).readLine(); if (response.equalsIgnoreCase("y") || response.equalsIgnoreCase("yes")) { writeToLocalFile = true; } else { writeToLocalFile = false; }/** System.out.print("Generate cpl and contact lists? (y/n) "); response = new BufferedReader(new InputStreamReader(System.in)).readLine(); if (response.equalsIgnoreCase("y") || response.equalsIgnoreCase("yes")) { generateCplAndCl = true; } else { generateCplAndCl = false; }**/ } catch (IOException e) { System.out.println("Could not read response because:"); e.printStackTrace(); } //instantiate a parser for the seed user file try { //create a dom tree from the initial user xml string parser.parse(new InputSource(userXML)); } catch (Exception e) { System.out.println("Error parsing seed user xml because:"); e.printStackTrace(); return; } //get the paths where the various cpl files need to be put DOMParser pathParser = new DOMParser(); try { BufferedReader features = connection.request("GET", "SystemConfiguration", "ListOfFeatureServers"); pathParser.parse(new InputSource(features)); } catch (Exception e) { System.out.println("Could not find cpl paths because:"); e.printStackTrace(); return; } //read the feature groups from the server getGroups(); Random random = new Random(); long startTime = System.currentTimeMillis(); System.out.println("Start time = " + new Date(startTime)); for (int i=startNumber; i<startNumber+numUsr; i++) { String userName = new Integer(i).toString(); //want user name to be 4 digit number. If it is shorter than that, pad //left with 0s up to 4 digits. int count = userName.length(); for (int j=0; j<digitCount-count; j++) { userName = "0"+userName; } userName = userName + "@vocal.com"; //modify the xml Document doc = generateUser(userName); //save the new xml file String theXML = new XMLUtils().buildXMLString(doc); //convert the dom to an xml string if (writeToLocalFile) { try { connection.doPut("Accounts", userName, theXML, VPPTransaction.WRITE_TO_FILE); } catch(VPPException e) { VPPTransactionWrapper.showVPPException(e, "Failed to write " + userName + " account to file"); } } else { try { connection.doPut("Accounts", userName, theXML); } catch(VPPException e) { VPPTransactionWrapper.showVPPException(e, "Failed to write " + userName + " account to file");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -