當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。