• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Session类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.jetty.http2.api.Session的典型用法代码示例。如果您正苦于以下问题:Java Session类的具体用法?Java Session怎么用?Java Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Session类属于org.eclipse.jetty.http2.api包,在下文中一共展示了Session类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: setup

import org.eclipse.jetty.http2.api.Session; //导入依赖的package包/类
@Before
  public void setup() {
headerManagerMock = Mockito.mock(HeaderManager.class);
urlMock = Mockito.mock(URL.class);
cookieManagerMock = Mockito.mock(CookieManager.class);
sessionMock = Mockito.mock(Session.class);
      try {
	http2Connection = new HTTP2Connection("1", true);
} catch (Exception e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
  }
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:14,代码来源:HTTP2ConnectionTest.java


示例2: performHttpRequestReceivePush

import org.eclipse.jetty.http2.api.Session; //导入依赖的package包/类
/**
 * Perform an http request and wait for a possibly incoming push promise.
 *
 * @param host           the hostname
 * @param port           the port
 * @param path           the request path
 * @param sessionPromise the session promise object
 * @param phaser         the phaser
 * @throws Exception may occur when client is started or stopped
 */
public void performHttpRequestReceivePush(
    String host, int port, String path,
    FuturePromise<Session> sessionPromise, Phaser phaser)
    throws Exception {

  http2Client.addBean(sslContextFactory);
  http2Client.start();

  http2Client.connect(sslContextFactory, new InetSocketAddress(host, port),
      new ServerSessionListener.Adapter(), sessionPromise);
  Session session = sessionPromise.get(5, TimeUnit.SECONDS);

  HttpFields requestFields = new HttpFields();
  requestFields.put("User-Agent", http2Client
      .getClass()
      .getName() + "/" + Jetty.VERSION);
  MetaData.Request metaData =
      new MetaData.Request("GET", new HttpURI("https://" + host + ":" + port + path),
          HttpVersion.HTTP_2, requestFields);
  HeadersFrame headersFrame = new HeadersFrame(metaData, null, true);
  session.newStream(headersFrame, new Promise.Adapter<>(), new StreamListener(phaser));

  phaser.awaitAdvanceInterruptibly(phaser.arrive(), 5, TimeUnit.SECONDS);

  http2Client.stop();
}
 
开发者ID:janweinschenker,项目名称:servlet4-demo,代码行数:37,代码来源:JettyClientDemo.java


示例3: setUp

import org.eclipse.jetty.http2.api.Session; //导入依赖的package包/类
@Before
public void setUp() {
  httpClient = mock(HttpClient.class);
  HTTP2Client http2Client = mock(HTTP2Client.class);
  contentResponse = mock(ContentResponse.class);
  request = mock(Request.class);
  SslContextFactory sslContextFactory = mock(SslContextFactory.class);
  session = mock(Session.class);
  phaser = mock(Phaser.class);

  sut = new JettyClientDemo(httpClient, http2Client, sslContextFactory);
}
 
开发者ID:janweinschenker,项目名称:servlet4-demo,代码行数:13,代码来源:JettyClientDemoTest.java


示例4: connect

import org.eclipse.jetty.http2.api.Session; //导入依赖的package包/类
private void connect() throws Exception {
    this.http2Client = new HTTP2Client();
    this.http2Client.start();

    FuturePromise<Session> sessionPromise = new FuturePromise<>();
    this.http2Client.connect(sslContextFactory, new InetSocketAddress(APNS_HOST, APNS_PORT), new ServerSessionListener.Adapter(), sessionPromise);
    // Obtain the client Session object.
    session = sessionPromise.get(connectTimeout, TimeUnit.SECONDS);
    createTime = System.currentTimeMillis();
    sendCount = 0L;
    log.info("{} APNS Client build", clientName);
}
 
开发者ID:linmingchang,项目名称:java-apns2,代码行数:13,代码来源:ApnsHttp2ClientImpl.java


示例5: setSession

import org.eclipse.jetty.http2.api.Session; //导入依赖的package包/类
public void setSession(Session session){
	this.session = session;
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:4,代码来源:HTTP2Connection.java


示例6: connect

import org.eclipse.jetty.http2.api.Session; //导入依赖的package包/类
public void connect(String hostname, int port) throws InterruptedException, ExecutionException, TimeoutException {
	FuturePromise<Session> sessionFuture = new FuturePromise<>();
	this.client.connect(this.sslContextFactory, new InetSocketAddress(hostname, port), this.http2SettingsHandler,
			sessionFuture);
	setSession(sessionFuture.get(10, TimeUnit.SECONDS));
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:7,代码来源:HTTP2Connection.java


示例7: onSettings

import org.eclipse.jetty.http2.api.Session; //导入依赖的package包/类
@Override
public void onSettings(Session session, SettingsFrame frame) {
	super.onSettings(session, frame);
	connection.setFrameSize(frame.MAX_FRAME_SIZE);
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:6,代码来源:HTTP2SettingsHandler.java


示例8: main

import org.eclipse.jetty.http2.api.Session; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    long startTime = System.nanoTime();

    // Create and start HTTP2Client.
    HTTP2Client client = new HTTP2Client();
    SslContextFactory sslContextFactory = new SslContextFactory(true);
    client.addBean(sslContextFactory);
    client.start();

    // Connect to host.
    String host = "localhost";
    int port = 8443;

    FuturePromise<Session> sessionPromise = new FuturePromise<>();
    client.connect(sslContextFactory, new InetSocketAddress(host, port), new ServerSessionListener.Adapter(), sessionPromise);

    // Obtain the client Session object.
    Session session = sessionPromise.get(5, TimeUnit.SECONDS);

    // Prepare the HTTP request headers.
    HttpFields requestFields = new HttpFields();
    requestFields.put("User-Agent", client.getClass().getName() + "/" + Jetty.VERSION);
    // Prepare the HTTP request object.
    MetaData.Request request = new MetaData.Request("GET", new HttpURI("https://" + host + ":" + port + "/"), HttpVersion.HTTP_2, requestFields);
    // Create the HTTP/2 HEADERS frame representing the HTTP request.
    HeadersFrame headersFrame = new HeadersFrame(request, null, true);

    // Prepare the listener to receive the HTTP response frames.
    Stream.Listener responseListener = new Stream.Listener.Adapter()
    {
        @Override
        public void onData(Stream stream, DataFrame frame, Callback callback)
        {
            byte[] bytes = new byte[frame.getData().remaining()];
            frame.getData().get(bytes);
            int duration = (int) TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime);
            System.out.println("After " + duration + " seconds: " + new String(bytes));
            callback.succeeded();
        }
    };

    session.newStream(headersFrame, new FuturePromise<>(), responseListener);
    session.newStream(headersFrame, new FuturePromise<>(), responseListener);
    session.newStream(headersFrame, new FuturePromise<>(), responseListener);

    Thread.sleep(TimeUnit.SECONDS.toMillis(20));

    client.stop();
}
 
开发者ID:fstab,项目名称:http2-examples,代码行数:50,代码来源:JettyClientExample.java


示例9: lowLevelApiTest

import org.eclipse.jetty.http2.api.Session; //导入依赖的package包/类
@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,代码行数:50,代码来源:LowLevelHttp2ClientTest.java


示例10: pushApiTest

import org.eclipse.jetty.http2.api.Session; //导入依赖的package包/类
@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,代码行数:62,代码来源:Http2PushTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StyleSheet类代码示例发布时间:2022-05-23
下一篇:
Java DefaultModelBuilder类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap