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


Java HeadersFrame类代码示例

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


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

示例1: sendMutExc

import org.eclipse.jetty.http2.frames.HeadersFrame; //导入依赖的package包/类
private synchronized void sendMutExc(String method, HeadersFrame headersFrame, FuturePromise<Stream> streamPromise,
		HTTP2StreamHandler http2StreamHandler, DataPostContent dataPostContent, HTTP2SampleResult sampleResult)
		throws Exception {
	session.newStream(headersFrame, streamPromise, http2StreamHandler);
	if (method.equals("POST")) {
		Stream actualStream = streamPromise.get();
		int streamID = actualStream.getId();
		DataCallBack dataCallback = new DataCallBack();
		DataFrame data = new DataFrame(streamID,
				ByteBuffer.wrap(dataPostContent.getPayload(), 0, dataPostContent.getPayload().length), true);
		actualStream.data(data, dataCallback);
		this.addDataCallbackHandler(dataCallback);
		sampleResult.setQueryString(data.toString());// TODO revisar si es este metodo
		// add byte size of the queryString
		sampleResult.setBytes(sampleResult.getBytesAsLong() + (long) sampleResult.getQueryString().length()); 
	}

}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:19,代码来源:HTTP2Connection.java

示例2: setup

import org.eclipse.jetty.http2.frames.HeadersFrame; //导入依赖的package包/类
@Before
public void setup() throws MalformedURLException {
	TestJMeterUtils.createJmeterEnv();
	JMeterUtils.setProperty("HTTPResponse.parsers", "htmlParser");
	JMeterUtils.setProperty("htmlParser.className","org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser");
	JMeterUtils.setProperty("htmlParser.types","text/html application/xhtml+xml application/xml text/xml");
	url = new URL("http://www.tenfieldigital.com.uy");
	http2Connection = Mockito.mock(HTTP2Connection.class);
	stream = Mockito.mock(Stream.class);
	pushPromisFrame = Mockito.mock(PushPromiseFrame.class);
	headersFrame = Mockito.mock(HeadersFrame.class);
	responseMetadata = Mockito.mock(MetaData.Response.class);
	callback = Mockito.mock(Callback.class);
	dataFrame = Mockito.mock(DataFrame.class);
	
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:17,代码来源:HTTP2StreamHandlerTest.java

示例3: performHttpRequestReceivePush

import org.eclipse.jetty.http2.frames.HeadersFrame; //导入依赖的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

示例4: onHeaders

import org.eclipse.jetty.http2.frames.HeadersFrame; //导入依赖的package包/类
@Override
public void onHeaders(Stream stream, HeadersFrame frame) {
  LOG.info(frame);
  if (frame.isEndStream()) {
    phaser.arrive();
  }
}
 
开发者ID:janweinschenker,项目名称:servlet4-demo,代码行数:8,代码来源:StreamListener.java

示例5: setUp

import org.eclipse.jetty.http2.frames.HeadersFrame; //导入依赖的package包/类
@Before
public void setUp() {
  phaser = mock(Phaser.class);
  headersFrame = mock(HeadersFrame.class);
  dataFrame = mock(DataFrame.class);
  stream = mock(Stream.class);
  pushPromiseFrame = mock(PushPromiseFrame.class);
  callback = mock(Callback.class);
  sut = new StreamListener(phaser);

  when(headersFrame.isEndStream()).thenReturn(Boolean.TRUE);
  when(dataFrame.isEndStream()).thenReturn(Boolean.TRUE);
}
 
开发者ID:janweinschenker,项目名称:servlet4-demo,代码行数:14,代码来源:StreamListenerAdapterTest.java

示例6: onHeaders

import org.eclipse.jetty.http2.frames.HeadersFrame; //导入依赖的package包/类
@Override
public void onHeaders(Stream stream, HeadersFrame frame) {

	MetaData.Response responseMetadata = ((MetaData.Response) frame.getMetaData());
	// set status line - header[0] is not the status line...
	String header = responseMetadata.getHttpVersion() + " " + Integer.toString(responseMetadata.getStatus()) + "\n";
	result.setResponseCode(Integer.toString(responseMetadata.getStatus()));
	HttpFields hdrs = new HttpFields();
	for (HttpField h : frame.getMetaData().getFields()) {
		header = header + h.getName() + ": " + h.getValue() + "\n";
		switch (h.getName()) {
		case HTTPConstants.HEADER_CONTENT_TYPE:// TODO adaptar para traducir
												// gzip, etc
		case "content-type":
			result.setContentType(h.getValue());
			result.setEncodingAndType(h.getValue());
			break;
		case HTTPConstants.HEADER_CONTENT_ENCODING:
			result.setDataEncoding(h.getValue());
			break;
		}
		hdrs.add(h);
	}
	header = header + "\n";
	result.setResponseHeaders(header);
	result.setHeadersSize(header.length());
	result.setBytes(result.getBytesAsLong() + result.getHeadersSize()); // add
																		// size
																		// bytes
																		// of
																		// the
																		// header
																		// response
	result.setHttpFieldsResponse(hdrs);
	if (frame.isEndStream()) {
		result.sampleEnd();
		result.setPendingResponse(false);
		completedFuture.complete(null);

	}
	if (!result.isPendingResponse()) {
		// the sample has failed for another reason (eg. timeout)
		result.setResponseHeaders("");
	}
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:46,代码来源:HTTP2StreamHandler.java

示例7: main

import org.eclipse.jetty.http2.frames.HeadersFrame; //导入依赖的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

示例8: onHeaders

import org.eclipse.jetty.http2.frames.HeadersFrame; //导入依赖的package包/类
@Override
public void onHeaders(Stream stream, HeadersFrame frame) {
    System.out.println("[" + frame.getStreamId() + "] HEADERS " + frame.getMetaData().toString());
    frame.getMetaData().getFields().forEach(field -> System.out.println("[" + stream.getId() + "]     " + field.getName() + ": " + field.getValue()));
}
 
开发者ID:grro,项目名称:http2,代码行数:6,代码来源:PrintingFramesHandler.java

示例9: lowLevelApiTest

import org.eclipse.jetty.http2.frames.HeadersFrame; //导入依赖的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.frames.HeadersFrame; //导入依赖的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.frames.HeadersFrame类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。