use of core.framework.http.HTTPRequest in project core-ng-project by neowu.
the class WebServiceClient method execute.
// used by generated code, must be public
public Object execute(HTTPMethod method, String serviceURL, Type requestType, Object requestBean, Type responseType) {
HTTPRequest request = new HTTPRequest(method, serviceURL);
request.accept(ContentType.APPLICATION_JSON);
request.header(HTTPServerHandler.HEADER_CLIENT.toString(), logManager.appName);
linkContext(request);
if (requestType != null) {
addRequestBean(request, method, requestType, requestBean);
}
if (interceptor != null) {
logger.debug("intercept request, interceptor={}", interceptor.getClass().getCanonicalName());
interceptor.intercept(request);
}
HTTPResponse response = httpClient.execute(request);
validateResponse(response);
if (void.class != responseType) {
return JSONMapper.fromJSON(responseType, response.body());
} else {
return null;
}
}
use of core.framework.http.HTTPRequest in project core-ng-project by neowu.
the class WebServiceClientTest method addQueryParams.
@Test
void addQueryParams() {
HTTPRequest request = new HTTPRequest(HTTPMethod.POST, "/");
Map<String, String> params = Maps.newLinkedHashMap();
params.put("p1", "v1");
params.put("p2", null);
params.put("p3", "v3");
webServiceClient.addQueryParams(request, params);
assertEquals(2, request.params().size());
assertEquals("v1", request.params().get("p1"));
assertEquals("v3", request.params().get("p3"));
}
use of core.framework.http.HTTPRequest in project core-ng-project by neowu.
the class WebServiceClientTest method addRequestBeanWithPost.
@Test
void addRequestBeanWithPost() {
HTTPRequest request = new HTTPRequest(HTTPMethod.POST, "/");
TestWebService.TestRequest requestBean = new TestWebService.TestRequest();
requestBean.stringField = "123value";
webServiceClient.addRequestBean(request, HTTPMethod.POST, TestWebService.TestRequest.class, requestBean);
assertArrayEquals(JSONMapper.toJSON(requestBean), request.body());
assertEquals(ContentType.APPLICATION_JSON, request.contentType());
}
use of core.framework.http.HTTPRequest in project core-ng-project by neowu.
the class WebServiceClientTest method addRequestBeanWithGet.
@Test
void addRequestBeanWithGet() {
HTTPRequest request = new HTTPRequest(HTTPMethod.POST, "/");
TestWebService.TestSearchRequest requestBean = new TestWebService.TestSearchRequest();
requestBean.intField = 23;
webServiceClient.addRequestBean(request, HTTPMethod.GET, TestWebService.TestSearchRequest.class, requestBean);
assertEquals(1, request.params().size());
assertEquals("23", request.params().get("int_field"));
}
use of core.framework.http.HTTPRequest in project core-ng-project by neowu.
the class HTTPClientImplTest method httpRequest.
@Test
void httpRequest() {
HTTPRequest request = new HTTPRequest(HTTPMethod.POST, "http://localhost/uri");
request.addParam("query", "value");
request.accept(ContentType.APPLICATION_JSON);
request.body("text", ContentType.TEXT_PLAIN);
HttpUriRequest httpRequest = httpClient.httpRequest(request);
assertEquals("http://localhost/uri?query=value", httpRequest.getURI().toString());
assertEquals(ContentType.APPLICATION_JSON.toString(), httpRequest.getFirstHeader(HTTPHeaders.ACCEPT).getValue());
}
Aggregations