本文整理汇总了Java中org.eclipse.jetty.http.HttpVersion类的典型用法代码示例。如果您正苦于以下问题:Java HttpVersion类的具体用法?Java HttpVersion怎么用?Java HttpVersion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpVersion类属于org.eclipse.jetty.http包,在下文中一共展示了HttpVersion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHttpsConnector
import org.eclipse.jetty.http.HttpVersion; //导入依赖的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);
}
示例2: setupSSL
import org.eclipse.jetty.http.HttpVersion; //导入依赖的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);
}
示例3: setup
import org.eclipse.jetty.http.HttpVersion; //导入依赖的package包/类
@Before
public void setup() throws Exception {
servletTester.addServlet(DummyAssetServlet.class, DUMMY_SERVLET + '*');
servletTester.addServlet(NoIndexAssetServlet.class, NOINDEX_SERVLET + '*');
servletTester.addServlet(NoCharsetAssetServlet.class, NOCHARSET_SERVLET + '*');
servletTester.addServlet(RootAssetServlet.class, ROOT_SERVLET + '*');
servletTester.addServlet(MimeMappingsServlet.class, MIME_SERVLET + '*');
servletTester.addServlet(CachingServlet.class, CACHE_SERVLET + '*');
ServletHolder servlet = new ServletHolder(MultipleMappingsServlet.class);
servletTester.addServlet(servlet, MM_ASSET_SERVLET + '*');
servletTester.addServlet(servlet, MM_JSON_SERVLET + '*');
servletTester.start();
servletTester.getContext().getMimeTypes().addMimeMapping("mp4", "video/mp4");
servletTester.getContext().getMimeTypes().addMimeMapping("m4a", "audio/mp4");
request.setMethod("GET");
request.setURI(DUMMY_SERVLET + "example.txt");
request.setVersion(HttpVersion.HTTP_1_0);
}
开发者ID:dropwizard-bundles,项目名称:dropwizard-configurable-assets-bundle,代码行数:22,代码来源:AssetServletTest.java
示例4: startHttpsServer
import org.eclipse.jetty.http.HttpVersion; //导入依赖的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";
}
示例5: toRequestMetadata
import org.eclipse.jetty.http.HttpVersion; //导入依赖的package包/类
private static MetaData.Request toRequestMetadata(ServiceRequestContext ctx, AggregatedHttpMessage aReq) {
// Construct the HttpURI
final StringBuilder uriBuf = new StringBuilder();
final HttpHeaders aHeaders = aReq.headers();
uriBuf.append(ctx.sessionProtocol().isTls() ? "https" : "http");
uriBuf.append("://");
uriBuf.append(aHeaders.authority());
uriBuf.append(aHeaders.path());
final HttpURI uri = new HttpURI(uriBuf.toString());
uri.setPath(ctx.mappedPath());
// Convert HttpHeaders to HttpFields
final HttpFields jHeaders = new HttpFields(aHeaders.size());
aHeaders.forEach(e -> {
final AsciiString key = e.getKey();
if (!key.isEmpty() && key.byteAt(0) != ':') {
jHeaders.add(key.toString(), e.getValue());
}
});
return new MetaData.Request(
aHeaders.method().name(), uri, HttpVersion.HTTP_1_1, jHeaders, aReq.content().length());
}
示例6: setupSslServer
import org.eclipse.jetty.http.HttpVersion; //导入依赖的package包/类
public void setupSslServer(int port, SslContextFactory sslContextFactory) {
if (_server != null && port > 0) {
try {
HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());
ServerConnector sslConnector = new ServerConnector(
_server,
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
new HttpConnectionFactory(https));
sslConnector.setPort(port);
_server.addConnector(sslConnector);
LOG.info("Helix SSL rest server is ready to start.");
} catch (Exception ex) {
LOG.error("Failed to setup Helix SSL rest server, " + ex);
}
}
}
示例7: runRequest
import org.eclipse.jetty.http.HttpVersion; //导入依赖的package包/类
/**
* Fire one request at the security handler (and by extension to the AuthServlet behind it).
*
* @param path The path to hit.
* @param request The request object to use.
* @param response The response object to use. Must be created by Mockito.mock()
* @return Any data written to response.getWriter()
* @throws IOException
* @throws ServletException
*/
private String runRequest(String path, Request request, Response response)
throws IOException, ServletException {
//request.setMethod(/*HttpMethod.GET,*/ "GET");
HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path);
HttpFields httpf = new HttpFields();
MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf);
request.setMetaData(metadata);
// request.setServerName(SERVER_NAME);
// request.setAuthority(SERVER_NAME,9999);
//// request.setPathInfo(path);
//// request.setURIPathQuery(path);
request.setDispatcherType(DispatcherType.REQUEST);
doReturn(response).when(request).getResponse();
ByteArrayOutputStream output = new ByteArrayOutputStream();
try (PrintWriter writer = new PrintWriter(output)) {
when(response.getWriter()).thenReturn(writer);
securityHandler.handle(path, request, request, response);
}
return new String(output.toByteArray());
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:33,代码来源:AppEngineAuthenticationTest.java
示例8: runRequest2
import org.eclipse.jetty.http.HttpVersion; //导入依赖的package包/类
private String runRequest2(String path, Request request, Response response)
throws IOException, ServletException {
//request.setMethod(/*HttpMethod.GET,*/ "GET");
HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path);
HttpFields httpf = new HttpFields();
MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf);
// request.setMetaData(metadata);
// request.setServerName(SERVER_NAME);
// request.setAuthority(SERVER_NAME,9999);
//// request.setPathInfo(path);
//// request.setURIPathQuery(path);
request.setDispatcherType(DispatcherType.REQUEST);
doReturn(response).when(request).getResponse();
ByteArrayOutputStream output = new ByteArrayOutputStream();
try (PrintWriter writer = new PrintWriter(output)) {
when(response.getWriter()).thenReturn(writer);
securityHandler.handle(path, request, request, response);
}
return new String(output.toByteArray());
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:23,代码来源:AppEngineAuthenticationTest.java
示例9: testUserRequired_NoUser
import org.eclipse.jetty.http.HttpVersion; //导入依赖的package包/类
public void testUserRequired_NoUser() throws Exception {
String path = "/user/blah";
Request request = spy(new Request(null, null));
//request.setServerPort(9999);
HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path);
HttpFields httpf = new HttpFields();
MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf);
request.setMetaData(metadata);
// request.setAuthority(SERVER_NAME,9999);
Response response = mock(Response.class);
String output = runRequest(path, request, response);
// Verify that the servlet never was run (there is no output).
assertEquals("", output);
// Verify that the request was redirected to the login url.
String loginUrl = UserServiceFactory.getUserService()
.createLoginURL(String.format("http://%s%s", SERVER_NAME + ":9999", path));
verify(response).sendRedirect(loginUrl);
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:19,代码来源:AppEngineAuthenticationTest.java
示例10: testUserRequired_PreserveQueryParams
import org.eclipse.jetty.http.HttpVersion; //导入依赖的package包/类
public void testUserRequired_PreserveQueryParams() throws Exception {
String path = "/user/blah";
Request request = new Request(null, null);
// request.setServerPort(9999);
HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path,"foo=baqr","foo=bar","foo=barff");
HttpFields httpf = new HttpFields();
MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf);
request.setMetaData(metadata);
MultiMap<String> queryParameters = new MultiMap<> ();
queryParameters.add("ffo", "bar");
request.setQueryParameters(queryParameters);
request = spy(request);
/// request.setAuthority(SERVER_NAME,9999);
request.setQueryString("foo=bar");
Response response = mock(Response.class);
String output = runRequest2(path, request, response);
// Verify that the servlet never was run (there is no output).
assertEquals("", output);
// Verify that the request was redirected to the login url.
String loginUrl = UserServiceFactory.getUserService()
.createLoginURL(String.format("http://%s%s?foo=bar", SERVER_NAME + ":9999", path));
verify(response).sendRedirect(loginUrl);
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:26,代码来源:AppEngineAuthenticationTest.java
示例11: testAdminRequired_NoUser
import org.eclipse.jetty.http.HttpVersion; //导入依赖的package包/类
public void testAdminRequired_NoUser() throws Exception {
String path = "/admin/blah";
Request request = spy(new Request(null, null));
//request.setServerPort(9999);
HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path);
HttpFields httpf = new HttpFields();
MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf);
request.setMetaData(metadata);
// request.setAuthority(SERVER_NAME,9999);
Response response = mock(Response.class);
String output = runRequest(path, request, response);
// Verify that the servlet never was run (there is no output).
assertEquals("", output);
// Verify that the request was redirected to the login url.
String loginUrl = UserServiceFactory.getUserService()
.createLoginURL(String.format("http://%s%s", SERVER_NAME + ":9999", path));
verify(response).sendRedirect(loginUrl);
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:19,代码来源:AppEngineAuthenticationTest.java
示例12: createServerRequest
import org.eclipse.jetty.http.HttpVersion; //导入依赖的package包/类
public boolean createServerRequest(String rewrittenTarget, HttpClient client, String hostHeader, String viaName, long timeout) {
log.debug("{} rewriting: {} -> {}", id(), Log.defer(this::target), rewrittenTarget);
if (rewrittenTarget == null) {
sendProxyResponseError(HttpStatus.FORBIDDEN_403);
return false;
}
proxyRequest = client.newRequest(rewrittenTarget).method(clientRequest.getMethod()).version(HttpVersion.fromString(clientRequest.getProtocol()));
initRequestHeaders(hostHeader, viaName);
final AsyncContext asyncContext = clientRequest.startAsync();
// We do not timeout the continuation, but the proxy request.
asyncContext.setTimeout(0);
proxyRequest.timeout(timeout, TimeUnit.MILLISECONDS);
return true;
}
示例13: fireResponse
import org.eclipse.jetty.http.HttpVersion; //导入依赖的package包/类
private void fireResponse(CapturingRequest request, int errorCode, String responseText, int resultSize, ObservableObserver observer, boolean successfulResponse) throws InterruptedException {
Response.CompleteListener listener = request.awaitSend(1000, TimeUnit.MILLISECONDS);
assertNotNull(listener);
InputStreamResponseListener responseListener = (InputStreamResponseListener) listener;
Result result = mock(Result.class);
Response response = mock(Response.class);
when(result.getResponse()).thenReturn(response);
when(result.isSucceeded()).thenReturn(successfulResponse);
when(result.isFailed()).thenReturn(!successfulResponse);
HttpFields headers = mock(HttpFields.class);
when(response.getHeaders()).thenReturn(headers);
when(headers.get(HttpHeader.CONTENT_LENGTH)).thenReturn(String.valueOf(resultSize));
when(response.getStatus()).thenReturn(errorCode);
when(response.getVersion()).thenReturn(HttpVersion.HTTP_1_1);
// fire that event
responseListener.onHeaders(response);
responseListener.onContent(response, ByteBuffer.allocate(0));
responseListener.onComplete(result);
assertTrue(observer.getLatch().await(1000, TimeUnit.MILLISECONDS));
}
示例14: Requests_with_HTTP_version_1_0_are_rejected_with_the_status_code_505
import org.eclipse.jetty.http.HttpVersion; //导入依赖的package包/类
@Test
public void Requests_with_HTTP_version_1_0_are_rejected_with_the_status_code_505() throws Exception {
final ContentResponse response = client
.newRequest("http://localhost:8080/")
.method(HttpMethod.GET)
.version(HttpVersion.HTTP_1_0)
.send();
assertEquals(505, response.getStatus());
}
示例15: Requests_with_HTTP_version_2_0_are_rejected_with_the_status_code_505
import org.eclipse.jetty.http.HttpVersion; //导入依赖的package包/类
@Test
public void Requests_with_HTTP_version_2_0_are_rejected_with_the_status_code_505() throws Exception {
final ContentResponse response = client
.newRequest("http://localhost:8080/")
.method(HttpMethod.GET)
.version(HttpVersion.HTTP_2)
.send();
assertEquals(505, response.getStatus());
}