本文整理汇总了Java中org.eclipse.jetty.server.Request类的典型用法代码示例。如果您正苦于以下问题:Java Request类的具体用法?Java Request怎么用?Java Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于org.eclipse.jetty.server包,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWithEscapedMappedQueryParams
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
/**
* Verify GET with escaped query parameters
*
* @throws Exception
*/
@Test
public void getWithEscapedMappedQueryParams() throws Exception {
Map<String, String> inputParams = new HashMap<String, String>();
inputParams.put("name", "us er");
inputParams.put("number", "100");
final Map<String, String> outputParams = new HashMap<String, String>();
final AtomicReference<String> method = new AtomicReference<String>();
handler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
method.set(request.getMethod());
outputParams.put("name", request.getParameter("name"));
outputParams.put("number", request.getParameter("number"));
response.setStatus(HTTP_OK);
}
};
HttpRequest request = get(url, inputParams, true);
assertTrue(request.ok());
assertEquals("GET", method.get());
assertEquals("us er", outputParams.get("name"));
assertEquals("100", outputParams.get("number"));
}
示例2: putWithVarargsQueryParams
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
/**
* Verify PUT with query parameters
*
* @throws Exception
*/
@Test
public void putWithVarargsQueryParams() throws Exception {
final Map<String, String> outputParams = new HashMap<String, String>();
final AtomicReference<String> method = new AtomicReference<String>();
handler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
method.set(request.getMethod());
outputParams.put("name", request.getParameter("name"));
outputParams.put("number", request.getParameter("number"));
response.setStatus(HTTP_OK);
}
};
HttpRequest request = put(url, false, "name", "user", "number", "100");
assertTrue(request.ok());
assertEquals("PUT", method.get());
assertEquals("user", outputParams.get("name"));
assertEquals("100", outputParams.get("number"));
}
示例3: sendHeadersWithoutCode
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
/**
* Verify data is send when receiving response headers without first calling
* {@link HttpRequest#code()}
*
* @throws Exception
*/
@Test
public void sendHeadersWithoutCode() throws Exception {
final AtomicReference<String> body = new AtomicReference<String>();
handler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
body.set(new String(read()));
response.setHeader("h1", "v1");
response.setHeader("h2", "v2");
response.setStatus(HTTP_OK);
}
};
HttpRequest request = post(url).ignoreCloseExceptions(false);
Map<String, List<String>> headers = request.send("hello").headers();
assertEquals("v1", headers.get("h1").get(0));
assertEquals("v2", headers.get("h2").get(0));
assertEquals("hello", body.get());
}
示例4: postWithMappedQueryParams
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
/**
* Verify POST with query parameters
*
* @throws Exception
*/
@Test
public void postWithMappedQueryParams() throws Exception {
Map<String, String> inputParams = new HashMap<String, String>();
inputParams.put("name", "user");
inputParams.put("number", "100");
final Map<String, String> outputParams = new HashMap<String, String>();
final AtomicReference<String> method = new AtomicReference<String>();
handler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
method.set(request.getMethod());
outputParams.put("name", request.getParameter("name"));
outputParams.put("number", request.getParameter("number"));
response.setStatus(HTTP_OK);
}
};
HttpRequest request = post(url, inputParams, false);
assertTrue(request.ok());
assertEquals("POST", method.get());
assertEquals("user", outputParams.get("name"));
assertEquals("100", outputParams.get("number"));
}
示例5: stats
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
@Test
void stats() throws IOException, ServletException {
Request baseReq = mock(Request.class);
HttpChannelState s = new HttpChannelState(null){};
when(baseReq.getHttpChannelState()).thenReturn(s);
Response resp = mock(Response.class);
when(baseReq.getResponse()).thenReturn(resp);
when(resp.getContentCount()).thenReturn(772L);
handler.handle("/testUrl", baseReq, new MockHttpServletRequest(), new MockHttpServletResponse());
assertThat(registry.mustFind("jetty.requests").functionTimer().count()).isEqualTo(1L);
assertThat(registry.mustFind("jetty.responses.size").functionCounter().count()).isEqualTo(772.0);
}
示例6: handle
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// invoke
RpcResponse rpcResponse = doInvoke(request);
// serialize response
byte[] responseBytes = HessianSerializer.serialize(rpcResponse);
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
OutputStream out = response.getOutputStream();
out.write(responseBytes);
out.flush();
}
示例7: getWithEscapedVarargsQueryParams
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
/**
* Verify GET with escaped query parameters
*
* @throws Exception
*/
@Test
public void getWithEscapedVarargsQueryParams() throws Exception {
final Map<String, String> outputParams = new HashMap<String, String>();
final AtomicReference<String> method = new AtomicReference<String>();
handler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
method.set(request.getMethod());
outputParams.put("name", request.getParameter("name"));
outputParams.put("number", request.getParameter("number"));
response.setStatus(HTTP_OK);
}
};
HttpRequest request = get(url, true, "name", "us er", "number", "100");
assertTrue(request.ok());
assertEquals("GET", method.get());
assertEquals("us er", outputParams.get("name"));
assertEquals("100", outputParams.get("number"));
}
示例8: getParameters
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
/**
* Get header parameter values
*
* @throws Exception
*/
@Test
public void getParameters() throws Exception {
handler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
response.setStatus(HTTP_OK);
response.setHeader("a", "value;b=c;d=e");
}
};
HttpRequest request = get(url);
assertTrue(request.ok());
Map<String, String> params = request.parameters("a");
assertNotNull(params);
assertEquals(2, params.size());
assertEquals("c", params.get("b"));
assertEquals("e", params.get("d"));
}
示例9: getUrlEmpty
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
/**
* Make a GET request with an empty body response
*
* @throws Exception
*/
@Test
public void getUrlEmpty() throws Exception {
final AtomicReference<String> method = new AtomicReference<String>();
handler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
method.set(request.getMethod());
response.setStatus(HTTP_OK);
}
};
HttpRequest request = get(new URL(url));
assertNotNull(request.getConnection());
int code = request.code();
assertTrue(request.ok());
assertFalse(request.created());
assertFalse(request.noContent());
assertFalse(request.badRequest());
assertFalse(request.serverError());
assertFalse(request.notFound());
assertEquals("GET", method.get());
assertEquals("OK", request.message());
assertEquals(HTTP_OK, code);
assertEquals("", request.body());
}
示例10: putWithEscapedMappedQueryParams
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
/**
* Verify PUT with escaped query parameters
*
* @throws Exception
*/
@Test
public void putWithEscapedMappedQueryParams() throws Exception {
Map<String, String> inputParams = new HashMap<String, String>();
inputParams.put("name", "us er");
inputParams.put("number", "100");
final Map<String, String> outputParams = new HashMap<String, String>();
final AtomicReference<String> method = new AtomicReference<String>();
handler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
method.set(request.getMethod());
outputParams.put("name", request.getParameter("name"));
outputParams.put("number", request.getParameter("number"));
response.setStatus(HTTP_OK);
}
};
HttpRequest request = put(url, inputParams, true);
assertTrue(request.ok());
assertEquals("PUT", method.get());
assertEquals("us er", outputParams.get("name"));
assertEquals("100", outputParams.get("number"));
}
示例11: postWithVaragsQueryParams
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
/**
* Verify POST with query parameters
*
* @throws Exception
*/
@Test
public void postWithVaragsQueryParams() throws Exception {
final Map<String, String> outputParams = new HashMap<String, String>();
final AtomicReference<String> method = new AtomicReference<String>();
handler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
method.set(request.getMethod());
outputParams.put("name", request.getParameter("name"));
outputParams.put("number", request.getParameter("number"));
response.setStatus(HTTP_OK);
}
};
HttpRequest request = post(url, false, "name", "user", "number", "100");
assertTrue(request.ok());
assertEquals("POST", method.get());
assertEquals("user", outputParams.get("name"));
assertEquals("100", outputParams.get("number"));
}
示例12: getUrlEncodedWithUnicode
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
/**
* Make a GET request with a URL that needs encoding
*
* @throws Exception
*/
@Test
public void getUrlEncodedWithUnicode() throws Exception {
String unencoded = "/\u00DF";
final AtomicReference<String> path = new AtomicReference<String>();
handler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
path.set(request.getPathInfo());
response.setStatus(HTTP_OK);
}
};
HttpRequest request = get(encode(url + unencoded));
assertTrue(request.ok());
assertEquals(unencoded, path.get());
}
示例13: getUrlEncodedWithPercent
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
/**
* Make a GET request with a URL that needs encoding
*
* @throws Exception
*/
@Test
public void getUrlEncodedWithPercent() throws Exception {
String unencoded = "/%";
final AtomicReference<String> path = new AtomicReference<String>();
handler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
path.set(request.getPathInfo());
response.setStatus(HTTP_OK);
}
};
HttpRequest request = get(encode(url + unencoded));
assertTrue(request.ok());
assertEquals(unencoded, path.get());
}
示例14: getEmptyParameters
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
/**
* Get header parameter value
*
* @throws Exception
*/
@Test
public void getEmptyParameters() throws Exception {
handler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
response.setStatus(HTTP_OK);
response.setHeader("a", "b;");
}
};
HttpRequest request = get(url);
assertTrue(request.ok());
assertNull(request.parameter("a", "c"));
assertTrue(request.parameters("a").isEmpty());
}
示例15: handle
import org.eclipse.jetty.server.Request; //导入依赖的package包/类
public void handle(String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
String header = request.getHeader("Authorization");
if(header == null || !header.equals(authenticationHeader)) {
response.addHeader("WWW-Authenticate", "Basic");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.setContentType("text/plain; charset=utf-8");
PrintWriter out = response.getWriter();
out.println("Login to access API");
baseRequest.setHandled(true);
}
}