@Test public void execute() throws IOException, RemoteServerUnavailableException { final int expectedCode = 200; final String expectedMessage = "this is message"; final String expectedEntity = "content"; httpResponse.setStatusCode(expectedCode); HttpGet httpGet = new HttpGet("http: new Expectations(EntityUtils.class) { { EntityUtils.toString(httpResponse.getEntity()); result = expectedEntity; httpResponse.getStatusLine().getStatusCode(); result = expectedCode; httpResponse.getStatusLine().getReasonPhrase(); result = expectedMessage; } }; Response resp = httpHttpTransport.execute(httpGet); assertEquals(resp.getStatusCode(), expectedCode); assertEquals(expectedMessage, resp.getStatusMessage()); assertEquals(expectedEntity, resp.getContent()); }
@Override public Response execute(HttpUriRequest httpRequest) throws RemoteServerUnavailableException { Response resp = new Response(); try { DealHeaderUtil.addDefautHeader(httpRequest); DealHeaderUtil.addAKSKHeader(httpRequest, serviceCombAkSkProperties); HttpResponse httpResponse = httpClient.execute(httpRequest); resp.setStatusCode(httpResponse.getStatusLine().getStatusCode()); resp.setStatusMessage(httpResponse.getStatusLine().getReasonPhrase()); resp.setHeaders(httpResponse.getAllHeaders()); if (httpResponse.getEntity() != null) { resp.setContent(EntityUtils.toString(httpResponse.getEntity())); } } catch (IOException e) { throw new RemoteServerUnavailableException( "server is unavailable. message=" + e.getMessage(), e); } return resp; }
DefaultHttpTransport implements HttpTransport { @Override public Response execute(HttpUriRequest httpRequest) throws RemoteServerUnavailableException { Response resp = new Response(); try { DealHeaderUtil.addDefautHeader(httpRequest); DealHeaderUtil.addAKSKHeader(httpRequest, serviceCombAkSkProperties); HttpResponse httpResponse = httpClient.execute(httpRequest); resp.setStatusCode(httpResponse.getStatusLine().getStatusCode()); resp.setStatusMessage(httpResponse.getStatusLine().getReasonPhrase()); resp.setHeaders(httpResponse.getAllHeaders()); if (httpResponse.getEntity() != null) { resp.setContent(EntityUtils.toString(httpResponse.getEntity())); } } catch (IOException e) { throw new RemoteServerUnavailableException( "server is unavailable. message=" + e.getMessage(), e); } return resp; } }
DefaultHttpTransport implements HttpTransport { @Override public Response execute(HttpUriRequest httpRequest) throws RemoteServerUnavailableException { Response resp = new Response(); try { DealHeaderUtil.addDefautHeader(httpRequest); DealHeaderUtil.addAKSKHeader(httpRequest, serviceCombAkSkProperties); HttpResponse httpResponse = httpClient.execute(httpRequest); resp.setStatusCode(httpResponse.getStatusLine().getStatusCode()); resp.setStatusMessage(httpResponse.getStatusLine().getReasonPhrase()); resp.setHeaders(httpResponse.getAllHeaders()); if (httpResponse.getEntity() != null) { resp.setContent(EntityUtils.toString(httpResponse.getEntity())); } } catch (IOException e) { throw new RemoteServerUnavailableException( "server is unavailable. message=" + e.getMessage(), e); } return resp; } private  DefaultHttpTransport(ServiceCombSSLProperties serviceCombSSLProperties); }
DefaultHttpTransport implements HttpTransport { @Override public Response execute(HttpUriRequest httpRequest) throws RemoteServerUnavailableException { Response resp = new Response(); try { DealHeaderUtil.addDefautHeader(httpRequest); DealHeaderUtil.addAKSKHeader(httpRequest, serviceCombAkSkProperties); HttpResponse httpResponse = httpClient.execute(httpRequest); resp.setStatusCode(httpResponse.getStatusLine().getStatusCode()); resp.setStatusMessage(httpResponse.getStatusLine().getReasonPhrase()); resp.setHeaders(httpResponse.getAllHeaders()); if (httpResponse.getEntity() != null) { resp.setContent(EntityUtils.toString(httpResponse.getEntity())); } } catch (IOException e) { throw new RemoteServerUnavailableException( "server is unavailable. message=" + e.getMessage(), e); } return resp; } private  DefaultHttpTransport(ServiceCombSSLProperties serviceCombSSLProperties); static DefaultHttpTransport getInstance(
      ServiceCombSSLProperties serviceCombSSLProperties); @Override Response execute(HttpUriRequest httpRequest); @Override Response sendGetRequest(String url); Response sendGetRequest(String url, Map<String, String> headers); @Override Response sendPutRequest(String url, HttpEntity httpEntity); @Override Response sendPostRequest(String url, HttpEntity httpEntity); @Override Response sendDeleteRequest(String url); @Override void setServiceCombAkSkProperties(ServiceCombAkSkProperties serviceCombAkSkProperties); }
DefaultHttpTransport implements HttpTransport { @Override public Response execute(HttpUriRequest httpRequest) throws RemoteServerUnavailableException { Response resp = new Response(); try { DealHeaderUtil.addDefautHeader(httpRequest); DealHeaderUtil.addAKSKHeader(httpRequest, serviceCombAkSkProperties); HttpResponse httpResponse = httpClient.execute(httpRequest); resp.setStatusCode(httpResponse.getStatusLine().getStatusCode()); resp.setStatusMessage(httpResponse.getStatusLine().getReasonPhrase()); resp.setHeaders(httpResponse.getAllHeaders()); if (httpResponse.getEntity() != null) { resp.setContent(EntityUtils.toString(httpResponse.getEntity())); } } catch (IOException e) { throw new RemoteServerUnavailableException( "server is unavailable. message=" + e.getMessage(), e); } return resp; } private  DefaultHttpTransport(ServiceCombSSLProperties serviceCombSSLProperties); static DefaultHttpTransport getInstance(
      ServiceCombSSLProperties serviceCombSSLProperties); @Override Response execute(HttpUriRequest httpRequest); @Override Response sendGetRequest(String url); Response sendGetRequest(String url, Map<String, String> headers); @Override Response sendPutRequest(String url, HttpEntity httpEntity); @Override Response sendPostRequest(String url, HttpEntity httpEntity); @Override Response sendDeleteRequest(String url); @Override void setServiceCombAkSkProperties(ServiceCombAkSkProperties serviceCombAkSkProperties);  }