WebServiceClient { public <T> Object execute(HTTPMethod method, String path, Class<T> requestBeanClass, T requestBean, Type responseType) { var request = new HTTPRequest(method, serviceURL + path); request.accept(ContentType.APPLICATION_JSON); linkContext(request); if (requestBeanClass != null) { putRequestBean(request, requestBeanClass, requestBean); } if (interceptor != null) { LOGGER.debug("interceptor={}", interceptor.getClass().getCanonicalName()); interceptor.onRequest(request); } HTTPResponse response = httpClient.execute(request); if (interceptor != null) { interceptor.onResponse(response); } validateResponse(response); try { return reader.fromJSON(responseType, response.body); } catch (IOException e) { throw new UncheckedIOException("failed to deserialize remote service response, responseType=" + responseType.getTypeName(), e); } } WebServiceClient(String serviceURL, HTTPClient httpClient, RequestBeanWriter writer, ResponseBeanReader reader); Object execute(HTTPMethod method, String path, Class<T> requestBeanClass, T requestBean, Type responseType); void intercept(WebServiceClientInterceptor interceptor); void logCallWebService(String method); static final String USER_AGENT; }
@Test void execute() { HTTPResponse response = new HTTPResponse(200, Map.of(), new byte[0]); when(httpClient.execute(any())).thenReturn(response); var request = new TestWebService.TestRequest(); request.stringField = "12345"; Object result = webServiceClient.execute(HTTPMethod.PUT, "/api", TestWebService.TestRequest.class, request, void.class); assertThat(result).isNull(); }