本文整理汇总了Java中org.eclipse.jetty.http.MetaData.Request方法的典型用法代码示例。如果您正苦于以下问题:Java MetaData.Request方法的具体用法?Java MetaData.Request怎么用?Java MetaData.Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.http.MetaData
的用法示例。
在下文中一共展示了MetaData.Request方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toRequestMetadata
import org.eclipse.jetty.http.MetaData; //导入方法依赖的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());
}
示例2: runRequest
import org.eclipse.jetty.http.MetaData; //导入方法依赖的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
示例3: runRequest2
import org.eclipse.jetty.http.MetaData; //导入方法依赖的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
示例4: testUserRequired_NoUser
import org.eclipse.jetty.http.MetaData; //导入方法依赖的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
示例5: testUserRequired_PreserveQueryParams
import org.eclipse.jetty.http.MetaData; //导入方法依赖的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
示例6: testAdminRequired_NoUser
import org.eclipse.jetty.http.MetaData; //导入方法依赖的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
示例7: performHttpRequestReceivePush
import org.eclipse.jetty.http.MetaData; //导入方法依赖的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();
}
示例8: main
import org.eclipse.jetty.http.MetaData; //导入方法依赖的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();
}
示例9: push
import org.eclipse.jetty.http.MetaData; //导入方法依赖的package包/类
@Override
public void push(MetaData.Request request) {}
示例10: lowLevelApiTest
import org.eclipse.jetty.http.MetaData; //导入方法依赖的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();
}
示例11: pushApiTest
import org.eclipse.jetty.http.MetaData; //导入方法依赖的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();
}