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


Java Request类代码示例

本文整理汇总了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"));
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:29,代码来源:HttpRequestTest.java

示例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"));
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:26,代码来源:HttpRequestTest.java

示例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());
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:27,代码来源:HttpRequestTest.java

示例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"));
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:29,代码来源:HttpRequestTest.java

示例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);
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:15,代码来源:JettyStatisticsMetricsTest.java

示例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();
	
}
 
开发者ID:kevinKaiF,项目名称:xxl-job,代码行数:19,代码来源:JettyServerHandler.java

示例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"));
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:26,代码来源:HttpRequestTest.java

示例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"));
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:24,代码来源:HttpRequestTest.java

示例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());
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:31,代码来源:HttpRequestTest.java

示例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"));
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:29,代码来源:HttpRequestTest.java

示例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"));
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:26,代码来源:HttpRequestTest.java

示例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());
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:22,代码来源:HttpRequestTest.java

示例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());
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:22,代码来源:HttpRequestTest.java

示例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());
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:21,代码来源:HttpRequestTest.java

示例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);
    }
}
 
开发者ID:nemec,项目名称:JDHttpAPI,代码行数:17,代码来源:AuthorizationHandler.java


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