@Test public void returnsResponses() throws Exception { final Channel server = serve(port, new HttpObject("/some/resource/with/headers") { @Override public Response get(Request req) { return OK(Text("You GET it"), new GenericHeaderField("a-custom-header-name", "a-custom-header-value")); } }); try { final HttpClient testSubject = new ApacheCommons4xHttpClient(); final Response response = testSubject .resource("http: .get(); assertEquals(ResponseCode.OK, response.code()); assertEquals("You GET it", HttpObjectAssert.bodyOf(response).asString()); assertEquals("text/plain; charset=utf-8", response.representation().contentType().toLowerCase()); assertEquals( "a-custom-header-value", findByName("a-custom-header-name", response.header()).value()); } finally { server.close(); } }
@Override public RemoteObject resource(final String uri) { return new RemoteObject() { @Override public Response trace(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "trace", uri); } @Override public Response put(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "put", uri); } @Override public Response post(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "post", uri); } @Override public Response patch(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "patch", uri); } @Override public Response options(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "options", uri); } @Override public Response head(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "head", uri); } @Override public Response get(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "get", uri); } @Override public Response delete(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "delete", uri); } }; }
ApacheCommons4xHttpClient implements HttpClient { @Override public RemoteObject resource(final String uri) { return new RemoteObject() { @Override public Response trace(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "trace", uri); } @Override public Response put(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "put", uri); } @Override public Response post(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "post", uri); } @Override public Response patch(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "patch", uri); } @Override public Response options(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "options", uri); } @Override public Response head(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "head", uri); } @Override public Response get(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "get", uri); } @Override public Response delete(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "delete", uri); } }; } }
ApacheCommons4xHttpClient implements HttpClient { @Override public RemoteObject resource(final String uri) { return new RemoteObject() { @Override public Response trace(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "trace", uri); } @Override public Response put(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "put", uri); } @Override public Response post(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "post", uri); } @Override public Response patch(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "patch", uri); } @Override public Response options(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "options", uri); } @Override public Response head(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "head", uri); } @Override public Response get(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "get", uri); } @Override public Response delete(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "delete", uri); } }; } ApacheCommons4xHttpClient();  ApacheCommons4xHttpClient(org.apache.http.client.HttpClient client); }
ApacheCommons4xHttpClient implements HttpClient { @Override public RemoteObject resource(final String uri) { return new RemoteObject() { @Override public Response trace(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "trace", uri); } @Override public Response put(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "put", uri); } @Override public Response post(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "post", uri); } @Override public Response patch(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "patch", uri); } @Override public Response options(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "options", uri); } @Override public Response head(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "head", uri); } @Override public Response get(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "get", uri); } @Override public Response delete(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "delete", uri); } }; } ApacheCommons4xHttpClient();  ApacheCommons4xHttpClient(org.apache.http.client.HttpClient client); @Override RemoteObject resource(final String uri); }
ApacheCommons4xHttpClient implements HttpClient { @Override public RemoteObject resource(final String uri) { return new RemoteObject() { @Override public Response trace(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "trace", uri); } @Override public Response put(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "put", uri); } @Override public Response post(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "post", uri); } @Override public Response patch(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "patch", uri); } @Override public Response options(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "options", uri); } @Override public Response head(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "head", uri); } @Override public Response get(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "get", uri); } @Override public Response delete(Representation r, String query, HeaderField ... fields) { return doit(query, r, fields, "delete", uri); } }; } ApacheCommons4xHttpClient();  ApacheCommons4xHttpClient(org.apache.http.client.HttpClient client); @Override RemoteObject resource(final String uri);  }