本文整理匯總了Java中org.eclipse.jetty.http.HttpVersion.HTTP_2屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpVersion.HTTP_2屬性的具體用法?Java HttpVersion.HTTP_2怎麽用?Java HttpVersion.HTTP_2使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.eclipse.jetty.http.HttpVersion
的用法示例。
在下文中一共展示了HttpVersion.HTTP_2屬性的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: runRequest
/**
* 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,代碼行數:32,代碼來源:AppEngineAuthenticationTest.java
示例2: runRequest2
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,代碼行數:22,代碼來源:AppEngineAuthenticationTest.java
示例3: testUserRequired_NoUser
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,代碼行數:18,代碼來源:AppEngineAuthenticationTest.java
示例4: testUserRequired_PreserveQueryParams
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,代碼行數:25,代碼來源:AppEngineAuthenticationTest.java
示例5: testAdminRequired_NoUser
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,代碼行數:18,代碼來源:AppEngineAuthenticationTest.java
示例6: performHttpRequestReceivePush
/**
* 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();
}
示例7: main
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();
}
示例8: 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();
}
示例9: 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();
}