/** * Checks that the only connector configured for the current jetty instance and returns it. * * @return Connector instance. * @throws GridException If no or more than one connectors found. */ private AbstractNetworkConnector getJettyConnector() throws GridException { if (httpSrv.getConnectors().length == 1) { Connector connector = httpSrv.getConnectors()[0]; if (!(connector instanceof AbstractNetworkConnector)) throw new GridException( "Error in jetty configuration. Jetty connector should extend " + "AbstractNetworkConnector class."); return (AbstractNetworkConnector) connector; } else throw new GridException( "Error in jetty configuration [connectorsFound=" + httpSrv.getConnectors().length + "connectorsExpected=1]"); }
/** * @throws GridException If failed. * @return {@code True} if Jetty started. */ @SuppressWarnings("IfMayBeConditional") private boolean startJetty() throws GridException { try { httpSrv.start(); if (httpSrv.isStarted()) { for (Connector con : httpSrv.getConnectors()) { int connPort = ((NetworkConnector) con).getPort(); if (connPort > 0) ctx.ports().registerPort(connPort, TCP, getClass()); } return true; } return false; } catch (SocketException ignore) { if (log.isDebugEnabled()) log.debug("Failed to bind HTTP server to configured port."); stopJetty(); return false; } catch (MultiException e) { if (log.isDebugEnabled()) log.debug("Caught multi exception: " + e); for (Object obj : e.getThrowables()) if (!(obj instanceof SocketException)) throw new GridException("Failed to start Jetty HTTP server.", e); if (log.isDebugEnabled()) log.debug("Failed to bind HTTP server to configured port."); stopJetty(); return false; } catch (Exception e) { throw new GridException("Failed to start Jetty HTTP server.", e); } }