diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java index 2d1f835f27e..6e5866bf628 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java @@ -129,10 +129,10 @@ public class LikeJettyXml // === jetty-https.xml === // SSL Context Factory SslContextFactory sslContextFactory = new SslContextFactory(); - sslContextFactory.setKeyStorePath(jetty_home + "/etc/keystore"); + sslContextFactory.setKeyStorePath(jetty_home + "/../../../jetty-server/src/test/config/etc/keystore"); sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g"); - sslContextFactory.setTrustStorePath(jetty_home + "/etc/keystore"); + sslContextFactory.setTrustStorePath(jetty_home + "/../../../jetty-server/src/test/config/etc/keystore"); sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA", "SSL_DHE_RSA_WITH_DES_CBC_SHA", "SSL_DHE_DSS_WITH_DES_CBC_SHA", diff --git a/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/HttpSpiContextHandler.java b/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/HttpSpiContextHandler.java index 03dc87cc6ec..18f6079b7ce 100644 --- a/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/HttpSpiContextHandler.java +++ b/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/HttpSpiContextHandler.java @@ -99,7 +99,7 @@ public class HttpSpiContextHandler extends ContextHandler ex.printStackTrace(writer); writer.println(""); - writer.println("

"+Jetty.POWERED_BY_HTML+"

"); + baseRequest.getHttpChannel().getHttpConfiguration().writePoweredBy(writer,"

","

"); writer.close(); } diff --git a/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/JettyHttpServer.java b/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/JettyHttpServer.java index 73a12ce508e..552d405fcdf 100644 --- a/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/JettyHttpServer.java +++ b/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/JettyHttpServer.java @@ -28,6 +28,8 @@ import java.util.concurrent.ThreadPoolExecutor; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.HttpConfiguration; +import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.NetworkConnector; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; @@ -48,24 +50,35 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer { private static final Logger LOG = Log.getLogger(JettyHttpServer.class); + private final HttpConfiguration _httpConfiguration; + + private final Server _server; - private Server _server; - private boolean _serverShared; private InetSocketAddress _addr; - private ThreadPoolExecutor _executor; private Map _contexts = new HashMap(); - + private Map _connectors = new HashMap(); - + public JettyHttpServer(Server server, boolean shared) + { + this(server,shared,new HttpConfiguration()); + } + + public JettyHttpServer(Server server, boolean shared, HttpConfiguration configuration) { this._server = server; this._serverShared = shared; + this._httpConfiguration = configuration; + } + + public HttpConfiguration getHttpConfiguration() + { + return _httpConfiguration; } @Override @@ -83,10 +96,10 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer } } } - + if (_serverShared) - throw new IOException("jetty server is not bound to port " + addr.getPort()); - + throw new IOException("jetty server is not bound to port " + addr.getPort()); + this._addr = addr; if (LOG.isDebugEnabled()) LOG.debug("binding server to port " + addr.getPort()); @@ -94,10 +107,18 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer connector.setPort(addr.getPort()); connector.setHost(addr.getHostName()); _server.addConnector(connector); - + _connectors.put(addr.getHostName() + addr.getPort(), connector); } + protected ServerConnector newServerConnector(InetSocketAddress addr,int backlog) + { + ServerConnector connector = new ServerConnector(_server,new HttpConnectionFactory(_httpConfiguration)); + connector.setPort(addr.getPort()); + connector.setHost(addr.getHostName()); + return connector; + } + @Override public InetSocketAddress getAddress() { @@ -108,7 +129,7 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer public void start() { if (_serverShared) return; - + try { _server.start(); @@ -145,7 +166,7 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer { cleanUpContexts(); cleanUpConnectors(); - + if (_serverShared) return; try @@ -158,15 +179,15 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer } } - private void cleanUpContexts() - { + private void cleanUpContexts() + { for (Map.Entry stringJettyHttpContextEntry : _contexts.entrySet()) { JettyHttpContext context = stringJettyHttpContextEntry.getValue(); _server.removeBean(context.getJettyContextHandler()); } - _contexts.clear(); - } + _contexts.clear(); + } private void cleanUpConnectors() { @@ -176,15 +197,17 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer try { connector.stop(); - } catch (Exception ex) { + } + catch (Exception ex) + { LOG.warn(ex); } _server.removeConnector(connector); } - _connectors.clear(); - } + _connectors.clear(); + } - @Override + @Override public HttpContext createContext(String path, HttpHandler httpHandler) { checkIfContextIsFree(path); @@ -194,7 +217,7 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer ContextHandlerCollection chc = findContextHandlerCollection(_server.getHandlers()); if (chc == null) - throw new RuntimeException("could not find ContextHandlerCollection, you must configure one"); + throw new RuntimeException("could not find ContextHandlerCollection, you must configure one"); chc.addHandler(jettyContextHandler); _contexts.put(path, context); @@ -228,13 +251,13 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer private void checkIfContextIsFree(String path) { Handler serverHandler = _server.getHandler(); - if (serverHandler instanceof ContextHandler) - { - ContextHandler ctx = (ContextHandler) serverHandler; - if (ctx.getContextPath().equals(path)) - throw new RuntimeException("another context already bound to path " + path); - } - + if (serverHandler instanceof ContextHandler) + { + ContextHandler ctx = (ContextHandler) serverHandler; + if (ctx.getContextPath().equals(path)) + throw new RuntimeException("another context already bound to path " + path); + } + Handler[] handlers = _server.getHandlers(); if (handlers == null) return; @@ -246,9 +269,9 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer throw new RuntimeException("another context already bound to path " + path); } } - } + } - @Override + @Override public HttpContext createContext(String path) { return createContext(path, null); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java index 79146119d86..cc7af64161c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.server; +import java.io.IOException; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -208,6 +209,19 @@ public class HttpConfiguration return _sendServerVersion; } + /* ------------------------------------------------------------ */ + public void writePoweredBy(Appendable out,String preamble,String postamble) throws IOException + { + if (getSendServerVersion()) + { + if (preamble!=null) + out.append(preamble); + out.append(Jetty.POWERED_BY); + if (postamble!=null) + out.append(postamble); + } + } + /* ------------------------------------------------------------ */ public void setSendXPoweredBy (boolean sendXPoweredBy) { diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java index d044e867e5f..c6e2107f400 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java @@ -605,11 +605,8 @@ public class Response implements HttpServletResponse writer.write(message); writer.write(""); writer.write("

