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


Java HttpCoreContext.create方法代码示例

本文整理汇总了Java中org.apache.http.protocol.HttpCoreContext.create方法的典型用法代码示例。如果您正苦于以下问题:Java HttpCoreContext.create方法的具体用法?Java HttpCoreContext.create怎么用?Java HttpCoreContext.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.protocol.HttpCoreContext的用法示例。


在下文中一共展示了HttpCoreContext.create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testIntQueryParam

import org.apache.http.protocol.HttpCoreContext; //导入方法依赖的package包/类
@Test
public void testIntQueryParam() throws Exception {
    MyController controller = new MyController();

    ReflectionControllerRequestHandler handler = new ControllerBuilder(new GsonBuilder().create())
            .addController(controller)
            .withPathPrefix("/")
            .create();


    HttpCoreContext context = HttpCoreContext.create();
    HttpRequest request = new BasicHttpRequest("GET", "/stuff/testInt?apples=5&bananas=4.3");
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, ""));

    handler.handle(request, response, context);

    assertTrue(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK);
}
 
开发者ID:dinocore1,项目名称:MiniWeb,代码行数:19,代码来源:ReflectionControllerTest.java

示例2: testJsonBody

import org.apache.http.protocol.HttpCoreContext; //导入方法依赖的package包/类
@Test
public void testJsonBody() throws Exception {
    MyController controller = new MyController();

    ReflectionControllerRequestHandler handler = new ControllerBuilder(new GsonBuilder().create())
            .addController(controller)
            .withPathPrefix("/")
            .create();


    HttpCoreContext context = HttpCoreContext.create();
    BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("PUT", "/stuff/putthis");
    request.setHeader("Content-Type", "application/json");
    request.setEntity(new StringEntity("{ \"name\": \"paul\" }"));


    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, ""));

    handler.handle(request, response, context);

    assertTrue(response.getStatusLine().getStatusCode() == 200);
    String resultBody = EntityUtils.toString(response.getEntity());
    assertTrue("itworked".equals(resultBody));
}
 
开发者ID:dinocore1,项目名称:MiniWeb,代码行数:25,代码来源:ReflectionControllerTest.java

示例3: testJsonResponse

import org.apache.http.protocol.HttpCoreContext; //导入方法依赖的package包/类
@Test
public void testJsonResponse() throws Exception {
    MyController controller = new MyController();

    ReflectionControllerRequestHandler handler = new ControllerBuilder(new GsonBuilder().create())
            .addController(controller)
            .withPathPrefix("/")
            .create();


    HttpCoreContext context = HttpCoreContext.create();
    BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("GET", "/stuff/getjson");
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, ""));

    handler.handle(request, response, context);

    assertTrue(response.getStatusLine().getStatusCode() == 200);
    String resultBody = EntityUtils.toString(response.getEntity());

    Gson gson = new GsonBuilder().create();
    MyController.TestObj retobj = gson.fromJson(resultBody, MyController.TestObj.class);

    assertNotNull(retobj);
    assertEquals("Jack", retobj.name);
}
 
开发者ID:dinocore1,项目名称:MiniWeb,代码行数:26,代码来源:ReflectionControllerTest.java

示例4: createHttpContext

import org.apache.http.protocol.HttpCoreContext; //导入方法依赖的package包/类
private static HttpContext createHttpContext( final Socket socket ) {
    final HttpContext httpContext = HttpCoreContext.create();

    final Protocol protocol;
    if( !Inet.isLocalAddress( socket.getInetAddress() ) ) protocol = Protocol.LOCAL;
    else protocol = SSLSocket.class.isInstance( socket ) ? Protocol.HTTPS : Protocol.HTTP;

    httpContext.setAttribute( "protocol", protocol );

    return httpContext;
}
 
开发者ID:oaplatform,项目名称:oap,代码行数:12,代码来源:Server.java

示例5: testJsonWriterResponse

