本文整理汇总了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);
}
示例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));
}
示例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);
}
示例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;
}
示例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);
}
示例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¶m2=rad¶m1=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));
}
示例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);
}
示例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));
}