/** * Bind listener by closing and opening the listener. * @param listener * @throws Exception */ private static void bindListener(ServerConnector listener) throws Exception { // jetty has a bug where you can't reopen a listener that previously // failed to open w/o issuing a close first, even if the port is changed listener.close(); listener.open(); LOG.info("Jetty bound to port " + listener.getLocalPort()); }
mServerConnector.open(); } catch (IOException e) { throw new RuntimeException(e);
listener.open(); LOG.info("Jetty bound to port " + listener.getLocalPort()); break;
private static ServerConnector createServerConnector( ServerSocketChannel channel, Server server, Executor executor, int acceptors, int selectors, ConnectionFactory... factories) throws IOException { ServerConnector connector = new ServerConnector(server, executor, null, null, acceptors, selectors, factories); connector.open(channel); return connector; } }
private static ServerConnector createServerConnector( ServerSocketChannel channel, Server server, Executor executor, int acceptors, int selectors, ConnectionFactory... factories) throws IOException { ServerConnector connector = new ServerConnector(server, executor, null, null, acceptors, selectors, factories); connector.open(channel); return connector; } }
public void start() throws Exception { // Trying to keep all the signatures compatible so this is not super pretty, but it works connector.open(); // Hack to allow successfull test via maven CLI // Read http://stackoverflow.com/questions/2151075/cannot-load-jstl-taglib-within-embedded-jetty-server System.out.println(">>>>>> " + System.getProperty("maven.repo.local")); ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); File taglibsJarFile = new File(System.getProperty("user.home") + "/.m2/repository/taglibs/standard/1.1.2/standard-1.1.2.jar"); if (! taglibsJarFile.exists()) { taglibsJarFile = new File(System.getProperty("maven.repo.local") + "/taglibs/standard/1.1.2/standard-1.1.2.jar"); if (! taglibsJarFile.exists()) { throw new RuntimeException("Taglib Jar file does not exist at path: " + taglibsJarFile.getAbsolutePath()); } } URL taglibsJarUrl = taglibsJarFile.toURI().toURL(); URLClassLoader newClassLoader = new URLClassLoader(new URL[]{taglibsJarUrl}, currentClassLoader); Thread.currentThread().setContextClassLoader(newClassLoader); server.start(); // // When the server starts if the port is specified at 0, then it will find a free port. Once that // happens we'll store it so that client code can rely on a valid and free port number. // PORT = getListeningPort(); }
/** Create a port based connector. * This methods adds a port connector to the server * @return A URL to access the server via the connector. * @throws Exception */ public String createConnector(boolean localhost) throws Exception { ServerConnector connector = new ServerConnector(_server); if (localhost) connector.setHost("127.0.0.1"); _server.addConnector(connector); if (_server.isStarted()) connector.start(); else connector.open(); return "http://"+(localhost?"127.0.0.1": InetAddress.getLocalHost().getHostAddress() )+":"+connector.getLocalPort(); }
/** Create a port based connector. * This methods adds a port connector to the server * @return A URL to access the server via the connector. * @throws Exception */ public String createConnector(boolean localhost) throws Exception { ServerConnector connector = new ServerConnector(_server); if (localhost) connector.setHost("127.0.0.1"); _server.addConnector(connector); if (_server.isStarted()) connector.start(); else connector.open(); return "http://"+(localhost?"127.0.0.1": InetAddress.getLocalHost().getHostAddress() )+":"+connector.getLocalPort(); }
/** Create a port based connector. * This methods adds a port connector to the server * @return A URL to access the server via the connector. * @throws Exception */ public String createConnector(boolean localhost) throws Exception { ServerConnector connector = new ServerConnector(_server); if (localhost) connector.setHost("127.0.0.1"); _server.addConnector(connector); if (_server.isStarted()) connector.start(); else connector.open(); return "http://"+(localhost?"127.0.0.1": InetAddress.getLocalHost().getHostAddress() )+":"+connector.getLocalPort(); }
log.log(Level.INFO, "No channel set by activator, opening channel ourselves."); try { super.open(); } catch (RuntimeException e) { log.log(Level.SEVERE, "failed org.eclipse.jetty.server.Server open() with port " + getPort());
@Override public void open() throws IOException { try { super.open(); } catch (BindException e) { InetSocketAddress addr = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort()); throw new PortBindFailureException(addr); } } };
mServerConnector.open(); } catch (IOException e) { throw new RuntimeException(e);
listener.open(); LOG.info("Jetty bound to port " + listener.getLocalPort()); break;
listener.open(); LOG.info("Jetty bound to port " + listener.getLocalPort()); break;
connector.open(); } catch (IOException e) { connector.close();