import org.apache.http.protocol.HttpCoreContext; //导入方法依赖的package包/类
@Test
public void testJsonWriterResponse() throws Exception {


    MyController controller = new MyController();

    ReflectionControllerRequestHandler handler = new ControllerBuilder(new GsonBuilder().create())
            .addController(controller)
            .withPathPrefix("/")
            .create();


    HttpCoreContext context = HttpCoreContext.create();
    BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("GET", "/stuff/getjsonstream");
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, ""));

    handler.handle(request, response, context);

    assertTrue(response.getStatusLine().getStatusCode() == 200);
    String resultBody = EntityUtils.toString(response.getEntity());

    Gson gson = new GsonBuilder().create();
    JsonElement retobj = gson.fromJson(resultBody, JsonElement.class);
    assertNotNull(retobj);
    assertTrue(retobj.isJsonObject());
    JsonObject obj = retobj.getAsJsonObject();
    JsonElement value = obj.get("hello");
    assertNotNull(value);
    assertTrue(value.isJsonPrimitive() && value.getAsJsonPrimitive().isString());
    String world = value.getAsString();
    assertEquals("world", world);

}
 
开发者ID:dinocore1,项目名称:MiniWeb,代码行数:34,代码来源:ReflectionControllerTest.java

示例6: testStringQueryParam

import org.apache.http.protocol.HttpCoreContext; //导入方法依赖的package包/类
@Test
public void testStringQueryParam() throws Exception {

    MyController controller = new MyController();

    ReflectionControllerRequestHandler handler = new ControllerBuilder(new GsonBuilder().create())
        .addController(controller)
        .withPathPrefix("/")
        .create();


    HttpCoreContext context = HttpCoreContext.create();
    HttpRequest request = new BasicHttpRequest("GET", "/stuff/test?param1=itworked&param2=rad&param1=cool");
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, ""));

    handler.handle(request, response, context);

    assertTrue(response.getStatusLine().getStatusCode() == 200);
    String resultBody = EntityUtils.toString(response.getEntity());
    assertTrue("itworked".equals(resultBody));

}
 
开发者ID:dinocore1,项目名称:MiniWeb,代码行数:23,代码来源:ReflectionControllerTest.java

示例7: testPathVar

import org.apache.http.protocol.HttpCoreContext; //导入方法依赖的package包/类
@Test
public void testPathVar() throws Exception {
    MyController controller = new MyController();

    ReflectionControllerRequestHandler handler = new ControllerBuilder(new GsonBuilder().create())
            .addController(controller)
            .withPathPrefix("/")
            .create();


    HttpCoreContext context = HttpCoreContext.create();
    BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("GET", "/stuff/request/28");
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, ""));

    handler.handle(request, response, context);

    assertTrue(response.getStatusLine().getStatusCode() == 200);
    String resultBody = EntityUtils.toString(response.getEntity());
    assertEquals("28", resultBody);



}
 
开发者ID:dinocore1,项目名称:MiniWeb,代码行数:24,代码来源:ReflectionControllerTest.java

示例8: testInheritController

import org.apache.http.protocol.HttpCoreContext; //导入方法依赖的package包/类
@Test
public void testInheritController() throws Exception {

    MyInheritController controller = new MyInheritController();

    ReflectionControllerRequestHandler handler = new ControllerBuilder(new GsonBuilder().create())
            .addController(controller)
            .withPathPrefix("/")
            .create();


    HttpCoreContext context = HttpCoreContext.create();
    BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("PUT", "/stuff/putthis");
    request.setHeader("Content-Type", "application/json");
    request.setEntity(new StringEntity("{ \"name\": \"paul\" }"));


    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, ""));

    handler.handle(request, response, context);

    assertTrue(response.getStatusLine().getStatusCode() == 200);
    String resultBody = EntityUtils.toString(response.getEntity());
    assertTrue("itworked".equals(resultBody));
}
 
开发者ID:dinocore1,项目名称:MiniWeb,代码行数:26,代码来源:ReflectionControllerTest.java


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