@Test public void testEmptyProxyPortNumber() throws ODataClientException, MalformedURLException { Properties properties = new Properties(); properties.setProperty(CLIENT_SERVICE_PROXY_PORT, ""); EndpointCaller proxifiedCaller = new TracingEndpointCaller(properties); String response = proxifiedCaller.callEndpoint(emptyMap(), new URL(basePath + RESPONSE)); String result = URLTestUtils.loadTextFile(RESPONSE); assertThat(response, equalTo(result.substring(0, result.lastIndexOf(lineSeparator())))); }
@Override public String callEndpoint(Map<String, String> requestProperties, URL url) throws ODataClientException { LOG.debug("Preparing the call endpoint for given url: {}", url); CloseableHttpResponse closeableResponse = null; try { RequestBuilder requestBuilder = RequestBuilder.get() .setUri(url.toURI()); getRequestHeaders(requestProperties, -1, null, XML).entrySet().stream() .forEach(entry -> requestBuilder.addHeader(entry.getKey(), entry.getValue())); closeableResponse = closeableHttpClient.execute(requestBuilder.build()); String response = EntityUtils.toString(closeableResponse.getEntity(), "UTF-8"); if (closeableResponse.getStatusLine().getStatusCode() >= HTTP_BAD_REQUEST) { throw buildException(response, closeableResponse.getStatusLine().getStatusCode()); } return response; } catch (URISyntaxException e) { throw new ODataClientException(WRONG_URL_MESSAGE, e); } catch (IOException e) { throw new ODataClientRuntimeException(REQUEST_FAILED_MESSAGE + url, e); } finally { closeIfNecessary(closeableResponse); } }
TracingEndpointCaller implements EndpointCaller { @Override public String callEndpoint(Map<String, String> requestProperties, URL url) throws ODataClientException { LOG.debug("Preparing the call endpoint for given url: {}", url); CloseableHttpResponse closeableResponse = null; try { RequestBuilder requestBuilder = RequestBuilder.get() .setUri(url.toURI()); getRequestHeaders(requestProperties, -1, null, XML).entrySet().stream() .forEach(entry -> requestBuilder.addHeader(entry.getKey(), entry.getValue())); closeableResponse = closeableHttpClient.execute(requestBuilder.build()); String response = EntityUtils.toString(closeableResponse.getEntity(), "UTF-8"); if (closeableResponse.getStatusLine().getStatusCode() >= HTTP_BAD_REQUEST) { throw buildException(response, closeableResponse.getStatusLine().getStatusCode()); } return response; } catch (URISyntaxException e) { throw new ODataClientException(WRONG_URL_MESSAGE, e); } catch (IOException e) { throw new ODataClientRuntimeException(REQUEST_FAILED_MESSAGE + url, e); } finally { closeIfNecessary(closeableResponse); } } }
TracingEndpointCaller implements EndpointCaller { @Override public String callEndpoint(Map<String, String> requestProperties, URL url) throws ODataClientException { LOG.debug("Preparing the call endpoint for given url: {}", url); CloseableHttpResponse closeableResponse = null; try { RequestBuilder requestBuilder = RequestBuilder.get() .setUri(url.toURI()); getRequestHeaders(requestProperties, -1, null, XML).entrySet().stream() .forEach(entry -> requestBuilder.addHeader(entry.getKey(), entry.getValue())); closeableResponse = closeableHttpClient.execute(requestBuilder.build()); String response = EntityUtils.toString(closeableResponse.getEntity(), "UTF-8"); if (closeableResponse.getStatusLine().getStatusCode() >= HTTP_BAD_REQUEST) { throw buildException(response, closeableResponse.getStatusLine().getStatusCode()); } return response; } catch (URISyntaxException e) { throw new ODataClientException(WRONG_URL_MESSAGE, e); } catch (IOException e) { throw new ODataClientRuntimeException(REQUEST_FAILED_MESSAGE + url, e); } finally { closeIfNecessary(closeableResponse); } } TracingEndpointCaller(Properties properties); }
TracingEndpointCaller implements EndpointCaller { @Override public String callEndpoint(Map<String, String> requestProperties, URL url) throws ODataClientException { LOG.debug("Preparing the call endpoint for given url: {}", url); CloseableHttpResponse closeableResponse = null; try { RequestBuilder requestBuilder = RequestBuilder.get() .setUri(url.toURI()); getRequestHeaders(requestProperties, -1, null, XML).entrySet().stream() .forEach(entry -> requestBuilder.addHeader(entry.getKey(), entry.getValue())); closeableResponse = closeableHttpClient.execute(requestBuilder.build()); String response = EntityUtils.toString(closeableResponse.getEntity(), "UTF-8"); if (closeableResponse.getStatusLine().getStatusCode() >= HTTP_BAD_REQUEST) { throw buildException(response, closeableResponse.getStatusLine().getStatusCode()); } return response; } catch (URISyntaxException e) { throw new ODataClientException(WRONG_URL_MESSAGE, e); } catch (IOException e) { throw new ODataClientRuntimeException(REQUEST_FAILED_MESSAGE + url, e); } finally { closeIfNecessary(closeableResponse); } } TracingEndpointCaller(Properties properties); @Override String callEndpoint(Map<String, String> requestProperties, URL url); @Override InputStream getInputStream(Map<String, String> requestProperties, URL url); @Override String doPostEntity(Map<String, String> requestProperties, URL url, String body,
                               MediaType contentType, MediaType acceptType); @Override String doPutEntity(Map<String, String> requestProperties, URL url, String body, MediaType type); @Override void doDeleteEntity(Map<String, String> requestProperties, URL url); }
TracingEndpointCaller implements EndpointCaller { @Override public String callEndpoint(Map<String, String> requestProperties, URL url) throws ODataClientException { LOG.debug("Preparing the call endpoint for given url: {}", url); CloseableHttpResponse closeableResponse = null; try { RequestBuilder requestBuilder = RequestBuilder.get() .setUri(url.toURI()); getRequestHeaders(requestProperties, -1, null, XML).entrySet().stream() .forEach(entry -> requestBuilder.addHeader(entry.getKey(), entry.getValue())); closeableResponse = closeableHttpClient.execute(requestBuilder.build()); String response = EntityUtils.toString(closeableResponse.getEntity(), "UTF-8"); if (closeableResponse.getStatusLine().getStatusCode() >= HTTP_BAD_REQUEST) { throw buildException(response, closeableResponse.getStatusLine().getStatusCode()); } return response; } catch (URISyntaxException e) { throw new ODataClientException(WRONG_URL_MESSAGE, e); } catch (IOException e) { throw new ODataClientRuntimeException(REQUEST_FAILED_MESSAGE + url, e); } finally { closeIfNecessary(closeableResponse); } } TracingEndpointCaller(Properties properties); @Override String callEndpoint(Map<String, String> requestProperties, URL url); @Override InputStream getInputStream(Map<String, String> requestProperties, URL url); @Override String doPostEntity(Map<String, String> requestProperties, URL url, String body,
                               MediaType contentType, MediaType acceptType); @Override String doPutEntity(Map<String, String> requestProperties, URL url, String body, MediaType type); @Override void doDeleteEntity(Map<String, String> requestProperties, URL url);  }