\n
"); - if (getHttpChannel().getHttpConfiguration().getSendServerVersion()) - { - writer.write(Jetty.POWERED_BY_HTML); - writer.write("
"); - } + + getHttpChannel().getHttpConfiguration().writePoweredBy(writer,null,"
"); writer.write("\n\n\n"); writer.flush(); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/DefaultHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/DefaultHandler.java index cada111a494..4aa5931292c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/DefaultHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/DefaultHandler.java @@ -165,12 +165,8 @@ public class DefaultHandler extends AbstractHandler writer.write("
"); - - if (baseRequest.getHttpChannel().getHttpConfiguration().getSendServerVersion()) - { - writer.write(" "); - writer.write(Jetty.POWERED_BY_HTML+"
\n"); - } + baseRequest.getHttpChannel().getHttpConfiguration() + .writePoweredBy(writer," ","
\n"); writer.write("\n\n\n"); writer.flush(); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java index 3a0698ea4a3..c7fa2f50138 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java @@ -162,9 +162,9 @@ public class ErrorHandler extends AbstractHandler writeErrorPageMessage(request,writer,code,message,uri); if (showStacks) writeErrorPageStacks(request,writer); - - if (Request.getBaseRequest(request).getHttpChannel().getHttpConfiguration().getSendServerVersion()) - writer.write("
"+Jetty.POWERED_BY_HTML+"
\n"); + + Request.getBaseRequest(request).getHttpChannel().getHttpConfiguration() + .writePoweredBy(writer,"
","
\n"); } /* ------------------------------------------------------------ */ diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Jetty.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Jetty.java index 6130b70b922..fc338458410 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/Jetty.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Jetty.java @@ -22,7 +22,6 @@ public class Jetty { public static final String VERSION; public static final String POWERED_BY; - public static final String POWERED_BY_HTML; static { @@ -34,8 +33,7 @@ public class Jetty else VERSION = System.getProperty("jetty.version", "9.3.z-SNAPSHOT"); - POWERED_BY="Powered by Jetty://"+VERSION; - POWERED_BY_HTML=""+POWERED_BY+""; + POWERED_BY="Powered by Jetty:// "+VERSION+""; } private Jetty()