@Test public void execute_requestIsValid_success() throws Exception { final String returnResult = "return result"; final String exception = StringUtils.EMPTY; final String statusCode = "status code"; final String responseHeaders = "response headers"; final String returnCode = "return code"; Map<String, String> rawResponse = new HashMap<>(); rawResponse.put(HttpClientOutputNames.RETURN_RESULT, returnResult); rawResponse.put(HttpClientOutputNames.EXCEPTION, exception); rawResponse.put(HttpClientOutputNames.STATUS_CODE, statusCode); rawResponse.put(HttpClientOutputNames.RESPONSE_HEADERS, responseHeaders); rawResponse.put(HttpClientOutputNames.RETURN_CODE, returnCode); HttpClientAction httpClientActionMock = PowerMockito.mock(HttpClientAction.class); PowerMockito.whenNew(HttpClientAction.class).withAnyArguments().thenReturn(httpClientActionMock); when(httpClientActionMock.execute(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), any(SerializableSessionObject.class), any(GlobalSessionObject.class))).thenReturn(rawResponse); HttpClientResponse.Builder httpClientResponseBuilderSpy = new HttpClientResponse.Builder(); httpClientResponseBuilderSpy = PowerMockito.spy(httpClientResponseBuilderSpy); when(httpClientResponseBuilderSpy.build()).thenReturn(null); PowerMockito.whenNew(HttpClientResponse.Builder.class).withAnyArguments().thenReturn(httpClientResponseBuilderSpy); HttpClient.execute(httpRequestMock); verify(httpClientActionMock).execute(eq(url), eq(tlsVersion), eq(allowedCyphers), eq(authType), eq(preemptiveAuth.toString()), eq(username), eq(password), eq(kerberosConfigFile), eq(kerberosLoginConfFile), eq(kerberosSkipPortForLookup), eq(proxyHost), eq(proxyPort.toString()), eq(proxyUsername), eq(proxyPassword), eq(trustAllRoots.toString()), eq(x509HostnameVerifier), eq(trustKeystore), eq(trustPassword), eq(keystore), eq(keystorePassword), eq(connectTimeout.toString()), eq(socketTimeout.toString()), eq(useCookies.toString()), eq(keepAlive.toString()), eq(connectionsMaxPerRoute.toString()), eq(connectionsMaxTotal.toString()), eq(headers), eq(responseCharacterSet), eq(destinationFile.toAbsolutePath().toString()), eq(followedRedirects.toString()), eq(queryParams), eq(queryParamsAreURLEncoded.toString()), eq(queryParamsAreFormEncoded.toString()), eq(formParams), eq(formParamsAreURLEncoded.toString()), eq(sourceFile.toAbsolutePath().toString()), eq(body), eq(contentType), eq(requestCharacterSet), eq(multipartBodies), eq(multipartBodiesContentType), eq(multipartFiles), eq(multipartFilesContentType), eq(multipartValuesAreURLEncoded.toString()), eq(chunkedRequestEntity.toString()), eq(method), eq(httpClientCookieSession), eq(httpClientPoolingConnectionManager) ); verify(httpClientResponseBuilderSpy).returnResult(returnResult); verify(httpClientResponseBuilderSpy).exception(exception); verify(httpClientResponseBuilderSpy).statusCode(statusCode); verify(httpClientResponseBuilderSpy).responseHeaders(responseHeaders); verify(httpClientResponseBuilderSpy).returnCode(returnCode); }
public static HttpClientResponse execute(@NotNull HttpRequest request) throws IOException, HttpClientException, URISyntaxException { Map<String, String> rawResponse = new HttpClientAction().execute( request.getUrl(), request.getTlsVersion(), request.getAllowedCyphers(), request.getAuthType(), String.valueOf(request.isPreemptiveAuth()), request.getUsername(), request.getPassword(), request.getKerberosConfigFile(), request.getKerberosLoginConfFile(), request.getKerberosSkipPortForLookup(), request.getProxyHost(), String.valueOf(request.getProxyPort()), request.getProxyUsername(), request.getProxyPassword(), String.valueOf(request.isTrustAllRoots()), request.getX509HostnameVerifier(), request.getTrustKeystore(), request.getTrustPassword(), request.getKeystore(), request.getKeystorePassword(), String.valueOf(request.getConnectTimeout()), String.valueOf(request.getSocketTimeout()), String.valueOf(request.isUseCookies()), String.valueOf(request.isKeepAlive()), String.valueOf(request.getConnectionsMaxPerRoute()), String.valueOf(request.getConnectionsMaxTotal()), request.getHeaders(), request.getResponseCharacterSet(), request.getDestinationFile() != null ? request.getDestinationFile().toAbsolutePath().toString() : null, String.valueOf(request.isFollowRedirects()), request.getQueryParams(), String.valueOf(request.isQueryParamsAreURLEncoded()), String.valueOf(request.isQueryParamsAreFormEncoded()), request.getFormParams(), String.valueOf(request.isFormParamsAreURLEncoded()), request.getSourceFile() != null ? request.getSourceFile().toAbsolutePath().toString() : null, request.getBody(), request.getContentType(), request.getRequestCharacterSet(), request.getMultipartBodies(), request.getMultipartBodiesContentType(), request.getMultipartFiles(), request.getMultipartFilesContentType(), String.valueOf(request.isMultipartValuesAreURLEncoded()), String.valueOf(request.isChunkedRequestEntity()), request.getMethod(), request.getHttpClientCookieSession(), request.getHttpClientPoolingConnectionManager() ); if (ReturnCodes.FAILURE.equals(rawResponse.get(HttpClientOutputNames.RETURN_CODE))) { throw new HttpClientException(rawResponse.get(HttpClientOutputNames.EXCEPTION)); } String returnResult = rawResponse.get(HttpClientOutputNames.RETURN_RESULT); if(StringUtils.isNotEmpty(returnResult)){ returnResult = EncodingUtils.discardBOMChar(returnResult); } return new HttpClientResponse.Builder() .returnResult(returnResult) .exception(rawResponse.get(HttpClientOutputNames.EXCEPTION)) .statusCode(rawResponse.get(HttpClientOutputNames.STATUS_CODE)) .responseHeaders(rawResponse.get(HttpClientOutputNames.RESPONSE_HEADERS)) .returnCode(rawResponse.get(HttpClientOutputNames.RETURN_CODE)) .build(); }
HttpClient { public static HttpClientResponse execute(@NotNull HttpRequest request) throws IOException, HttpClientException, URISyntaxException { Map<String, String> rawResponse = new HttpClientAction().execute( request.getUrl(), request.getTlsVersion(), request.getAllowedCyphers(), request.getAuthType(), String.valueOf(request.isPreemptiveAuth()), request.getUsername(), request.getPassword(), request.getKerberosConfigFile(), request.getKerberosLoginConfFile(), request.getKerberosSkipPortForLookup(), request.getProxyHost(), String.valueOf(request.getProxyPort()), request.getProxyUsername(), request.getProxyPassword(), String.valueOf(request.isTrustAllRoots()), request.getX509HostnameVerifier(), request.getTrustKeystore(), request.getTrustPassword(), request.getKeystore(), request.getKeystorePassword(), String.valueOf(request.getConnectTimeout()), String.valueOf(request.getSocketTimeout()), String.valueOf(request.isUseCookies()), String.valueOf(request.isKeepAlive()), String.valueOf(request.getConnectionsMaxPerRoute()), String.valueOf(request.getConnectionsMaxTotal()), request.getHeaders(), request.getResponseCharacterSet(), request.getDestinationFile() != null ? request.getDestinationFile().toAbsolutePath().toString() : null, String.valueOf(request.isFollowRedirects()), request.getQueryParams(), String.valueOf(request.isQueryParamsAreURLEncoded()), String.valueOf(request.isQueryParamsAreFormEncoded()), request.getFormParams(), String.valueOf(request.isFormParamsAreURLEncoded()), request.getSourceFile() != null ? request.getSourceFile().toAbsolutePath().toString() : null, request.getBody(), request.getContentType(), request.getRequestCharacterSet(), request.getMultipartBodies(), request.getMultipartBodiesContentType(), request.getMultipartFiles(), request.getMultipartFilesContentType(), String.valueOf(request.isMultipartValuesAreURLEncoded()), String.valueOf(request.isChunkedRequestEntity()), request.getMethod(), request.getHttpClientCookieSession(), request.getHttpClientPoolingConnectionManager() ); if (ReturnCodes.FAILURE.equals(rawResponse.get(HttpClientOutputNames.RETURN_CODE))) { throw new HttpClientException(rawResponse.get(HttpClientOutputNames.EXCEPTION)); } String returnResult = rawResponse.get(HttpClientOutputNames.RETURN_RESULT); if(StringUtils.isNotEmpty(returnResult)){ returnResult = EncodingUtils.discardBOMChar(returnResult); } return new HttpClientResponse.Builder() .returnResult(returnResult) .exception(rawResponse.get(HttpClientOutputNames.EXCEPTION)) .statusCode(rawResponse.get(HttpClientOutputNames.STATUS_CODE)) .responseHeaders(rawResponse.get(HttpClientOutputNames.RESPONSE_HEADERS)) .returnCode(rawResponse.get(HttpClientOutputNames.RETURN_CODE)) .build(); } }
HttpClient { public static HttpClientResponse execute(@NotNull HttpRequest request) throws IOException, HttpClientException, URISyntaxException { Map<String, String> rawResponse = new HttpClientAction().execute( request.getUrl(), request.getTlsVersion(), request.getAllowedCyphers(), request.getAuthType(), String.valueOf(request.isPreemptiveAuth()), request.getUsername(), request.getPassword(), request.getKerberosConfigFile(), request.getKerberosLoginConfFile(), request.getKerberosSkipPortForLookup(), request.getProxyHost(), String.valueOf(request.getProxyPort()), request.getProxyUsername(), request.getProxyPassword(), String.valueOf(request.isTrustAllRoots()), request.getX509HostnameVerifier(), request.getTrustKeystore(), request.getTrustPassword(), request.getKeystore(), request.getKeystorePassword(), String.valueOf(request.getConnectTimeout()), String.valueOf(request.getSocketTimeout()), String.valueOf(request.isUseCookies()), String.valueOf(request.isKeepAlive()), String.valueOf(request.getConnectionsMaxPerRoute()), String.valueOf(request.getConnectionsMaxTotal()), request.getHeaders(), request.getResponseCharacterSet(), request.getDestinationFile() != null ? request.getDestinationFile().toAbsolutePath().toString() : null, String.valueOf(request.isFollowRedirects()), request.getQueryParams(), String.valueOf(request.isQueryParamsAreURLEncoded()), String.valueOf(request.isQueryParamsAreFormEncoded()), request.getFormParams(), String.valueOf(request.isFormParamsAreURLEncoded()), request.getSourceFile() != null ? request.getSourceFile().toAbsolutePath().toString() : null, request.getBody(), request.getContentType(), request.getRequestCharacterSet(), request.getMultipartBodies(), request.getMultipartBodiesContentType(), request.getMultipartFiles(), request.getMultipartFilesContentType(), String.valueOf(request.isMultipartValuesAreURLEncoded()), String.valueOf(request.isChunkedRequestEntity()), request.getMethod(), request.getHttpClientCookieSession(), request.getHttpClientPoolingConnectionManager() ); if (ReturnCodes.FAILURE.equals(rawResponse.get(HttpClientOutputNames.RETURN_CODE))) { throw new HttpClientException(rawResponse.get(HttpClientOutputNames.EXCEPTION)); } String returnResult = rawResponse.get(HttpClientOutputNames.RETURN_RESULT); if(StringUtils.isNotEmpty(returnResult)){ returnResult = EncodingUtils.discardBOMChar(returnResult); } return new HttpClientResponse.Builder() .returnResult(returnResult) .exception(rawResponse.get(HttpClientOutputNames.EXCEPTION)) .statusCode(rawResponse.get(HttpClientOutputNames.STATUS_CODE)) .responseHeaders(rawResponse.get(HttpClientOutputNames.RESPONSE_HEADERS)) .returnCode(rawResponse.get(HttpClientOutputNames.RETURN_CODE)) .build(); }  }
HttpClient { public static HttpClientResponse execute(@NotNull HttpRequest request) throws IOException, HttpClientException, URISyntaxException { Map<String, String> rawResponse = new HttpClientAction().execute( request.getUrl(), request.getTlsVersion(), request.getAllowedCyphers(), request.getAuthType(), String.valueOf(request.isPreemptiveAuth()), request.getUsername(), request.getPassword(), request.getKerberosConfigFile(), request.getKerberosLoginConfFile(), request.getKerberosSkipPortForLookup(), request.getProxyHost(), String.valueOf(request.getProxyPort()), request.getProxyUsername(), request.getProxyPassword(), String.valueOf(request.isTrustAllRoots()), request.getX509HostnameVerifier(), request.getTrustKeystore(), request.getTrustPassword(), request.getKeystore(), request.getKeystorePassword(), String.valueOf(request.getConnectTimeout()), String.valueOf(request.getSocketTimeout()), String.valueOf(request.isUseCookies()), String.valueOf(request.isKeepAlive()), String.valueOf(request.getConnectionsMaxPerRoute()), String.valueOf(request.getConnectionsMaxTotal()), request.getHeaders(), request.getResponseCharacterSet(), request.getDestinationFile() != null ? request.getDestinationFile().toAbsolutePath().toString() : null, String.valueOf(request.isFollowRedirects()), request.getQueryParams(), String.valueOf(request.isQueryParamsAreURLEncoded()), String.valueOf(request.isQueryParamsAreFormEncoded()), request.getFormParams(), String.valueOf(request.isFormParamsAreURLEncoded()), request.getSourceFile() != null ? request.getSourceFile().toAbsolutePath().toString() : null, request.getBody(), request.getContentType(), request.getRequestCharacterSet(), request.getMultipartBodies(), request.getMultipartBodiesContentType(), request.getMultipartFiles(), request.getMultipartFilesContentType(), String.valueOf(request.isMultipartValuesAreURLEncoded()), String.valueOf(request.isChunkedRequestEntity()), request.getMethod(), request.getHttpClientCookieSession(), request.getHttpClientPoolingConnectionManager() ); if (ReturnCodes.FAILURE.equals(rawResponse.get(HttpClientOutputNames.RETURN_CODE))) { throw new HttpClientException(rawResponse.get(HttpClientOutputNames.EXCEPTION)); } String returnResult = rawResponse.get(HttpClientOutputNames.RETURN_RESULT); if(StringUtils.isNotEmpty(returnResult)){ returnResult = EncodingUtils.discardBOMChar(returnResult); } return new HttpClientResponse.Builder() .returnResult(returnResult) .exception(rawResponse.get(HttpClientOutputNames.EXCEPTION)) .statusCode(rawResponse.get(HttpClientOutputNames.STATUS_CODE)) .responseHeaders(rawResponse.get(HttpClientOutputNames.RESPONSE_HEADERS)) .returnCode(rawResponse.get(HttpClientOutputNames.RETURN_CODE)) .build(); }  static HttpClientResponse execute(@NotNull HttpRequest request); }
HttpClient { public static HttpClientResponse execute(@NotNull HttpRequest request) throws IOException, HttpClientException, URISyntaxException { Map<String, String> rawResponse = new HttpClientAction().execute( request.getUrl(), request.getTlsVersion(), request.getAllowedCyphers(), request.getAuthType(), String.valueOf(request.isPreemptiveAuth()), request.getUsername(), request.getPassword(), request.getKerberosConfigFile(), request.getKerberosLoginConfFile(), request.getKerberosSkipPortForLookup(), request.getProxyHost(), String.valueOf(request.getProxyPort()), request.getProxyUsername(), request.getProxyPassword(), String.valueOf(request.isTrustAllRoots()), request.getX509HostnameVerifier(), request.getTrustKeystore(), request.getTrustPassword(), request.getKeystore(), request.getKeystorePassword(), String.valueOf(request.getConnectTimeout()), String.valueOf(request.getSocketTimeout()), String.valueOf(request.isUseCookies()), String.valueOf(request.isKeepAlive()), String.valueOf(request.getConnectionsMaxPerRoute()), String.valueOf(request.getConnectionsMaxTotal()), request.getHeaders(), request.getResponseCharacterSet(), request.getDestinationFile() != null ? request.getDestinationFile().toAbsolutePath().toString() : null, String.valueOf(request.isFollowRedirects()), request.getQueryParams(), String.valueOf(request.isQueryParamsAreURLEncoded()), String.valueOf(request.isQueryParamsAreFormEncoded()), request.getFormParams(), String.valueOf(request.isFormParamsAreURLEncoded()), request.getSourceFile() != null ? request.getSourceFile().toAbsolutePath().toString() : null, request.getBody(), request.getContentType(), request.getRequestCharacterSet(), request.getMultipartBodies(), request.getMultipartBodiesContentType(), request.getMultipartFiles(), request.getMultipartFilesContentType(), String.valueOf(request.isMultipartValuesAreURLEncoded()), String.valueOf(request.isChunkedRequestEntity()), request.getMethod(), request.getHttpClientCookieSession(), request.getHttpClientPoolingConnectionManager() ); if (ReturnCodes.FAILURE.equals(rawResponse.get(HttpClientOutputNames.RETURN_CODE))) { throw new HttpClientException(rawResponse.get(HttpClientOutputNames.EXCEPTION)); } String returnResult = rawResponse.get(HttpClientOutputNames.RETURN_RESULT); if(StringUtils.isNotEmpty(returnResult)){ returnResult = EncodingUtils.discardBOMChar(returnResult); } return new HttpClientResponse.Builder() .returnResult(returnResult) .exception(rawResponse.get(HttpClientOutputNames.EXCEPTION)) .statusCode(rawResponse.get(HttpClientOutputNames.STATUS_CODE)) .responseHeaders(rawResponse.get(HttpClientOutputNames.RESPONSE_HEADERS)) .returnCode(rawResponse.get(HttpClientOutputNames.RETURN_CODE)) .build(); }  static HttpClientResponse execute(@NotNull HttpRequest request);  }