-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #218 from europeana/MET-1778
Met 1778
- Loading branch information
Showing
6 changed files
with
130 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
.../europeana/cloud/service/dps/storm/topologies/oaipmh/bolt/harvester/CustomConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package eu.europeana.cloud.service.dps.storm.topologies.oaipmh.bolt.harvester; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.dspace.xoai.serviceprovider.exceptions.HttpException; | ||
import org.dspace.xoai.serviceprovider.parameters.Parameters; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
|
||
/** | ||
* Created by Tarek on 3/7/2019. | ||
*/ | ||
public class CustomConnection { | ||
private String baseUrl; | ||
private HttpClient httpclient; | ||
private int timeout = '\uea60'; | ||
|
||
public CustomConnection(String baseUrl) { | ||
this.baseUrl = baseUrl; | ||
this.httpclient = HttpClientBuilder.create().setConnectionTimeToLive(timeout, TimeUnit.SECONDS).build(); | ||
} | ||
|
||
public String execute(Parameters parameters) throws HttpException { | ||
HttpGet httpGet = null; | ||
try { | ||
httpGet = this.createGetRequest(parameters); | ||
HttpResponse response = this.httpclient.execute(httpGet); | ||
if (response.getStatusLine().getStatusCode() == 200) { | ||
return getData(response.getEntity().getContent()); | ||
} else { | ||
throw new HttpException("Error querying service. Returned HTTP Status Code: " + response.getStatusLine().getStatusCode()); | ||
} | ||
} catch (IOException exception) { | ||
throw new HttpException(exception); | ||
} finally { | ||
if (httpGet != null) | ||
httpGet.releaseConnection(); | ||
} | ||
} | ||
|
||
|
||
private String getData(InputStream is) throws IOException { | ||
|
||
return IOUtils.toString(is, "UTF-8"); | ||
} | ||
|
||
private HttpGet createGetRequest(Parameters parameters) { | ||
return new HttpGet(parameters.toUrl(this.baseUrl)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.