本文整理匯總了Java中org.eclipse.jetty.server.HttpConfiguration類的典型用法代碼示例。如果您正苦於以下問題:Java HttpConfiguration類的具體用法?Java HttpConfiguration怎麽用?Java HttpConfiguration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpConfiguration類屬於org.eclipse.jetty.server包,在下文中一共展示了HttpConfiguration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: customize
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
@Override
public void customize(Server server) {
// HTTPS Configuration
HttpConfiguration httpsConfig = new HttpConfiguration();
httpsConfig.setSecureScheme("https");
httpsConfig.setSecurePort(8443);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
// SSL Context Factory for HTTPS and HTTP/2
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStoreResource(newClassPathResource("keystore"));
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
// SSL Connection Factory
SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, "h2");
// HTTP/2 Connector
ServerConnector http2Connector = new ServerConnector(server, ssl, new HTTP2ServerConnectionFactory(httpsConfig));
http2Connector.setPort(8443);
server.addConnector(http2Connector);
}
示例2: createConnector
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
/**
* Creates a server connector.
*
* If an HTTPS key store is configured, returns a SSL connector for HTTPS.
*
* Otherwise, returns a normal HTTP connector by default.
*
* @param server The server.
* @return The server connector.
*/
@SuppressWarnings("squid:S2095")
private ServerConnector createConnector(final Server server) {
final String keyStorePath = (String) configuration.get(MinijaxProperties.SSL_KEY_STORE_PATH);
if (keyStorePath == null || keyStorePath.isEmpty()) {
// Normal HTTP
return new ServerConnector(server);
}
final String keyStorePassword = (String) configuration.get(MinijaxProperties.SSL_KEY_STORE_PASSWORD);
final String keyManagerPassword = (String) configuration.get(MinijaxProperties.SSL_KEY_MANAGER_PASSWORD);
final HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(Minijax.class.getClassLoader().getResource(keyStorePath).toExternalForm());
sslContextFactory.setKeyStorePassword(keyStorePassword);
sslContextFactory.setKeyManagerPassword(keyManagerPassword);
return new ServerConnector(server,
new SslConnectionFactory(sslContextFactory, "http/1.1"),
new HttpConnectionFactory(https));
}
示例3: createHttpsConnector
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
/**
* Create an HTTPS connector for given jetty server instance. If the config has specified keystore/truststore settings
* they will be used else a self-signed certificate is generated and used.
*
* @param hostName
* @param config {@link DremioConfig} containing SSL related settings if any.
* @param embeddedJetty Jetty server instance needed for creating a ServerConnector.
*
* @return Initialized {@link ServerConnector} for HTTPS connections and the trust store. Trust store is non-null only
* when in case of auto generated self-signed certificate.
* @throws Exception
*/
public Pair<ServerConnector, KeyStore> createHttpsConnector(final Server embeddedJetty,
final DremioConfig config, final String hostName, final String... alternativeNames) throws Exception {
logger.info("Setting up HTTPS connector for web server");
final SslContextFactory sslContextFactory = new SslContextFactory();
Pair<KeyStore, String> keyStore = getKeyStore(config, hostName, alternativeNames);
KeyStore trustStore = getTrustStore(config);
sslContextFactory.setKeyStore(keyStore.getLeft());
// Assuming that the keystore and the keymanager passwords are the same
// based on JSSE examples...
sslContextFactory.setKeyManagerPassword(keyStore.getRight());
sslContextFactory.setTrustStore(trustStore);
// Disable ciphers, protocols and other that are considered weak/vulnerable
sslContextFactory.setExcludeCipherSuites(
"TLS_DHE.*",
"TLS_EDH.*"
// TODO: there are few other ciphers that Chrome complains about being obsolete. Research more about them and
// include here.
);
sslContextFactory.setExcludeProtocols("SSLv3");
sslContextFactory.setRenegotiationAllowed(false);
// SSL Connector
final ServerConnector sslConnector = new ServerConnector(embeddedJetty,
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
new HttpConnectionFactory(new HttpConfiguration()));
return Pair.of(sslConnector, trustStore);
}
示例4: setupSSL
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
private void setupSSL(Server server,HttpConfiguration http_config) {
SslContextFactory sslContextFactory = new SslContextFactory();
if (sslKeyStoreFile!=null)
sslContextFactory.setKeyStorePath(sslKeyStoreFile);
else if (sslKeyStore!=null)
sslContextFactory.setKeyStore(sslKeyStore);
else {
log.log(Level.SEVERE,"Error while configuring SSL connection. Missing KeyStore!");
return;
}
sslContextFactory.setKeyStorePassword(new String(sslKeyStorePassword));
sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA",
"SSL_DHE_RSA_WITH_DES_CBC_SHA", "SSL_DHE_DSS_WITH_DES_CBC_SHA",
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
HttpConfiguration https_config = new HttpConfiguration(http_config);
https_config.addCustomizer(new SecureRequestCustomizer());
ServerConnector sslConnector = new ServerConnector(server,
new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),
new HttpConnectionFactory(https_config));
sslConnector.setPort(daemonPortSecure);
server.addConnector(sslConnector);
}
示例5: addHttpsConnector
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
public static void addHttpsConnector(Server server, int port) throws IOException, URISyntaxException {
String keyStoreFile = resourceAsFile("ssltest-keystore.jks").getAbsolutePath();
SslContextFactory sslContextFactory = new SslContextFactory(keyStoreFile);
sslContextFactory.setKeyStorePassword("changeit");
String trustStoreFile = resourceAsFile("ssltest-cacerts.jks").getAbsolutePath();
sslContextFactory.setTrustStorePath(trustStoreFile);
sslContextFactory.setTrustStorePassword("changeit");
HttpConfiguration httpsConfig = new HttpConfiguration();
httpsConfig.setSecureScheme("https");
httpsConfig.setSecurePort(port);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
ServerConnector connector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(httpsConfig));
connector.setPort(port);
server.addConnector(connector);
}
示例6: newHttpConfiguration
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
public HttpConfiguration newHttpConfiguration() {
// HTTP Configuration
boolean sendServerVersion = Boolean.parseBoolean(
System.getProperty(AthenzConsts.ATHENZ_PROP_SEND_SERVER_VERSION, "false"));
boolean sendDateHeader = Boolean.parseBoolean(
System.getProperty(AthenzConsts.ATHENZ_PROP_SEND_DATE_HEADER, "false"));
int outputBufferSize = Integer.parseInt(
System.getProperty(AthenzConsts.ATHENZ_PROP_OUTPUT_BUFFER_SIZE, "32768"));
int requestHeaderSize = Integer.parseInt(
System.getProperty(AthenzConsts.ATHENZ_PROP_REQUEST_HEADER_SIZE, "8192"));
int responseHeaderSize = Integer.parseInt(
System.getProperty(AthenzConsts.ATHENZ_PROP_RESPONSE_HEADER_SIZE, "8192"));
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setOutputBufferSize(outputBufferSize);
httpConfig.setRequestHeaderSize(requestHeaderSize);
httpConfig.setResponseHeaderSize(responseHeaderSize);
httpConfig.setSendServerVersion(sendServerVersion);
httpConfig.setSendDateHeader(sendDateHeader);
return httpConfig;
}
示例7: testHttpConfigurationValidHttpsPort
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
@Test
public void testHttpConfigurationValidHttpsPort() {
AthenzJettyContainer container = new AthenzJettyContainer();
container.createServer(100);
System.setProperty(AthenzConsts.ATHENZ_PROP_SEND_SERVER_VERSION, "true");
System.setProperty(AthenzConsts.ATHENZ_PROP_SEND_DATE_HEADER, "false");
System.setProperty(AthenzConsts.ATHENZ_PROP_OUTPUT_BUFFER_SIZE, "128");
System.setProperty(AthenzConsts.ATHENZ_PROP_REQUEST_HEADER_SIZE, "256");
System.setProperty(AthenzConsts.ATHENZ_PROP_RESPONSE_HEADER_SIZE, "512");
HttpConfiguration httpConfig = container.newHttpConfiguration();
assertNotNull(httpConfig);
assertEquals(httpConfig.getOutputBufferSize(), 128);
assertFalse(httpConfig.getSendDateHeader());
assertTrue(httpConfig.getSendServerVersion());
assertEquals(httpConfig.getRequestHeaderSize(), 256);
assertEquals(httpConfig.getResponseHeaderSize(), 512);
// it defaults to https even if we have no value specified
assertEquals(httpConfig.getSecureScheme(), "https");
}
示例8: testHttpConfigurationNoHttpsPort
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
@Test
public void testHttpConfigurationNoHttpsPort() {
AthenzJettyContainer container = new AthenzJettyContainer();
container.createServer(100);
System.setProperty(AthenzConsts.ATHENZ_PROP_SEND_SERVER_VERSION, "false");
System.setProperty(AthenzConsts.ATHENZ_PROP_SEND_DATE_HEADER, "true");
System.setProperty(AthenzConsts.ATHENZ_PROP_OUTPUT_BUFFER_SIZE, "64");
System.setProperty(AthenzConsts.ATHENZ_PROP_REQUEST_HEADER_SIZE, "128");
System.setProperty(AthenzConsts.ATHENZ_PROP_RESPONSE_HEADER_SIZE, "256");
HttpConfiguration httpConfig = container.newHttpConfiguration();
assertNotNull(httpConfig);
assertEquals(httpConfig.getOutputBufferSize(), 64);
assertTrue(httpConfig.getSendDateHeader());
assertFalse(httpConfig.getSendServerVersion());
assertEquals(httpConfig.getRequestHeaderSize(), 128);
assertEquals(httpConfig.getResponseHeaderSize(), 256);
assertEquals(httpConfig.getSecurePort(), 0);
// it defaults to https even if we have no value specified
assertEquals(httpConfig.getSecureScheme(), "https");
}
示例9: testHttpConnectorsHttpsOnly
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
@Test
public void testHttpConnectorsHttpsOnly() {
System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PATH, "file:///tmp/keystore");
System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_TYPE, "PKCS12");
System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PASSWORD, "pass123");
System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PATH, "file:///tmp/truststore");
System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_TYPE, "PKCS12");
System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PASSWORD, "pass123");
System.setProperty(AthenzConsts.ATHENZ_PROP_KEYMANAGER_PASSWORD, "pass123");
System.setProperty(AthenzConsts.ATHENZ_PROP_IDLE_TIMEOUT, "10001");
AthenzJettyContainer container = new AthenzJettyContainer();
container.createServer(100);
HttpConfiguration httpConfig = container.newHttpConfiguration();
container.addHTTPConnectors(httpConfig, 0, 8082, 0);
Server server = container.getServer();
Connector[] connectors = server.getConnectors();
assertEquals(connectors.length, 1);
assertTrue(connectors[0].getProtocols().contains("http/1.1"));
assertTrue(connectors[0].getProtocols().contains("ssl"));
}
示例10: testHttpConnectorsHttpOnly
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
@Test
public void testHttpConnectorsHttpOnly() {
System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PATH, "file:///tmp/keystore");
System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_TYPE, "PKCS12");
System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PASSWORD, "pass123");
System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PATH, "file:///tmp/truststore");
System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_TYPE, "PKCS12");
System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PASSWORD, "pass123");
System.setProperty(AthenzConsts.ATHENZ_PROP_KEYMANAGER_PASSWORD, "pass123");
System.setProperty(AthenzConsts.ATHENZ_PROP_IDLE_TIMEOUT, "10001");
AthenzJettyContainer container = new AthenzJettyContainer();
container.createServer(100);
HttpConfiguration httpConfig = container.newHttpConfiguration();
container.addHTTPConnectors(httpConfig, 8081, 0, 0);
Server server = container.getServer();
Connector[] connectors = server.getConnectors();
assertEquals(connectors.length, 1);
assertEquals(connectors[0].getIdleTimeout(), 10001);
assertTrue(connectors[0].getProtocols().contains("http/1.1"));
assertFalse(connectors[0].getProtocols().contains("ssl"));
}
示例11: verifyConfiguration
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
/**
* Verifies all the needed bits are present in Jetty XML configuration (as HTTPS must be enabled by users).
*/
private void verifyConfiguration(final HttpScheme httpScheme) {
try {
if (HttpScheme.HTTP == httpScheme) {
bean(HTTP_CONFIG_ID, HttpConfiguration.class);
bean(HTTP_CONNECTOR_ID, ServerConnector.class);
}
else if (HttpScheme.HTTPS == httpScheme) {
bean(SSL_CONTEXT_FACTORY_ID, SslContextFactory.class);
bean(HTTPS_CONFIG_ID, HttpConfiguration.class);
bean(HTTPS_CONNECTOR_ID, ServerConnector.class);
}
else {
throw new UnsupportedHttpSchemeException(httpScheme);
}
}
catch (IllegalStateException e) {
throw new IllegalStateException("Jetty HTTPS is not enabled in Nexus", e);
}
}
示例12: buildHttpConfiguration
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
protected HttpConfiguration buildHttpConfiguration() {
HttpConfiguration httpConfig = new HttpConfiguration();
// most parameters are hardcoded for now... we should turn these
// into properties
httpConfig.setHeaderCacheSize(512);
httpConfig.setOutputBufferSize(32 * 1024);
httpConfig.setRequestHeaderSize(requestHeaderSize);
httpConfig.setResponseHeaderSize(responseHeaderSize);
httpConfig.setSendDateHeader(true);
httpConfig.setSendServerVersion(true);
httpConfig.addCustomizer(new ForwardedRequestCustomizer());
return httpConfig;
}
示例13: setup
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
public ServerConnector setup(final Server server, final InetSocketAddress address) {
final HttpConfiguration config = this.config.build();
final ConnectionFactory[] factories = this.factories
.stream()
.map(f -> f.setup(config))
.toArray(size -> new ConnectionFactory[size]);
final ServerConnector c = new ServerConnector(server, factories);
c.setHost(this.address.map(a -> a.getHostString()).orElseGet(address::getHostString));
c.setPort(this.address.map(a -> a.getPort()).orElseGet(address::getPort));
defaultProtocol.ifPresent(c::setDefaultProtocol);
return c;
}
示例14: startHttpsServer
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
@BeforeClass
public static void startHttpsServer() throws Exception {
skipIfHeadlessEnvironment();
server = new Server();
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(ErrorCases.class.getResource("keystore").getPath());
sslContextFactory.setKeyStorePassword("activeeon");
HttpConfiguration httpConfig = new HttpConfiguration();
HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
ServerConnector sslConnector = new ServerConnector(server,
new ConnectionFactory[] { new SslConnectionFactory(sslContextFactory,
HttpVersion.HTTP_1_1.asString()),
new HttpConnectionFactory(httpsConfig) });
server.addConnector(sslConnector);
server.start();
serverUrl = "https://localhost:" + sslConnector.getLocalPort() + "/rest";
}
示例15: listener
import org.eclipse.jetty.server.HttpConfiguration; //導入依賴的package包/類
public void listener(int port) {
initJettyConfig();
this.port = port;
HttpConfiguration httpConfiguration = initHttpConfiguration();
HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(httpConfiguration);
QueuedThreadPool threadPool = this.initThreadPool();
this.server = new Server(threadPool);
int cores = Runtime.getRuntime().availableProcessors();
ServerConnector connector = new ServerConnector(server, null, null, null, 1 + cores / 2, -1,
httpConnectionFactory);
initConnector(connector);
connector.setPort(this.port);
server.setConnectors(new Connector[] { connector });
logger.info("Application listen on " + port);
}