31
31
import org .apache .http .impl .client .HttpClients ;
32
32
import org .apache .http .ssl .SSLContextBuilder ;
33
33
import org .apache .http .util .EntityUtils ;
34
- import org .slf4j .Logger ;
35
- import org .slf4j .LoggerFactory ;
36
34
37
35
import javax .net .ssl .HostnameVerifier ;
38
36
import javax .net .ssl .SSLContext ;
@@ -56,7 +54,6 @@ public class HttpReader
56
54
public static class Job
57
55
extends Reader .Job
58
56
{
59
- private static final Logger log = LoggerFactory .getLogger (Job .class );
60
57
private Configuration originConfig = null ;
61
58
62
59
@ Override
@@ -68,7 +65,7 @@ public void init()
68
65
@ Override
69
66
public void destroy ()
70
67
{
71
-
68
+ //
72
69
}
73
70
74
71
@ Override
@@ -83,23 +80,19 @@ public List<Configuration> split(int adviceNumber)
83
80
public static class Task
84
81
extends Reader .Task
85
82
{
86
- private static final Logger log = LoggerFactory .getLogger (Task .class );
87
83
private Configuration readerSliceConfig = null ;
88
- private String url ;
89
- private URI fullUri ;
90
84
private URIBuilder uriBuilder ;
91
85
private HttpHost proxy ;
92
86
private String username ;
93
87
private String password ;
94
- private String token ;
88
+ private String proxyAuth ;
95
89
96
90
@ Override
97
91
public void init ()
98
92
{
99
93
this .readerSliceConfig = this .getPluginJobConf ();
100
94
this .username = readerSliceConfig .getString (Key .USERNAME , null );
101
95
this .password = readerSliceConfig .getString (Key .PASSWORD , null );
102
- this .token = readerSliceConfig .getString (Key .TOKEN , null );
103
96
Configuration conn =
104
97
readerSliceConfig .getListConfiguration (Key .CONNECTION ).get (0 );
105
98
uriBuilder = new URIBuilder (URI .create (conn .getString (Key .URL )));
@@ -214,10 +207,10 @@ record = recordSender.createRecord();
214
207
}
215
208
}
216
209
217
-
218
210
private void createProxy (Configuration proxyConf )
219
211
{
220
- String host = proxyConf .getString (Key .ADDRESS );
212
+ String host = proxyConf .getString (Key .HOST );
213
+ this .proxyAuth = proxyConf .getString (Key .AUTH );
221
214
if (host .startsWith ("socks" )) {
222
215
throw DataXException .asDataXException (
223
216
HttpReaderErrorCode .NOT_SUPPORT , "sockes 代理暂时不支持"
@@ -265,19 +258,32 @@ else if ("post".equalsIgnoreCase(method)) {
265
258
private CloseableHttpClient createCloseableHttpClient ()
266
259
{
267
260
HttpClientBuilder httpClientBuilder = HttpClients .custom ();
268
-
261
+ CredentialsProvider provider = null ;
269
262
if (this .password != null ) {
270
- log .info ("set authentication with user:{}" , this .username );
271
263
httpClientBuilder = HttpClientBuilder .create ();
272
264
// setup BasicAuth
273
- CredentialsProvider provider = new BasicCredentialsProvider ();
265
+ provider = new BasicCredentialsProvider ();
274
266
// Create the authentication scope
275
- AuthScope scope = new AuthScope (AuthScope .ANY_HOST , AuthScope .ANY_PORT , AuthScope .ANY_REALM );
267
+ HttpHost target = new HttpHost (uriBuilder .getHost (), uriBuilder .getPort ());
268
+ AuthScope scope = new AuthScope (target );
276
269
// Create credential pair
277
270
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials (this .username , this .password );
278
271
// Inject the credentials
279
272
provider .setCredentials (scope , credentials );
280
273
// Set the default credentials provider
274
+ }
275
+
276
+ if (this .proxyAuth != null ) {
277
+ String [] up = this .proxyAuth .split (":" );
278
+ provider = new BasicCredentialsProvider ();
279
+ if (up .length == 1 ) {
280
+ provider .setCredentials (new AuthScope (this .proxy ), new UsernamePasswordCredentials (up [0 ], null ));
281
+ }
282
+ if (up .length == 2 ) {
283
+ provider .setCredentials (new AuthScope (this .proxy ), new UsernamePasswordCredentials (up [0 ], up [1 ]));
284
+ }
285
+ }
286
+ if (provider != null ) {
281
287
httpClientBuilder .setDefaultCredentialsProvider (provider );
282
288
}
283
289
httpClientBuilder .setSSLSocketFactory (ignoreSSLErrors ());
0 commit comments