4242import java .util .Date ;
4343import java .util .List ;
4444import java .util .UUID ;
45+ import java .util .concurrent .TimeUnit ;
4546import javax .servlet .http .HttpServletRequest ;
4647
4748import com .atmire .statistics .export .factory .OpenURLTrackerLoggerServiceFactory ;
4849import com .atmire .statistics .export .service .OpenURLTrackerLoggerService ;
4950import org .apache .commons .lang .StringUtils ;
51+ import org .apache .http .HttpResponse ;
52+ import org .apache .http .client .HttpClient ;
53+ import org .apache .http .client .methods .HttpGet ;
54+ import org .apache .http .impl .client .HttpClientBuilder ;
5055import org .apache .log4j .Logger ;
5156import org .dspace .app .util .Util ;
5257import org .dspace .content .Bitstream ;
@@ -332,19 +337,17 @@ private String getItemInfo(final Item item) {
332337 private static void processUrl (Context c , String urlStr ) throws IOException , SQLException {
333338 log .debug ("Prepared to send url to tracker URL: " + urlStr );
334339 System .out .println (urlStr );
335- URLConnection conn ;
336340
337341 try {
338342 // Send data
339- URL url = new URL (urlStr );
340- conn = url . openConnection ();
343+ HttpGet httpGet = new HttpGet (urlStr );
344+ HttpClient httpClient = HttpClientBuilder . create (). setConnectionTimeToLive ( 10 , TimeUnit . SECONDS ). build ();
341345
342346 // Get the response
343- BufferedReader rd = new BufferedReader (new InputStreamReader (conn .getInputStream ()));
344- while (rd .readLine () != null ) ;
347+ HttpResponse httpResponse = httpClient .execute (httpGet );
345348
346- rd . close ();
347- if ((( HttpURLConnection ) conn ). getResponseCode () != 200 ) {
349+
350+ if (httpResponse . getStatusLine (). getStatusCode () != 200 ) {
348351 ExportUsageEventListener .logfailed (c , urlStr );
349352 } else if (log .isDebugEnabled ()) {
350353 log .debug ("Successfully posted " + urlStr + " on " + new Date ());
@@ -357,14 +360,12 @@ private static void processUrl(Context c, String urlStr) throws IOException, SQL
357360
358361 private static void tryReprocessFailed (Context context , OpenURLTracker tracker ) throws SQLException {
359362 boolean success = false ;
360- URLConnection conn ;
361363 try {
362- URL url = new URL (tracker .getUrl ());
363- conn = url .openConnection ();
364- BufferedReader rd = new BufferedReader (new InputStreamReader (conn .getInputStream ()));
365- while (rd .readLine () != null ) ;
366- rd .close ();
367- if (((HttpURLConnection ) conn ).getResponseCode () == 200 ) {
364+ HttpGet httpGet = new HttpGet (tracker .getUrl ());
365+ HttpClient httpClient = HttpClientBuilder .create ().setConnectionTimeToLive (10 , TimeUnit .SECONDS ).build ();
366+ HttpResponse httpResponse = httpClient .execute (httpGet );
367+
368+ if (httpResponse .getStatusLine ().getStatusCode () == 200 ) {
368369 success = true ;
369370 }
370371 } catch (Exception e ) {
0 commit comments