@Override public boolean startRequest( HttpMethod method, String methodString, ByteBuffer uri, HttpVersion httpVersion) { Connector connector = getConnector(); String scheme = connector.getConnectionFactory(SslConnectionFactory.class) != null ? "https" : "http"; headers.put(HTTPSPDYHeader.SCHEME.name(version), scheme); headers.put(HTTPSPDYHeader.METHOD.name(version), methodString); headers.put( HTTPSPDYHeader.URI.name(version), BufferUtil.toUTF8String(uri)); // TODO handle bad encodings headers.put(HTTPSPDYHeader.VERSION.name(version), httpVersion.asString()); return false; }
@Override public void start() { jettyServer = jettyFactory.createServer( configuration.getServerMaxThreads(), configuration.getServerMinThreads(), configuration.getServerIdleTimeout()); httpConnector = null; httpSecureConnector = null; String[] addresses = configuration.getListeningAddresses(); if (addresses == null || addresses.length == 0) { addresses = new String[] {null}; } Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("javax.servlet.context.tempdir", configuration.getTemporaryDirectory()); // Fix for PAXWEB-193 jettyServer.setServerConfigDir(configuration.getConfigurationDir()); jettyServer.setServerConfigURL(configuration.getConfigurationURL()); jettyServer.configureContext( attributes, configuration.getSessionTimeout(), configuration.getSessionCookie(), configuration.getSessionDomain(), configuration.getSessionPath(), configuration.getSessionUrl(), configuration.getSessionCookieHttpOnly(), configuration.getSessionCookieSecure(), configuration.getWorkerName(), configuration.getSessionLazyLoad(), configuration.getSessionStoreDirectory()); // Configure NCSA RequestLogHandler if (configuration.isLogNCSAFormatEnabled()) { jettyServer.configureRequestLog( new ConfigureRequestLogParameter( configuration.getLogNCSAFormat(), configuration.getLogNCSARetainDays(), configuration.isLogNCSAAppend(), configuration.isLogNCSAExtended(), configuration.isLogNCSADispatch(), configuration.getLogNCSATimeZone(), configuration.getLogNCSADirectory(), configuration.isLogNCSALatency(), configuration.isLogNCSACookies(), configuration.isLogNCSAServer())); } jettyServer.start(); for (String address : addresses) { Integer httpPort = configuration.getHttpPort(); // Boolean useNIO = configuration.useNIO(); Integer httpSecurePort = configuration.getHttpSecurePort(); // Server should listen to std. http. if (configuration.isHttpEnabled()) { Connector[] connectors = jettyServer.getConnectors(); // Flag is set if the same connector has been found // through xml config and properties boolean masterConnectorFound = false; if (connectors != null && connectors.length > 0) { // Combine the configurations if they do match ServerConnector backupConnector = null; for (Connector connector : connectors) { if ((connector instanceof ServerConnector) && (connector.getConnectionFactory(SslConnectionFactory.class)) == null) { if (match(address, httpPort, connector)) { // the same connection as configured through // property/config-admin already is // configured through jetty.xml // therefore just use it as the one if not // already done so. // CHECKSTYLE:OFF if (httpConnector == null) { httpConnector = (ServerConnector) connector; } // CHECKSTYLE:ON masterConnectorFound = true; } else { // CHECKSTYLE:OFF if (backupConnector == null) { backupConnector = (ServerConnector) connector; } // CHECKSTYLE:ON } } } if (httpConnector == null && backupConnector != null) { httpConnector = backupConnector; } } if (!masterConnectorFound) { final Connector connector = jettyFactory.createConnector( jettyServer.getServer(), configuration.getHttpConnectorName(), httpPort, httpSecurePort, address, configuration.checkForwardedHeaders()); if (httpConnector == null) { httpConnector = (ServerConnector) connector; } jettyServer.addConnector(connector); } } else { // remove maybe already configured connectors through // jetty.xml, the config-property/config-admin service is // master configuration Connector[] connectors = jettyServer.getConnectors(); if (connectors != null) { for (Connector connector : connectors) { if ((connector instanceof Connector) && (connector.getConnectionFactory(SslConnectionFactory.class)) == null) { LOG.warn( String.format( "HTTP is not enabled in Pax Web configuration - removing connector: %s", connector)); jettyServer.removeConnector(connector); } } } } if (configuration.isHttpSecureEnabled()) { final String sslPassword = configuration.getSslPassword(); final String sslKeyPassword = configuration.getSslKeyPassword(); Connector[] connectors = jettyServer.getConnectors(); boolean masterSSLConnectorFound = false; if (connectors != null && connectors.length > 0) { // Combine the configurations if they do match ServerConnector backupConnector = null; for (Connector connector : connectors) { if (connector.getConnectionFactory(SslConnectionFactory.class) != null) { ServerConnector sslCon = (ServerConnector) connector; String[] split = connector.getName().split(":"); if (httpSecurePort == Integer.valueOf(split[1]).intValue() && address.equalsIgnoreCase(split[0])) { httpSecureConnector = sslCon; masterSSLConnectorFound = true; } else { // default behavior // CHECKSTYLE:OFF if (backupConnector == null) { backupConnector = (ServerConnector) connector; } // CHECKSTYLE:ON } } } if (httpSecureConnector == null && backupConnector != null) { httpSecureConnector = backupConnector; } } if (!masterSSLConnectorFound) { // no combination of jetty.xml and // config-admin/properties needed if (sslPassword != null && sslKeyPassword != null) { final Connector secureConnector = jettyFactory.createSecureConnector( jettyServer.getServer(), configuration.getHttpSecureConnectorName(), httpSecurePort, configuration.getSslKeystore(), sslPassword, sslKeyPassword, address, configuration.getSslKeystoreType(), configuration.isClientAuthNeeded(), configuration.isClientAuthWanted(), configuration.getCiphersuiteIncluded(), configuration.getCiphersuiteExcluded()); if (httpSecureConnector == null) { httpSecureConnector = (ServerConnector) secureConnector; } jettyServer.addConnector(secureConnector); } else { LOG.warn( "SSL password and SSL keystore password must be set in order to enable SSL."); LOG.warn("SSL connector will not be started"); } } } else { // remove maybe already configured connectors through // jetty.xml, the config-property/config-admin service is // master configuration Connector[] connectors = jettyServer.getConnectors(); if (connectors != null) { for (Connector connector : connectors) { if (connector.getConnectionFactory(SslConnectionFactory.class) != null) { LOG.warn( String.format( "HTTPS is not enabled in Pax Web configuration - removing connector: %s", connector)); jettyServer.removeConnector(connector); } } } } } state = new Started(); notifyListeners(ServerEvent.STARTED); }