List of usage examples for java.io FileNotFoundException printStackTrace
public void printStackTrace()
From source file:examples.nntp.PostMessage.java
public static void main(String[] args) { String from, subject, newsgroup, filename, server, organization; String references;//ww w.j av a2 s .c o m BufferedReader stdin; FileReader fileReader = null; SimpleNNTPHeader header; NNTPClient client; if (args.length < 1) { System.err.println("Usage: post newsserver"); System.exit(1); } server = args[0]; stdin = new BufferedReader(new InputStreamReader(System.in)); try { System.out.print("From: "); System.out.flush(); from = stdin.readLine(); System.out.print("Subject: "); System.out.flush(); subject = stdin.readLine(); header = new SimpleNNTPHeader(from, subject); System.out.print("Newsgroup: "); System.out.flush(); newsgroup = stdin.readLine(); header.addNewsgroup(newsgroup); while (true) { System.out.print("Additional Newsgroup <Hit enter to end>: "); System.out.flush(); // Of course you don't want to do this because readLine() may be null newsgroup = stdin.readLine().trim(); if (newsgroup.length() == 0) { break; } header.addNewsgroup(newsgroup); } System.out.print("Organization: "); System.out.flush(); organization = stdin.readLine(); System.out.print("References: "); System.out.flush(); references = stdin.readLine(); if (organization != null && organization.length() > 0) { header.addHeaderField("Organization", organization); } if (references != null && references.length() > 0) { header.addHeaderField("References", references); } header.addHeaderField("X-Newsreader", "NetComponents"); System.out.print("Filename: "); System.out.flush(); filename = stdin.readLine(); try { fileReader = new FileReader(filename); } catch (FileNotFoundException e) { System.err.println("File not found. " + e.getMessage()); System.exit(1); } client = new NNTPClient(); client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true)); client.connect(server); if (!NNTPReply.isPositiveCompletion(client.getReplyCode())) { client.disconnect(); System.err.println("NNTP server refused connection."); System.exit(1); } if (client.isAllowedToPost()) { Writer writer = client.postArticle(); if (writer != null) { writer.write(header.toString()); Util.copyReader(fileReader, writer); writer.close(); client.completePendingCommand(); } } if (fileReader != null) { fileReader.close(); } client.logout(); client.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } }
From source file:de.tudarmstadt.ukp.dariah.pipeline.RunPipeline.java
public static void main(String[] args) { Date startDate = new Date(); PrintStream ps;//from w w w . ja v a 2 s . co m try { ps = new PrintStream("error.log"); System.setErr(ps); } catch (FileNotFoundException e) { System.out.println("Errors cannot be redirected"); } try { if (!parseArgs(args)) { System.out.println("Usage: java -jar pipeline.jar -help"); System.out.println("Usage: java -jar pipeline.jar -input <Input File> -output <Output Folder>"); System.out.println( "Usage: java -jar pipeline.jar -config <Config File> -input <Input File> -output <Output Folder>"); return; } } catch (ParseException e) { e.printStackTrace(); System.out.println( "Error when parsing command line arguments. Use\njava -jar pipeline.jar -help\n to get further information"); System.out.println("See error.log for further details"); return; } LinkedList<String> configFiles = new LinkedList<>(); String configFolder = "configs/"; configFiles.add(configFolder + "default.properties"); //Language dependent properties file String path = configFolder + "default_" + optLanguage + ".properties"; File f = new File(path); if (f.exists()) { configFiles.add(path); } else { System.out.println("Language config file: " + path + " not found"); } String[] configFileArg = new String[0]; for (int i = 0; i < args.length - 1; i++) { if (args[i].equals("-config")) { configFileArg = args[i + 1].split("[,;]"); break; } } for (String configFile : configFileArg) { f = new File(configFile); if (f.exists()) { configFiles.add(configFile); } else { //Check in configs folder path = configFolder + configFile; f = new File(path); if (f.exists()) { configFiles.add(path); } else { System.out.println("Config file: " + configFile + " not found"); return; } } } for (String configFile : configFiles) { try { parseConfig(configFile); } catch (Exception e) { e.printStackTrace(); System.out.println("Exception when parsing config file: " + configFile); System.out.println("See error.log for further details"); } } printConfiguration(configFiles.toArray(new String[0])); try { // Read in the input files String defaultFileExtension = (optReader == ReaderType.XML) ? ".xml" : ".txt"; GlobalFileStorage.getInstance().readFilePaths(optInput, defaultFileExtension, optOutput, optResume); System.out.println("Process " + GlobalFileStorage.getInstance().size() + " files"); CollectionReaderDescription reader; if (optReader == ReaderType.XML) { reader = createReaderDescription(XmlReader.class, XmlReader.PARAM_LANGUAGE, optLanguage); } else { reader = createReaderDescription(TextReaderWithInfo.class, TextReaderWithInfo.PARAM_LANGUAGE, optLanguage); } AnalysisEngineDescription paragraph = createEngineDescription(ParagraphSplitter.class, ParagraphSplitter.PARAM_SPLIT_PATTERN, (optParagraphSingleLineBreak) ? ParagraphSplitter.SINGLE_LINE_BREAKS_PATTERN : ParagraphSplitter.DOUBLE_LINE_BREAKS_PATTERN); AnalysisEngineDescription seg = createEngineDescription(optSegmenterCls, optSegmenterArguments); AnalysisEngineDescription paragraphSentenceCorrector = createEngineDescription( ParagraphSentenceCorrector.class); AnalysisEngineDescription frenchQuotesSeg = createEngineDescription(PatternBasedTokenSegmenter.class, PatternBasedTokenSegmenter.PARAM_PATTERNS, "+|[]"); AnalysisEngineDescription quotesSeg = createEngineDescription(PatternBasedTokenSegmenter.class, PatternBasedTokenSegmenter.PARAM_PATTERNS, "+|[\"\"]"); AnalysisEngineDescription posTagger = createEngineDescription(optPOSTaggerCls, optPOSTaggerArguments); AnalysisEngineDescription lemma = createEngineDescription(optLemmatizerCls, optLemmatizerArguments); AnalysisEngineDescription chunker = createEngineDescription(optChunkerCls, optChunkerArguments); AnalysisEngineDescription morph = createEngineDescription(optMorphTaggerCls, optMorphTaggerArguments); AnalysisEngineDescription hyphenation = createEngineDescription(optHyphenationCls, optHyphenationArguments); AnalysisEngineDescription depParser = createEngineDescription(optDependencyParserCls, optDependencyParserArguments); AnalysisEngineDescription constituencyParser = createEngineDescription(optConstituencyParserCls, optConstituencyParserArguments); AnalysisEngineDescription ner = createEngineDescription(optNERCls, optNERArguments); AnalysisEngineDescription directSpeech = createEngineDescription(DirectSpeechAnnotator.class, DirectSpeechAnnotator.PARAM_START_QUOTE, optStartQuote); AnalysisEngineDescription srl = createEngineDescription(optSRLCls, optSRLArguments); //Requires DKPro 1.8.0 AnalysisEngineDescription coref = createEngineDescription(optCorefCls, optCorefArguments); //StanfordCoreferenceResolver.PARAM_POSTPROCESSING, true AnalysisEngineDescription writer = createEngineDescription(DARIAHWriter.class, DARIAHWriter.PARAM_TARGET_LOCATION, optOutput, DARIAHWriter.PARAM_OVERWRITE, true); AnalysisEngineDescription annWriter = createEngineDescription(AnnotationWriter.class); AnalysisEngineDescription noOp = createEngineDescription(NoOpAnnotator.class); System.out.println("\nStart running the pipeline (this may take a while)..."); while (!GlobalFileStorage.getInstance().isEmpty()) { try { SimplePipeline.runPipeline(reader, paragraph, (optSegmenter) ? seg : noOp, paragraphSentenceCorrector, frenchQuotesSeg, quotesSeg, (optPOSTagger) ? posTagger : noOp, (optLemmatizer) ? lemma : noOp, (optChunker) ? chunker : noOp, (optMorphTagger) ? morph : noOp, (optHyphenation) ? hyphenation : noOp, directSpeech, (optDependencyParser) ? depParser : noOp, (optConstituencyParser) ? constituencyParser : noOp, (optNER) ? ner : noOp, (optSRL) ? srl : noOp, //Requires DKPro 1.8.0 (optCoref) ? coref : noOp, writer // ,annWriter ); } catch (OutOfMemoryError e) { System.out.println("Out of Memory at file: " + GlobalFileStorage.getInstance().getLastPolledFile().getAbsolutePath()); } } Date enddate = new Date(); double duration = (enddate.getTime() - startDate.getTime()) / (1000 * 60.0); System.out.println("---- DONE -----"); System.out.printf("All files processed in %.2f minutes", duration); } catch (ResourceInitializationException e) { System.out.println("Error when initializing the pipeline."); if (e.getCause() instanceof FileNotFoundException) { System.out.println("File not found. Maybe the input / output path is incorrect?"); System.out.println(e.getCause().getMessage()); } e.printStackTrace(); System.out.println("See error.log for further details"); } catch (UIMAException e) { e.printStackTrace(); System.out.println("Error in the pipeline."); System.out.println("See error.log for further details"); } catch (IOException e) { e.printStackTrace(); System.out .println("Error while reading or writing to the file system. Maybe some paths are incorrect?"); System.out.println("See error.log for further details"); } }
From source file:examples.mail.java
public final static void main(String[] args) { String sender, recipient, subject, filename, server, cc; Vector ccList = new Vector(); BufferedReader stdin;/*ww w . j av a 2s. c o m*/ FileReader fileReader = null; Writer writer; SimpleSMTPHeader header; SMTPClient client; Enumeration en; if (args.length < 1) { System.err.println("Usage: mail smtpserver"); System.exit(1); } server = args[0]; stdin = new BufferedReader(new InputStreamReader(System.in)); try { System.out.print("From: "); System.out.flush(); sender = stdin.readLine(); System.out.print("To: "); System.out.flush(); recipient = stdin.readLine(); System.out.print("Subject: "); System.out.flush(); subject = stdin.readLine(); header = new SimpleSMTPHeader(sender, recipient, subject); while (true) { System.out.print("CC <enter one address per line, hit enter to end>: "); System.out.flush(); // Of course you don't want to do this because readLine() may be null cc = stdin.readLine().trim(); if (cc.length() == 0) break; header.addCC(cc); ccList.addElement(cc); } System.out.print("Filename: "); System.out.flush(); filename = stdin.readLine(); try { fileReader = new FileReader(filename); } catch (FileNotFoundException e) { System.err.println("File not found. " + e.getMessage()); } client = new SMTPClient(); client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); client.connect(server); if (!SMTPReply.isPositiveCompletion(client.getReplyCode())) { client.disconnect(); System.err.println("SMTP server refused connection."); System.exit(1); } client.login(); client.setSender(sender); client.addRecipient(recipient); en = ccList.elements(); while (en.hasMoreElements()) client.addRecipient((String) en.nextElement()); writer = client.sendMessageData(); if (writer != null) { writer.write(header.toString()); Util.copyReader(fileReader, writer); writer.close(); client.completePendingCommand(); } fileReader.close(); client.logout(); client.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } }
From source file:com.xiangzhurui.util.email.SMTPMail.java
public static void main(String[] args) { String sender, recipient, subject, filename, server, cc; List<String> ccList = new ArrayList<String>(); BufferedReader stdin;//from w w w . j a v a2s .co m FileReader fileReader = null; Writer writer; SimpleSMTPHeader header; SMTPClient client; if (args.length < 1) { System.err.println("Usage: mail smtpserver"); System.exit(1); } server = args[0]; stdin = new BufferedReader(new InputStreamReader(System.in)); try { System.out.print("From: "); System.out.flush(); sender = stdin.readLine(); System.out.print("To: "); System.out.flush(); recipient = stdin.readLine(); System.out.print("Subject: "); System.out.flush(); subject = stdin.readLine(); header = new SimpleSMTPHeader(sender, recipient, subject); while (true) { System.out.print("CC <enter one address per line, hit enter to end>: "); System.out.flush(); cc = stdin.readLine(); if (cc == null || cc.length() == 0) { break; } header.addCC(cc.trim()); ccList.add(cc.trim()); } System.out.print("Filename: "); System.out.flush(); filename = stdin.readLine(); try { fileReader = new FileReader(filename); } catch (FileNotFoundException e) { System.err.println("File not found. " + e.getMessage()); } client = new SMTPClient(); client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true)); client.connect(server); if (!SMTPReply.isPositiveCompletion(client.getReplyCode())) { client.disconnect(); System.err.println("SMTP server refused connection."); System.exit(1); } client.login(); client.setSender(sender); client.addRecipient(recipient); for (String recpt : ccList) { client.addRecipient(recpt); } writer = client.sendMessageData(); if (writer != null) { writer.write(header.toString()); Util.copyReader(fileReader, writer); writer.close(); client.completePendingCommand(); } if (fileReader != null) { fileReader.close(); } client.logout(); client.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } }
From source file:edu.hawaii.soest.kilonalu.dvp2.DavisWxParser.java
public static void main(String[] args) { // Ensure we have a path to the binary file if (args.length != 1) { logger.info("Please provide the path to a file containing a binary LOOP packet."); System.exit(1);//from w w w . j a v a2 s . c om } else { try { // open and read the file File packetFile = new File(args[0]); FileInputStream fis = new FileInputStream(packetFile); FileChannel fileChannel = fis.getChannel(); ByteBuffer inBuffer = ByteBuffer.allocateDirect(8192); ByteBuffer packetBuffer = ByteBuffer.allocateDirect(8192); while (fileChannel.read(inBuffer) != -1 || inBuffer.position() > 0) { inBuffer.flip(); packetBuffer.put(inBuffer.get()); inBuffer.compact(); } fileChannel.close(); fis.close(); packetBuffer.put(inBuffer.get()); // create an instance of the parser, and report the field contents after parsing DavisWxParser davisWxParser = new DavisWxParser(packetBuffer); // Set up a simple logger that logs to the console PropertyConfigurator.configure(davisWxParser.getLogConfigurationFile()); logger.info("loopID: " + davisWxParser.getLoopID()); logger.info("barTrend: " + davisWxParser.getBarTrend()); logger.info("barTrendAsString: " + davisWxParser.getBarTrendAsString()); logger.info("packetType: " + davisWxParser.getPacketType()); logger.info("nextRecord: " + davisWxParser.getNextRecord()); logger.info("barometer: " + davisWxParser.getBarometer()); logger.info("insideTemperature: " + davisWxParser.getInsideTemperature()); logger.info("insideHumidity: " + davisWxParser.getInsideHumidity()); logger.info("outsideTemperature: " + davisWxParser.getOutsideTemperature()); logger.info("windSpeed: " + davisWxParser.getWindSpeed()); logger.info("tenMinuteAverageWindSpeed: " + davisWxParser.getTenMinuteAverageWindSpeed()); logger.info("windDirection: " + davisWxParser.getWindDirection()); logger.info( "extraTemperatures: " + Arrays.toString(davisWxParser.getExtraTemperatures())); logger.info( "soilTemperatures: " + Arrays.toString(davisWxParser.getSoilTemperatures())); logger.info( "leafTemperatures: " + Arrays.toString(davisWxParser.getLeafTemperatures())); logger.info("outsideHumidity: " + davisWxParser.getOutsideHumidity()); logger.info( "extraHumidities: " + Arrays.toString(davisWxParser.getExtraHumidities())); logger.info("rainRate: " + davisWxParser.getRainRate()); logger.info("uvRadiation: " + davisWxParser.getUvRadiation()); logger.info("solarRadiation: " + davisWxParser.getSolarRadiation()); logger.info("stormRain: " + davisWxParser.getStormRain()); logger.info("currentStormStartDate: " + davisWxParser.getCurrentStormStartDate()); logger.info("dailyRain: " + davisWxParser.getDailyRain()); logger.info("monthlyRain: " + davisWxParser.getMonthlyRain()); logger.info("yearlyRain: " + davisWxParser.getYearlyRain()); logger.info("dailyEvapoTranspiration: " + davisWxParser.getDailyEvapoTranspiration()); logger.info("monthlyEvapoTranspiration: " + davisWxParser.getMonthlyEvapoTranspiration()); logger.info("yearlyEvapoTranspiration: " + davisWxParser.getYearlyEvapoTranspiration()); logger.info("soilMoistures: " + Arrays.toString(davisWxParser.getSoilMoistures())); logger.info("leafWetnesses: " + Arrays.toString(davisWxParser.getLeafWetnesses())); logger.info("insideAlarm: " + davisWxParser.getInsideAlarm()); logger.info("rainAlarm: " + davisWxParser.getRainAlarm()); logger.info("outsideAlarms: " + davisWxParser.getOutsideAlarms()); logger.info("extraTemperatureHumidityAlarms: " + davisWxParser.getExtraTemperatureHumidityAlarms()); logger.info("soilLeafAlarms: " + davisWxParser.getSoilLeafAlarms()); logger.info("transmitterBatteryStatus: " + davisWxParser.getTransmitterBatteryStatus()); logger.info("consoleBatteryVoltage: " + davisWxParser.getConsoleBatteryVoltage()); logger.info("forecastIconValues: " + davisWxParser.getForecastAsString()); logger.info("forecastRuleNumber: " + davisWxParser.getForecastRuleNumberAsString()); logger.info("timeOfSunrise: " + davisWxParser.getTimeOfSunrise()); logger.info("timeOfSunset: " + davisWxParser.getTimeOfSunset()); logger.info("recordDelimiter: " + davisWxParser.getRecordDelimiterAsHexString()); logger.info("crcChecksum: " + davisWxParser.getCrcChecksum()); } catch (java.io.FileNotFoundException fnfe) { fnfe.printStackTrace(); } catch (java.io.IOException ioe) { ioe.printStackTrace(); } } }
From source file:net.jradius.server.Main.java
public static void main(String[] args) { if (args.length != 1) { showUsage();/* ww w . j a v a 2 s . co m*/ System.exit(1); } /** * CADBiS daemon run * ---> */ if (JRadiusConfigurator.getInstance().getProperty("cadbis_daemon").equals("enabled")) CADBiS.getInstance().start(); /** * <--- eof CADBiS */ String configFilePath = args[0]; try { File file = new File(configFilePath); Configuration.initialize(file); JRadiusServer server = new JRadiusServer(); server.start(); } catch (FileNotFoundException e) { System.err.println("Error: The configuration file '" + configFilePath + "' does not exist."); } catch (ConfigurationException e1) { System.err.println("Error: The configuration file could not be read," + " because the file contains an error: " + e1.getMessage()); showStackTrace(e1); } catch (SecurityException e2) { System.err.println("Error: The configuration file could not be read," + " because a security error occurred: " + e2.getMessage()); showStackTrace(e2); } catch (IllegalArgumentException e3) { System.err.println("Error: The configuration file could not be read," + " because an illegal argument error occurred: " + e3.getMessage()); showStackTrace(e3); } catch (ClassNotFoundException e4) { System.err.println("Error: The configuration file could not be read," + " because a class specified in the configuration file could not be found: " + e4.getMessage()); showStackTrace(e4); } catch (NoSuchMethodException e5) { System.err.println("Error: The configuration file could not be read," + " because a method does not exist in a class specified in the configuration file: " + e5.getMessage()); showStackTrace(e5); } catch (InstantiationException e6) { System.err.println("Error: The configuration file could not be read," + " because an object specified in the configuration file could not be instantiated: " + e6.getMessage()); showStackTrace(e6); } catch (IllegalAccessException e7) { System.err.println("Error: The configuration file could not be read," + " because an illegal access error occurred: " + e7.getMessage()); showStackTrace(e7); } catch (InvocationTargetException e8) { System.err.println("Error: The configuration file could not be read," + " because an invocation target exception was thrown: " + e8.getMessage()); showStackTrace(e8); } catch (Exception e) { e.printStackTrace(); } return; }
From source file:com.web.server.WebServer.java
/** * This is the start of the all the services in web server * @param args/*from ww w . j a v a 2 s . c o m*/ * @throws IOException * @throws SAXException */ public static void main(String[] args) throws IOException, SAXException { Hashtable urlClassLoaderMap = new Hashtable(); Hashtable executorServicesMap = new Hashtable(); Hashtable ataMap = new Hashtable<String, ATAConfig>(); Hashtable messagingClassMap = new Hashtable(); ConcurrentHashMap servletMapping = new ConcurrentHashMap(); DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() { protected void loadRules() { // TODO Auto-generated method stub try { loadXMLRules(new InputSource(new FileInputStream("./config/serverconfig-rules.xml"))); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); Digester serverdigester = serverdigesterLoader.newDigester(); final ServerConfig serverconfig = (ServerConfig) serverdigester .parse(new InputSource(new FileInputStream("./config/serverconfig.xml"))); DigesterLoader messagingdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() { protected void loadRules() { // TODO Auto-generated method stub try { loadXMLRules(new InputSource(new FileInputStream("./config/messagingconfig-rules.xml"))); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); Digester messagingdigester = messagingdigesterLoader.newDigester(); MessagingElem messagingconfig = (MessagingElem) messagingdigester .parse(new InputSource(new FileInputStream("./config/messaging.xml"))); //System.out.println(messagingconfig); ////System.out.println(serverconfig.getDeploydirectory()); PropertyConfigurator.configure("log4j.properties"); /*MemcachedClient cache=new MemcachedClient( new InetSocketAddress("localhost", 1000));*/ // Store a value (async) for one hour //c.set("someKey", 36, new String("arun")); // Retrieve a value. System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); ExecutorService executor = java.util.concurrent.Executors.newCachedThreadPool(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName name = null; try { name = new ObjectName("com.web.server:type=WarDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } WarDeployer warDeployer = new WarDeployer(serverconfig.getDeploydirectory(), serverconfig.getFarmWarDir(), serverconfig.getClustergroup(), urlClassLoaderMap, executorServicesMap, messagingClassMap, servletMapping, messagingconfig, sessionObjects); warDeployer.setPriority(MIN_PRIORITY); try { mbs.registerMBean(warDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //warDeployer.start(); executor.execute(warDeployer); ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); serverSocketChannel.bind(new InetSocketAddress("0.0.0.0", Integer.parseInt(serverconfig.getPort()))); serverSocketChannel.configureBlocking(false); final byte[] shutdownBt = new byte[50]; WebServerRequestProcessor webserverRequestProcessor = new WebServer().new WebServerRequestProcessor( servletMapping, urlClassLoaderMap, serverSocketChannel, serverconfig.getDeploydirectory(), Integer.parseInt(serverconfig.getShutdownport()), 1); webserverRequestProcessor.setPriority(MIN_PRIORITY); try { name = new ObjectName("com.web.server:type=WebServerRequestProcessor"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverRequestProcessor, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //webserverRequestProcessor.start(); executor.execute(webserverRequestProcessor); for (int i = 0; i < 10; i++) { WebServerRequestProcessor webserverRequestProcessor1 = new WebServer().new WebServerRequestProcessor( servletMapping, urlClassLoaderMap, serverSocketChannel, serverconfig.getDeploydirectory(), Integer.parseInt(serverconfig.getShutdownport()), 2); webserverRequestProcessor1.setPriority(MIN_PRIORITY); try { name = new ObjectName("com.web.server:type=WebServerRequestProcessor" + (i + 1)); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverRequestProcessor1, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(webserverRequestProcessor1); } ServerSocketChannel serverSocketChannelServices = ServerSocketChannel.open(); serverSocketChannelServices .bind(new InetSocketAddress("0.0.0.0", Integer.parseInt(serverconfig.getServicesport()))); serverSocketChannelServices.configureBlocking(false); ExecutorServiceThread executorService = new ExecutorServiceThread(serverSocketChannelServices, executorServicesMap, Integer.parseInt(serverconfig.getShutdownport()), ataMap, urlClassLoaderMap, serverconfig.getDeploydirectory(), serverconfig.getServicesdirectory(), serverconfig.getEarservicesdirectory(), serverconfig.getNodesport()); try { name = new ObjectName("com.web.services:type=ExecutorServiceThread"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(executorService, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //executorService.start(); executor.execute(executorService); for (int i = 0; i < 10; i++) { ExecutorServiceThread executorService1 = new ExecutorServiceThread(serverSocketChannelServices, executorServicesMap, Integer.parseInt(serverconfig.getShutdownport()), ataMap, urlClassLoaderMap, serverconfig.getDeploydirectory(), serverconfig.getServicesdirectory(), serverconfig.getEarservicesdirectory(), serverconfig.getNodesport()); try { name = new ObjectName("com.web.services:type=ExecutorServiceThread" + (i + 1)); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(executorService1, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(executorService1); } WebServerHttpsRequestProcessor webserverHttpsRequestProcessor = new WebServer().new WebServerHttpsRequestProcessor( servletMapping, urlClassLoaderMap, Integer.parseInt(serverconfig.getHttpsport()), serverconfig.getDeploydirectory(), Integer.parseInt(serverconfig.getShutdownport()), serverconfig.getHttpscertificatepath(), serverconfig.getHttpscertificatepasscode(), 1); try { name = new ObjectName("com.web.server:type=WebServerHttpsRequestProcessor"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverHttpsRequestProcessor, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } webserverHttpsRequestProcessor.setPriority(MAX_PRIORITY); //webserverRequestProcessor.start(); executor.execute(webserverHttpsRequestProcessor); /* for(int i=0;i<2;i++){ webserverHttpsRequestProcessor=new WebServer().new WebServerHttpsRequestProcessor(urlClassLoaderMap,Integer.parseInt(serverconfig.getHttpsport())+(i+1),serverconfig.getDeploydirectory(),Integer.parseInt(serverconfig.getShutdownport()),serverconfig.getHttpscertificatepath(),serverconfig.getHttpscertificatepasscode(),1); try { name = new ObjectName("com.web.server:type=WebServerHttpsRequestProcessor"+(i+1)); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverHttpsRequestProcessor, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(webserverHttpsRequestProcessor); }*/ /*ATAServer ataServer=new ATAServer(serverconfig.getAtaaddress(),serverconfig.getAtaport(),ataMap); try { name = new ObjectName("com.web.services:type=ATAServer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(ataServer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ataServer.start();*/ /*ATAConfigClient ataClient=new ATAConfigClient(serverconfig.getAtaaddress(),serverconfig.getAtaport(),serverconfig.getServicesport(),executorServicesMap); try { name = new ObjectName("com.web.services:type=ATAConfigClient"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(ataClient, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ataClient.start();*/ MessagingServer messageServer = new MessagingServer(serverconfig.getMessageport(), messagingClassMap); try { name = new ObjectName("com.web.messaging:type=MessagingServer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(messageServer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //messageServer.start(); executor.execute(messageServer); RandomQueueMessagePicker randomqueuemessagepicker = new RandomQueueMessagePicker(messagingClassMap); try { name = new ObjectName("com.web.messaging:type=RandomQueueMessagePicker"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(randomqueuemessagepicker, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //randomqueuemessagepicker.start(); executor.execute(randomqueuemessagepicker); RoundRobinQueueMessagePicker roundrobinqueuemessagepicker = new RoundRobinQueueMessagePicker( messagingClassMap); try { name = new ObjectName("com.web.messaging:type=RoundRobinQueueMessagePicker"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(roundrobinqueuemessagepicker, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //roundrobinqueuemessagepicker.start(); executor.execute(roundrobinqueuemessagepicker); TopicMessagePicker topicpicker = new TopicMessagePicker(messagingClassMap); try { name = new ObjectName("com.web.messaging:type=TopicMessagePicker"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(topicpicker, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //topicpicker.start(); executor.execute(topicpicker); try { name = new ObjectName("com.web.server:type=SARDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } SARDeployer sarDeployer = SARDeployer.newInstance(serverconfig.getDeploydirectory()); try { mbs.registerMBean(sarDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(sarDeployer); /*try { mbs.invoke(name, "startDeployer", null, null); } catch (InstanceNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ReflectionException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (MBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } */ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); System.setProperty(Context.PROVIDER_URL, "rmi://localhost:" + serverconfig.getServicesregistryport()); ; Registry registry = LocateRegistry.createRegistry(Integer.parseInt(serverconfig.getServicesregistryport())); /*JarDeployer jarDeployer=new JarDeployer(registry,serverconfig.getServicesdirectory(), serverconfig.getServiceslibdirectory(),serverconfig.getCachedir(),executorServicesMap, urlClassLoaderMap); try { name = new ObjectName("com.web.server:type=JarDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(jarDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //jarDeployer.start(); executor.execute(jarDeployer);*/ EARDeployer earDeployer = new EARDeployer(registry, serverconfig.getEarservicesdirectory(), serverconfig.getDeploydirectory(), executorServicesMap, urlClassLoaderMap, serverconfig.getCachedir(), warDeployer); try { name = new ObjectName("com.web.server:type=EARDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(earDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //earDeployer.start(); executor.execute(earDeployer); JVMConsole jvmConsole = new JVMConsole(Integer.parseInt(serverconfig.getJvmConsolePort())); try { name = new ObjectName("com.web.server:type=JVMConsole"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(jvmConsole, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(jvmConsole); ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); XMLDeploymentScanner xmlDeploymentScanner = new XMLDeploymentScanner(serverconfig.getDeploydirectory(), serverconfig.getServiceslibdirectory()); exec.scheduleAtFixedRate(xmlDeploymentScanner, 0, 1000, TimeUnit.MILLISECONDS); EmbeddedJMS embeddedJMS = null; try { embeddedJMS = new EmbeddedJMS(); embeddedJMS.start(); } catch (Exception ex) { // TODO Auto-generated catch block ex.printStackTrace(); } EJBDeployer ejbDeployer = new EJBDeployer(serverconfig.getServicesdirectory(), registry, Integer.parseInt(serverconfig.getServicesregistryport()), embeddedJMS); try { name = new ObjectName("com.web.server:type=EJBDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(ejbDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //jarDeployer.start(); executor.execute(ejbDeployer); new Thread() { public void run() { try { ServerSocket serverSocket = new ServerSocket(Integer.parseInt(serverconfig.getShutdownport())); while (true) { Socket sock = serverSocket.accept(); InputStream istream = sock.getInputStream(); istream.read(shutdownBt); String shutdownStr = new String(shutdownBt); String[] shutdownToken = shutdownStr.split("\r\n\r\n"); //System.out.println(shutdownStr); if (shutdownToken[0].startsWith("shutdown WebServer")) { synchronized (shutDownObject) { shutDownObject.notifyAll(); } } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.start(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { System.out.println("IN shutdown Hook"); synchronized (shutDownObject) { shutDownObject.notifyAll(); } } })); try { synchronized (shutDownObject) { shutDownObject.wait(); } executor.shutdownNow(); serverSocketChannel.close(); serverSocketChannelServices.close(); embeddedJMS.stop(); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println("IN shutdown Hook1"); /*try{ Thread.sleep(10000); } catch(Exception ex){ }*/ //webserverRequestProcessor.stop(); //webserverRequestProcessor1.stop(); /*warDeployer.stop(); executorService.stop(); //ataServer.stop(); //ataClient.stop(); messageServer.stop(); randomqueuemessagepicker.stop(); roundrobinqueuemessagepicker.stop(); topicpicker.stop();*/ /*try { mbs.invoke(new ObjectName("com.web.server:type=SARDeployer"), "destroyDeployer", null, null); } catch (InstanceNotFoundException | MalformedObjectNameException | ReflectionException | MBeanException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ //earDeployer.stop(); System.exit(0); }
From source file:fi.hoski.remote.ui.Admin.java
/** * @param args the command line arguments *//* ww w.ja va2 s. c om*/ public static void main(String[] args) { try { Properties properties = new Properties(); if (args.length != 0) { try (InputStream pFile = new FileInputStream(args[0])) { properties.load(pFile); } catch (FileNotFoundException ex) { } } ServerProperties sp = new ServerProperties(properties); DataObjectDialog<ServerProperties> dod = new DataObjectDialog<>(null, sp.getModel().hide( ServerProperties.Tables, ServerProperties.SupportsZonerSMS, ServerProperties.SuperUser), sp); if (dod.edit()) { String[] server = sp.getServer().split(","); RemoteAppEngine.init(server[0], sp.getUsername(), sp.getPassword()); DataStoreProxy dsp = new DataStoreProxy(properties); dsp.start(); Admin r = new Admin(sp); } else { System.exit(0); } } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.getMessage()); } }
From source file:Main.java
public static PrintStream getErrorLoggerPrintStream() { try {/*from w w w . j a va2 s . c o m*/ PrintStream s = new PrintStream(new FileOutputStream(new File("c:\\log.txt"), true)); return s; } catch (FileNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static InputStream getFileInputStream(String path) { File file = new File(path); try {/* www .ja va 2 s . c om*/ return new FileInputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } }