/** * Starts the server on the port and address specified in parameters. * * @param port the SMTP port to be opened. * @param bindAddress the address to bind to. null means bind to all. * @throws BindPortException when the port can't be opened. * @throws OutOfRangePortException when port is out of range. * @throws IllegalArgumentException when port is out of range. */ public void startServer(int port, InetAddress bindAddress) throws BindPortException, OutOfRangePortException { LOGGER.debug("Starting server on port {}", port); try { smtpServer.setBindAddress(bindAddress); smtpServer.setPort(port); smtpServer.start(); } catch (RuntimeException exception) { if (exception.getMessage().contains("BindException")) { // Can't open port LOGGER.error("{}. Port {}", exception.getMessage(), port); throw new BindPortException(exception, port); } else if (exception.getMessage().contains("out of range")) { // Port out of range LOGGER.error("Port {} out of range.", port); throw new OutOfRangePortException(exception, port); } else { // Unknown error LOGGER.error("", exception); throw exception; } } }
/** * Switches the text inside the button and calls the PortTextField observer to enable/disable the port field. * * @see PortTextField */ public void toggleButton() { try { UIModel.INSTANCE.toggleButton(); } catch (InvalidHostException ihe) { displayError(String.format(i18n.get("startsrv.err.invalidHost"), ihe.getHost())); } catch (InvalidPortException ipe) { displayError(String.format(i18n.get("startsrv.err.invalidPort"))); } catch (BindPortException bpe) { displayError(String.format(i18n.get("startsrv.err.bound"), bpe.getPort())); } catch (OutOfRangePortException orpe) { displayError(String.format(i18n.get("startsrv.err.range"), orpe.getPort())); } catch (RuntimeException re) { displayError(String.format(i18n.get("startsrv.err.default"), re.getMessage())); } if (UIModel.INSTANCE.isStarted()) { button.setText(i18n.get("startsrv.started")); button.setEnabled(false); } setChanged(); notifyObservers(); }