當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpVersion類代碼示例

本文整理匯總了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);
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:46,代碼來源:HttpsConnectorGenerator.java

示例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);
}
 
開發者ID:gustavohbf,項目名稱:robotoy,代碼行數:27,代碼來源:WebServer.java

示例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";
}
 
開發者ID:ow2-proactive,項目名稱:scheduling,代碼行數:23,代碼來源:ErrorCases.java

示例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());
}
 
開發者ID:line,項目名稱:armeria,代碼行數:26,代碼來源:JettyService.java

示例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);
    }
  }
}
 
開發者ID:apache,項目名稱:helix,代碼行數:20,代碼來源:HelixRestServer.java

示例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;
}
 
開發者ID:fuwjax,項目名稱:ev-oss,代碼行數:17,代碼來源:Dialog.java

示例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));
}
 
開發者ID:betfair,項目名稱:cougar,代碼行數:24,代碼來源:AsyncHttpExecutableTest.java

示例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());
}
 
開發者ID:galop-proxy,項目名稱:galop,代碼行數:10,代碼來源:UnsupportedRequestsTest.java

示例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());
}
 
開發者ID:galop-proxy,項目名稱:galop,代碼行數:10,代碼來源:UnsupportedRequestsTest.java


注:本文中的org.eclipse.jetty.http.HttpVersion類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。