} else if ( readurl ) { HttpClient client = HttpClientManager.getInstance().createDefaultClient(); HttpGet method = new HttpGet( StringXML ); method.addHeader( "Accept-Encoding", "gzip" );
@Before public void setup() throws Exception { HttpClientManager.HttpClientBuilderFacade builder = mock( HttpClientManager.HttpClientBuilderFacade.class ); HttpClientManager manager = mock( HttpClientManager.class ); doReturn( builder ).when( manager ).createBuilder(); CloseableHttpClient client = mock( CloseableHttpClient.class ); doReturn( client ).when( builder ).build(); CloseableHttpResponse response = mock( CloseableHttpResponse.class ); doReturn( response ).when( client ).execute( any( HttpGet.class ) ); BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent( new ByteArrayInputStream( DATA.getBytes() ) ); doReturn( entity ).when( response ).getEntity(); mockStatic( HttpClientManager.class ); when( HttpClientManager.getInstance() ).thenReturn( manager ); setInternalState( data, "realUrl", "http://pentaho.com" ); setInternalState( data, "argnrs", new int[0] ); doReturn( false ).when( meta ).isUrlInField(); doReturn( "body" ).when( meta ).getFieldName(); doReturn( false ).when( log ).isDetailed(); doCallRealMethod().when( http ).callHttpService( any( RowMetaInterface.class ), any( Object[].class ) ); doReturn( HttpURLConnection.HTTP_OK ).when( http ).requestStatusCode( any( CloseableHttpResponse.class ) ); doReturn( new Header[0] ).when( http ).searchForHeaders( any( CloseableHttpResponse.class ) ); setInternalState( http, "log", log ); setInternalState( http, "data", data ); setInternalState( http, "meta", meta ); }
public static HttpClientManager getInstance() { if ( httpClientManager == null ) { httpClientManager = new HttpClientManager(); } return httpClientManager; }
HttpGet getMethod = new HttpGet( urlAsString ); if ( !Utils.isEmpty( username ) ) { HttpClientManager.HttpClientBuilderFacade clientBuilder = HttpClientManager.getInstance().createBuilder(); clientBuilder.setCredentials( username, password ); httpClient = clientBuilder.build(); } else { httpClient = HttpClientManager.getInstance().createDefaultClient();
@VisibleForTesting HttpClient createHttpClient( String user, String password ) { HttpClientManager.HttpClientBuilderFacade httpClientBuilder = httpClientManager.createBuilder(); // client.setTimeout(10000); // client.setConnectionTimeout(10000); if ( StringUtils.isNotBlank( user ) ) { httpClientBuilder.setCredentials( user, password ); } return httpClientBuilder.build(); }
@VisibleForTesting HttpClientManager createHttpClientManager() { return HttpClientManager.getInstance(); }
@VisibleForTesting HttpClient getHttpClient() { return httpClientManager.createDefaultClient(); }
@VisibleForTesting HttpClient getHttpClient( String user, String password ) { HttpClientManager.HttpClientBuilderFacade clientBuilder = httpClientManager.createBuilder(); clientBuilder.setCredentials( user, password ); return clientBuilder.build(); }
public static void sendGetSlavesRequest( String urlString, String authentication ) throws Exception { HttpGet method = new HttpGet( urlString ); HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); //adding authorization token if ( authentication != null ) { method.addHeader( new BasicHeader( "Authorization", authentication ) ); } //executing method HttpClient client = HttpClientManager.getInstance().createDefaultClient(); HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); int code = httpResponse.getStatusLine().getStatusCode(); String response = HttpClientUtil.responseToString( httpResponse ); method.releaseConnection(); if ( code >= HttpStatus.SC_BAD_REQUEST ) { System.out.println( "Error occurred during getting slave servers." ); } System.out.println( "Server response:" ); System.out.println( response ); }
private HttpClient getHttpClient( HttpClientContext context ) { HttpClientManager.HttpClientBuilderFacade clientBuilder = HttpClientManager.getInstance().createBuilder(); String login = environmentSubstitute( meta.getHttpLogin() ); if ( StringUtils.isNotBlank( login ) ) { clientBuilder.setCredentials( login, Encr.decryptPasswordOptionallyEncrypted( environmentSubstitute( meta.getHttpPassword() ) ) ); } int proxyPort = 0; if ( StringUtils.isNotBlank( meta.getProxyHost() ) ) { proxyPort = Const.toInt( environmentSubstitute( meta.getProxyPort() ), 8080 ); clientBuilder.setProxy( meta.getProxyHost(), proxyPort ); } CloseableHttpClient httpClient = clientBuilder.build(); if ( proxyPort != 0 ) { // Preemptive authentication HttpHost target = new HttpHost( meta.getProxyHost(), proxyPort, "http" ); // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put( target, basicAuth ); // Add AuthCache to the execution context context.setAuthCache( authCache ); } return httpClient; }
public static String sendStopTransRequest( String urlString, String authentication ) throws Exception { HttpGet method = new HttpGet( urlString ); HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); //adding authorization token if ( authentication != null ) { method.addHeader( new BasicHeader( "Authorization", authentication ) ); } //executing method HttpClient client = HttpClientManager.getInstance().createDefaultClient(); HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); int code = httpResponse.getStatusLine().getStatusCode(); String response = HttpClientUtil.responseToString( httpResponse ); method.releaseConnection(); if ( code >= HttpStatus.SC_BAD_REQUEST ) { System.out.println( "Error occurred during stopping transformation." ); return null; } return response; }
@VisibleForTesting Object[] callHttpService( RowMetaInterface rowMeta, Object[] rowData ) throws KettleException { HttpClientManager.HttpClientBuilderFacade clientBuilder = HttpClientManager.getInstance().createBuilder();
public static String sendSniffStepRequest( String urlString, String authentication ) throws Exception { HttpGet method = new HttpGet( urlString ); HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); //adding authorization token if ( authentication != null ) { method.addHeader( new BasicHeader( "Authorization", authentication ) ); } //executing method HttpClient client = HttpClientManager.getInstance().createDefaultClient(); HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); int code = httpResponse.getStatusLine().getStatusCode(); String response = HttpClientUtil.responseToString( httpResponse ); method.releaseConnection(); if ( code >= HttpStatus.SC_BAD_REQUEST ) { System.out.println( "Error occurred during starting job." ); return null; } return response; }
private Object[] callHTTPPOST( Object[] rowData ) throws KettleException { HttpClientManager.HttpClientBuilderFacade clientBuilder = HttpClientManager.getInstance().createBuilder();
public static String sendStartTransRequest( String urlString, String authentication ) throws Exception { HttpGet method = new HttpGet( urlString ); HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); //adding authorization token if ( authentication != null ) { method.addHeader( new BasicHeader( "Authorization", authentication ) ); } //executing method HttpClient client = HttpClientManager.getInstance().createDefaultClient(); HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); int code = httpResponse.getStatusLine().getStatusCode(); String response = HttpClientUtil.responseToString( httpResponse ); method.releaseConnection(); if ( code >= HttpStatus.SC_BAD_REQUEST ) { System.out.println( "Error occurred during starting transformation." ); return null; } return response; }
/** * Returns an instance of an HttpClient. Only one is created per ConnectionServiceClient so all calls should be * made synchronously. * * @return The HTTP client to be used for web service calls */ public static HttpClient getClient( String userId, String password ) { HttpClientManager.HttpClientBuilderFacade clientBuilder = HttpClientManager.getInstance().createBuilder(); if ( StringUtils.isNotEmpty( userId ) && StringUtils.isNotEmpty( password ) ) { clientBuilder.setCredentials( userId, password ); } return clientBuilder.build(); }
public static String sendPrepareExecutionTransRequest( String urlString, String authentication ) throws Exception { HttpGet method = new HttpGet( urlString ); HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); //adding authorization token if ( authentication != null ) { method.addHeader( new BasicHeader( "Authorization", authentication ) ); } //executing method HttpClient client = HttpClientManager.getInstance().createDefaultClient(); HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); int code = httpResponse.getStatusLine().getStatusCode(); String response = HttpClientUtil.responseToString( httpResponse ); method.releaseConnection(); if ( code >= HttpStatus.SC_BAD_REQUEST ) { System.out.println( "Error occurred during preparing transformation execution." ); return null; } return response; }
HttpClientManager.HttpClientBuilderFacade httpClientBuilder = HttpClientManager.getInstance().createBuilder(); log.logDebug( Messages.getString( "SecurityService.INFO_CONNECTING_TO_URL", urlToUse ) ); //$NON-NLS-1$
public static String sendRemoveTransRequest( String urlString, String authentication ) throws Exception { HttpGet method = new HttpGet( urlString ); HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); //adding authorization token if ( authentication != null ) { method.addHeader( new BasicHeader( "Authorization", authentication ) ); } //executing method HttpClient client = HttpClientManager.getInstance().createDefaultClient(); HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); int code = httpResponse.getStatusLine().getStatusCode(); String response = HttpClientUtil.responseToString( httpResponse ); method.releaseConnection(); if ( code >= HttpStatus.SC_BAD_REQUEST ) { System.out.println( "Error occurred during removing transformation." ); return null; } return response; }
public static String sendStopJobRequest( String urlString, String authentication ) throws Exception { HttpGet method = new HttpGet( urlString ); HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); //adding authorization token if ( authentication != null ) { method.addHeader( new BasicHeader( "Authorization", authentication ) ); } //executing method HttpClient client = HttpClientManager.getInstance().createDefaultClient(); HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); int code = httpResponse.getStatusLine().getStatusCode(); String response = HttpClientUtil.responseToString( httpResponse ); method.releaseConnection(); if ( code >= HttpStatus.SC_BAD_REQUEST ) { System.out.println( "Error occurred during stopping job." ); return null; } return response; }