当前位置: 首页>>代码示例>>Java>>正文


Java HttpScheme.HTTP属性代码示例

本文整理汇总了Java中org.eclipse.jetty.http.HttpScheme.HTTP属性的典型用法代码示例。如果您正苦于以下问题:Java HttpScheme.HTTP属性的具体用法?Java HttpScheme.HTTP怎么用?Java HttpScheme.HTTP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.eclipse.jetty.http.HttpScheme的用法示例。


在下文中一共展示了HttpScheme.HTTP属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verifyConfiguration

/**
 * 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);
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:22,代码来源:ConnectorManager.java

示例2: defaultHttpConfiguration

/**
 * Returns the OOTB defined configuration for given HTTP scheme.
 */
private HttpConfiguration defaultHttpConfiguration(final HttpScheme httpScheme) {
  if (HttpScheme.HTTP == httpScheme) {
    return bean(HTTP_CONFIG_ID, HttpConfiguration.class);
  }
  else if (HttpScheme.HTTPS == httpScheme) {
    return bean(HTTPS_CONFIG_ID, HttpConfiguration.class);
  }
  else {
    throw new UnsupportedHttpSchemeException(httpScheme);
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:14,代码来源:ConnectorManager.java

示例3: defaultConnector

/**
 * Returns the OOTB defined connector for given HTTP scheme.
 */
private ServerConnector defaultConnector(final HttpScheme httpScheme) {
  if (HttpScheme.HTTP == httpScheme) {
    return bean(HTTP_CONNECTOR_ID, ServerConnector.class);
  }
  else if (HttpScheme.HTTPS == httpScheme) {
    return bean(HTTPS_CONNECTOR_ID, ServerConnector.class);
  }
  else {
    throw new UnsupportedHttpSchemeException(httpScheme);
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:14,代码来源:ConnectorManager.java

示例4: addConnector

/**
 * Adds and starts connector to Jetty based on passed in configuration.
 */
public ServerConnector addConnector(final ConnectorConfiguration connectorConfiguration)
{
  final HttpScheme httpScheme = connectorConfiguration.getScheme();
  verifyConfiguration(httpScheme);

  final HttpConfiguration httpConfiguration =
      connectorConfiguration.customize(defaultHttpConfiguration(httpScheme));
  final ServerConnector connectorPrototype =
      defaultConnector(httpScheme);
  final ServerConnector serverConnector;
  if (HttpScheme.HTTP == httpScheme) {
    serverConnector = new ServerConnector(
        server,
        connectorPrototype.getAcceptors(),
        connectorPrototype.getSelectorManager().getSelectorCount(),
        new InstrumentedConnectionFactory(
            new HttpConnectionFactory(httpConfiguration)
        )
    );
  }
  else if (HttpScheme.HTTPS == httpScheme) {
    final SslContextFactory sslContextFactory = bean(SSL_CONTEXT_FACTORY_ID, SslContextFactory.class);
    serverConnector = new ServerConnector(
        server,
        connectorPrototype.getAcceptors(),
        connectorPrototype.getSelectorManager().getSelectorCount(),
        new InstrumentedConnectionFactory(
            new SslConnectionFactory(sslContextFactory, "http/1.1")
        ),
        new HttpConnectionFactory(httpConfiguration)
    );
  }
  else {
    throw new UnsupportedHttpSchemeException(httpScheme);
  }
  serverConnector.setHost(connectorPrototype.getHost());
  serverConnector.setPort(connectorConfiguration.getPort());
  serverConnector.setIdleTimeout(connectorPrototype.getIdleTimeout());
  serverConnector.setSoLingerTime(connectorPrototype.getSoLingerTime());
  serverConnector.setAcceptorPriorityDelta(connectorPrototype.getAcceptorPriorityDelta());
  serverConnector.setAcceptQueueSize(connectorPrototype.getAcceptQueueSize());

  managedConnectors.put(connectorConfiguration, serverConnector);
  server.addConnector(serverConnector);
  try {
    serverConnector.start();
  }
  catch (Exception e) {
    log.warn("Could not start connector: {}", connectorConfiguration, e);
    throw new RuntimeException(e);
  }

  return serverConnector;
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:57,代码来源:ConnectorManager.java

示例5: lowLevelApiTest

@Test
public void lowLevelApiTest() throws Exception {
    
    // start the test server
    class MyServlet extends HttpServlet { 
        
        @Override
        protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.getWriter().write("<html> <header> ...");
        }
    };
    
    WebServer server = WebServer.servlet(new MyServlet())
                                .start();

    

    
    // create a low-level jetty HTTP/2 client
    HTTP2Client lowLevelClient = new HTTP2Client();
    lowLevelClient.start();
    


    
    // create a new session which will open a (multiplexed) connection to the server  
    FuturePromise<Session> sessionFuture = new FuturePromise<>();
    lowLevelClient.connect(new InetSocketAddress("localhost", server.getLocalport()), new Session.Listener.Adapter(), sessionFuture);
    Session session = sessionFuture.get();
    
    // create the header frame 
    MetaData.Request metaData = new MetaData.Request("GET", HttpScheme.HTTP, new HostPortHttpField("localhost:" + server.getLocalport()), "/", HttpVersion.HTTP_2, new HttpFields());
    HeadersFrame frame = new HeadersFrame(1, metaData, null, true);

    // ... and perform the http transaction
    PrintingFramesHandler framesHandler = new PrintingFramesHandler();
    session.newStream(frame, new Promise.Adapter<Stream>(), framesHandler);

    
    
    
    // wait until response is received (PrintingFramesHandler will write the response frame to console) 
    framesHandler.getCompletedFuture().get();
    
    
    // shut down the client and server
    lowLevelClient.stop();
    server.stop();
}
 
开发者ID:grro,项目名称:http2,代码行数:49,代码来源:LowLevelHttp2ClientTest.java

示例6: pushApiTest

@Test
public void pushApiTest() throws Exception {
    
    // start the test server
    class MyServlet extends HttpServlet { 
        
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            Request jettyRequest = (Request) req;
            
            if (jettyRequest.getRequestURI().equals("/myrichpage.html") && jettyRequest.isPushSupported()) {
                jettyRequest.getPushBuilder()    
                            .path("/pictures/logo.jpg")
                            .push();
            }
            
            
            if (jettyRequest.getRequestURI().equals("/myrichpage.html")) {
                resp.getWriter().write("<html> <header> ...");
            } else {
                resp.getWriter().write("���� ?JFIF   d d  �� ?Ducky  ?   P  �...");
            }
        }
    };
    
    WebServer server = WebServer.servlet(new MyServlet())
                                .start();

    
    

    // create a low-level jetty HTTP/2 client
    HTTP2Client lowLevelClient = new HTTP2Client();
    lowLevelClient.start();
    
    
    
    // create a new session which will open a (multiplexed) connection to the server  
    FuturePromise<Session> sessionFuture = new FuturePromise<>();
    lowLevelClient.connect(new InetSocketAddress("localhost", server.getLocalport()), new Session.Listener.Adapter(), sessionFuture);
    Session session = sessionFuture.get();
    
    // create the header frame
    MetaData.Request metaData = new MetaData.Request("GET", HttpScheme.HTTP, new HostPortHttpField("localhost:" + server.getLocalport()), "/myrichpage.html", HttpVersion.HTTP_2, new HttpFields());
    HeadersFrame frame = new HeadersFrame(1, metaData, null, true);

    // ... and perform the http transaction
    PrintingFramesHandler framesHandler = new PrintingFramesHandler();
    session.newStream(frame, new Promise.Adapter<Stream>(), framesHandler);

    
    
    
    // wait until response is received (PrintingFramesHandler will write the response frame to console) 
    framesHandler.getCompletedFuture().get();
    
    
    // shut down the client and server
    lowLevelClient.stop();
    server.stop();
}
 
开发者ID:grro,项目名称:http2,代码行数:61,代码来源:Http2PushTest.java


注:本文中的org.eclipse.jetty.http.HttpScheme.HTTP属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。