List of usage examples for java.net BindException getMessage
public String getMessage()
From source file:org.quickserver.net.server.QuickServer.java
public void run() { exceptionInRun = null;/*from w ww . j a v a2 s. c o m*/ TheClient theClient = initTheClient(); try { stopServer = false; closeAllPools(); initAllPools(); makeServerSocket(); if (getServerBanner().length() > 0) { System.out.println(getServerBanner()); //print banner } setServiceState(Service.RUNNING); //v1.2 processServerHooks(ServerHook.POST_STARTUP); //v1.3.3 if (getBlockingMode() == false) { runNonBlocking(theClient); if (stopServer == true) { logger.log(Level.FINEST, "Closing selector for {0}", getName()); selector.close(); } return; } else { runBlocking(theClient); } } catch (BindException e) { exceptionInRun = e; logger.log(Level.SEVERE, "{0} BindException for Port {1} @ {2} : {3}", new Object[] { getName(), getPort(), getBindAddr().getHostAddress(), e.getMessage() }); } catch (javax.net.ssl.SSLException e) { exceptionInRun = e; logger.log(Level.SEVERE, "SSLException {0}", e); logger.log(Level.FINE, "StackTrace:\n{0}", MyString.getStackTrace(e)); } catch (IOException e) { exceptionInRun = e; logger.log(Level.SEVERE, "IOError {0}", e); logger.log(Level.FINE, "StackTrace:\n{0}", MyString.getStackTrace(e)); } catch (Exception e) { exceptionInRun = e; logger.log(Level.SEVERE, "Error {0}", e); logger.log(Level.FINE, "StackTrace:\n{0}", MyString.getStackTrace(e)); } finally { if (getBlockingMode() == true) { logger.log(Level.WARNING, "Closing {0}", getName()); try { if (isClosed() == false) { server.close(); } } catch (Exception e) { throw new RuntimeException(e); } server = null; serverSocketChannel = null; setServiceState(Service.STOPPED); logger.log(Level.WARNING, "Closed {0}", getName()); processServerHooks(ServerHook.POST_SHUTDOWN); } else if (getBlockingMode() == false && exceptionInRun != null) { logger.log(Level.WARNING, "Closing {0} - Had Error: {1}", new Object[] { getName(), exceptionInRun }); try { if (isClosed() == false) { if (serverSocketChannel != null) serverSocketChannel.close(); if (server != null) server.close(); } } catch (Exception e) { throw new RuntimeException(e); } server = null; serverSocketChannel = null; setServiceState(Service.STOPPED); logger.log(Level.WARNING, "Closed {0}", getName()); processServerHooks(ServerHook.POST_SHUTDOWN); } } }
From source file:org.sdm.spa.BrowserUIServer.java
protected void startServer(String context, int port) throws IOException { try {//from w w w.jav a 2 s.com addr = new InetSocketAddress("localhost", port); server = HttpServer.create(addr, 11); server.createContext("/" + context, new BrowserUIHandler()); server.start(); if (isDebugging) log.debug("server " + server.getAddress()); } catch (java.net.BindException e) { if (e.getMessage().equalsIgnoreCase("Address already in use")) System.out.println("the server for BrowserUI is already started. Reuse it..."); } }
From source file:org.unitime.timetable.solver.remote.SolverRegisterService.java
public void run() { iStartTime = new Date(); try {//from w w w. j a v a 2s .c om ConnectionFactory.init(ApplicationProperties.getProperties(), ApplicationProperties.getDataFolder()); try { while (true) { try { iServerSocket = ConnectionFactory.getServerSocketFactory().createServerSocket(Integer .parseInt(ApplicationProperties.getProperty("tmtbl.solver.register.port", "9998"))); sLog.info("Service is running at " + iServerSocket.getInetAddress().getHostName() + ":" + iServerSocket.getLocalPort()); break; } catch (BindException e) { try { sLog.warn("Prior instance of service still running"); Socket socket = ConnectionFactory.getSocketFactory().createSocket("localhost", Integer.parseInt(ApplicationProperties.getProperty("tmtbl.solver.register.port", "9998"))); RemoteIo.writeObject(socket, "quit"); Object answer = RemoteIo.readObject(socket); sLog.warn("quit command sent, answer: " + answer); socket.close(); } catch (Exception f) { sLog.warn("Unable to connect to prior instance", f); } sleep(1000); } } } catch (IOException io) { sLog.error("Unable to start service, reason: " + io.getMessage(), io); return; } while (!iServerSocket.isClosed()) { try { Socket socket = iServerSocket.accept(); socket.setKeepAlive(true); sLog.debug("Client " + socket.getInetAddress() + " connected."); (new Thread(new SolverConnection(socket))).start(); } catch (Exception e) { if (!iServerSocket.isClosed()) sLog.warn("Unable to accept new connection, reason:" + e.getMessage(), e); } } } catch (Exception e) { sLog.error("Unexpected exception occured, reason: " + e.getMessage(), e); } finally { try { if (iServerSocket != null && !iServerSocket.isClosed()) iServerSocket.close(); } catch (Exception e) { sLog.warn("Unable to close socket, reason: " + e.getMessage(), e); } } }
From source file:org.vaadin.addons.sitekit.example.ExampleSiteMain.java
/** * Main method for running DefaultSiteUI. * @param args the commandline arguments * @throws Exception if exception occurs in jetty startup. *//*from w w w. j a v a 2 s. c o m*/ public static void main(final String[] args) throws Exception { // Configure logging. // ------------------ DOMConfigurator.configure("./log4j.xml"); // Configuration loading with HEROKU support. final String environmentDatabaseString = System.getenv("DATABASE_URL"); if (StringUtils.isNotEmpty(environmentDatabaseString)) { final URI dbUri = new URI(environmentDatabaseString); final String dbUser = dbUri.getUserInfo().split(":")[0]; final String dbPassword = dbUri.getUserInfo().split(":")[1]; final String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath(); PropertiesUtil.setProperty(PROPERTIES_CATEGORY, "javax.persistence.jdbc.url", dbUrl); PropertiesUtil.setProperty(PROPERTIES_CATEGORY, "javax.persistence.jdbc.user", dbUser); PropertiesUtil.setProperty(PROPERTIES_CATEGORY, "javax.persistence.jdbc.password", dbPassword); LOGGER.info("Environment variable defined database URL: " + environmentDatabaseString); } final String environmentPortString = System.getenv().get("PORT"); final int port; if (StringUtils.isNotEmpty(environmentPortString)) { port = Integer.parseInt(environmentPortString); LOGGER.info("Environment variable defined HTTP port: " + port); } else { port = Integer.parseInt(PropertiesUtil.getProperty("site", "http-port")); LOGGER.info("Configuration defined HTTP port: " + port); } // Configure Java Persistence API. // ------------------------------- DefaultSiteUI.setEntityManagerFactory( PersistenceUtil.getEntityManagerFactory(PERSISTENCE_UNIT, PROPERTIES_CATEGORY)); // Configure providers. // -------------------- // Configure security provider. DefaultSiteUI.setSecurityProvider(new SecurityProviderSessionImpl("administrator", "user")); // Configure content provider. DefaultSiteUI.setContentProvider(new DefaultContentProvider()); // Configure localization provider. DefaultSiteUI.setLocalizationProvider(new LocalizationProviderBundleImpl(LOCALIZATION_BUNDLE)); // Initialize modules SiteModuleManager.initializeModule(AuditModule.class); SiteModuleManager.initializeModule(ContentModule.class); // Add feedback view and set it default. // ----------------------------------- final SiteDescriptor siteDescriptor = DefaultSiteUI.getContentProvider().getSiteDescriptor(); // Customize navigation tree. final NavigationVersion navigationVersion = siteDescriptor.getNavigation().getProductionVersion(); navigationVersion.setDefaultPageName("feedback"); navigationVersion.addRootPage(0, "feedback"); // Describe feedback view. final ViewDescriptor feedback = new ViewDescriptor("feedback", "Feedback", DefaultView.class); feedback.setViewletClass("content", FeedbackViewlet.class); siteDescriptor.getViewDescriptors().add(feedback); // Describe feedback view fields. final FieldSetDescriptor feedbackFieldSetDescriptor = new FieldSetDescriptor(Feedback.class); feedbackFieldSetDescriptor.setVisibleFieldIds(new String[] { "title", "description", "emailAddress", "firstName", "lastName", "organizationName", "organizationSize" }); FieldSetDescriptorRegister.registerFieldSetDescriptor("feedback", feedbackFieldSetDescriptor); // Configure Embedded jetty. // ------------------------- final boolean developmentEnvironment = ExampleSiteMain.class.getClassLoader().getResource("webapp/") .toExternalForm().startsWith("file:"); final String webappUrl; if (developmentEnvironment) { webappUrl = DefaultSiteUI.class.getClassLoader().getResource("webapp/").toExternalForm() .replace("target/classes", "src/main/resources"); } else { webappUrl = DefaultSiteUI.class.getClassLoader().getResource("webapp/").toExternalForm(); } final Server server = new Server(port); final WebAppContext context = new WebAppContext(); context.setContextPath("/"); context.setDescriptor(webappUrl + "/WEB-INF/web.xml"); context.setResourceBase(webappUrl); context.setParentLoaderPriority(true); if (developmentEnvironment) { context.setInitParameter("cacheControl", "no-cache"); context.setInitParameter("useFileMappedBuffer", "false"); context.setInitParameter("maxCachedFiles", "0"); } server.setHandler(context); try { server.start(); } catch (final BindException e) { LOGGER.warn("Jetty port (" + port + ") binding failed: " + e.getMessage()); return; } server.join(); }
From source file:sitekit.tutorial.TutorialSiteMain.java
/** * Main method for running DefaultSiteUI. * * @param args the commandline arguments * @throws Exception if exception occurs in jetty startup. *//*w ww .j av a2 s . c o m*/ public static void main(final String[] args) throws Exception { // Configure logging. DOMConfigurator.configure("./log4j.xml"); // Configuration loading with HEROKU support. final String environmentDatabaseString = System.getenv("DATABASE_URL"); if (StringUtils.isNotEmpty(environmentDatabaseString)) { final URI dbUri = new URI(environmentDatabaseString); final String dbUser = dbUri.getUserInfo().split(":")[0]; final String dbPassword = dbUri.getUserInfo().split(":")[1]; final String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath(); PropertiesUtil.setProperty(PROPERTIES_CATEGORY, "javax.persistence.jdbc.url", dbUrl); PropertiesUtil.setProperty(PROPERTIES_CATEGORY, "javax.persistence.jdbc.user", dbUser); PropertiesUtil.setProperty(PROPERTIES_CATEGORY, "javax.persistence.jdbc.password", dbPassword); LOGGER.info("Environment variable defined database URL: " + environmentDatabaseString); } final String environmentPortString = System.getenv().get("PORT"); final int port; if (StringUtils.isNotEmpty(environmentPortString)) { port = Integer.parseInt(environmentPortString); LOGGER.info("Environment variable defined HTTP port: " + port); } else { port = Integer.parseInt(PropertiesUtil.getProperty("site", "http-port")); LOGGER.info("Configuration defined HTTP port: " + port); } // Configure Java Persistence API. DefaultSiteUI.setEntityManagerFactory( PersistenceUtil.getEntityManagerFactory(PERSISTENCE_UNIT, PROPERTIES_CATEGORY)); // Configure security provider. DefaultSiteUI.setSecurityProvider(new SecurityProviderSessionImpl("administrator", "user")); // Configure content provider. DefaultSiteUI.setContentProvider(new DefaultContentProvider()); // Configure localization provider. DefaultSiteUI.setLocalizationProvider( new LocalizationProviderBundleImpl(LOCALIZATION_BUNDLE, "custom-localization")); // Get default site descriptor. final SiteDescriptor siteDescriptor = DefaultSiteUI.getContentProvider().getSiteDescriptor(); // Describe custom view. final ViewDescriptor customDescriptor = new ViewDescriptor("custom", "Custom Title", DefaultView.class); customDescriptor.setViewletClass("content", HelloWorldViewlet.class); siteDescriptor.getViewDescriptors().add(customDescriptor); // Add custom view to navigation. final NavigationVersion navigationVersion = siteDescriptor.getNavigation().getProductionVersion(); navigationVersion.setDefaultPageName("custom"); navigationVersion.addRootPage(0, "custom"); // Configure Embedded jetty. // ------------------------- final boolean developmentEnvironment = TutorialSiteMain.class.getClassLoader().getResource("webapp/") .toExternalForm().startsWith("file:"); final String webappUrl; if (developmentEnvironment) { webappUrl = DefaultSiteUI.class.getClassLoader().getResource("webapp/").toExternalForm() .replace("target/classes", "src/main/resources"); } else { webappUrl = DefaultSiteUI.class.getClassLoader().getResource("webapp/").toExternalForm(); } final Server server = new Server(port); final WebAppContext context = new WebAppContext(); context.setContextPath("/"); context.setDescriptor(webappUrl + "/WEB-INF/web.xml"); context.setResourceBase(webappUrl); context.setParentLoaderPriority(true); if (developmentEnvironment) { context.setInitParameter("cacheControl", "no-cache"); context.setInitParameter("useFileMappedBuffer", "false"); context.setInitParameter("maxCachedFiles", "0"); } server.setHandler(context); try { server.start(); } catch (final BindException e) { LOGGER.warn("Jetty port (" + port + ") binding failed: " + e.getMessage()); return; } server.join(); }