mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 15:33:09 +00:00
Some more httpclient fixes
This commit is contained in:
@@ -7,7 +7,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.discovery;
|
package org.dspace.discovery;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@@ -31,8 +35,7 @@ import java.util.Vector;
|
|||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.collections.MapUtils;
|
import org.apache.commons.collections.MapUtils;
|
||||||
import org.apache.commons.collections.Transformer;
|
import org.apache.commons.collections.Transformer;
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.apache.commons.lang.ArrayUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.time.DateFormatUtils;
|
import org.apache.commons.lang.time.DateFormatUtils;
|
||||||
@@ -42,6 +45,7 @@ import org.apache.http.HttpResponse;
|
|||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.params.ClientPNames;
|
import org.apache.http.client.params.ClientPNames;
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
import org.apache.http.client.utils.URIBuilder;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.solr.client.solrj.SolrQuery;
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
import org.apache.solr.client.solrj.SolrServerException;
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
@@ -1756,9 +1760,9 @@ public class SolrServiceImpl implements SearchService, IndexingService {
|
|||||||
urlBuilder.append(solrQuery.toString());
|
urlBuilder.append(solrQuery.toString());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GetMethod get = new GetMethod(urlBuilder.toString());
|
HttpGet get = new HttpGet(urlBuilder.toString());
|
||||||
new HttpClient().executeMethod(get);
|
HttpResponse response = new DefaultHttpClient().execute(get);
|
||||||
return get.getResponseBodyAsStream();
|
return response.getEntity().getContent();
|
||||||
|
|
||||||
} catch (Exception e)
|
} catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@@ -13,13 +13,20 @@ import com.maxmind.geoip.Location;
|
|||||||
import com.maxmind.geoip.LookupService;
|
import com.maxmind.geoip.LookupService;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.apache.commons.lang.ArrayUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.time.DateFormatUtils;
|
import org.apache.commons.lang.time.DateFormatUtils;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.solr.client.solrj.SolrQuery;
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
import org.apache.solr.client.solrj.SolrServerException;
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
@@ -49,13 +56,6 @@ import org.dspace.statistics.util.LocationUtils;
|
|||||||
import org.dspace.statistics.util.SpiderDetector;
|
import org.dspace.statistics.util.SpiderDetector;
|
||||||
import org.dspace.usage.UsageWorkflowEvent;
|
import org.dspace.usage.UsageWorkflowEvent;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static holder for a HttpSolrClient connection pool to issue
|
* Static holder for a HttpSolrClient connection pool to issue
|
||||||
* usage logging events to Solr from DSpace libraries, and some static query
|
* usage logging events to Solr from DSpace libraries, and some static query
|
||||||
@@ -1322,9 +1322,9 @@ public class SolrLogger
|
|||||||
String solrRequestUrl = solr.getBaseURL() + "/select";
|
String solrRequestUrl = solr.getBaseURL() + "/select";
|
||||||
solrRequestUrl = generateURL(solrRequestUrl, yearQueryParams);
|
solrRequestUrl = generateURL(solrRequestUrl, yearQueryParams);
|
||||||
|
|
||||||
GetMethod get = new GetMethod(solrRequestUrl);
|
HttpGet get = new HttpGet(solrRequestUrl);
|
||||||
new HttpClient().executeMethod(get);
|
HttpResponse response = new DefaultHttpClient().execute(get);
|
||||||
InputStream csvInputstream = get.getResponseBodyAsStream();
|
InputStream csvInputstream = response.getEntity().getContent();
|
||||||
//Write the csv ouput to a file !
|
//Write the csv ouput to a file !
|
||||||
File csvFile = new File(tempDirectory.getPath() + File.separatorChar + "temp." + dcStart.getYear() + "." + i + ".csv");
|
File csvFile = new File(tempDirectory.getPath() + File.separatorChar + "temp." + dcStart.getYear() + "." + i + ".csv");
|
||||||
FileUtils.copyInputStreamToFile(csvInputstream, csvFile);
|
FileUtils.copyInputStreamToFile(csvInputstream, csvFile);
|
||||||
@@ -1398,10 +1398,10 @@ public class SolrLogger
|
|||||||
String solrRequestUrl = solr.getBaseURL() + "/select";
|
String solrRequestUrl = solr.getBaseURL() + "/select";
|
||||||
solrRequestUrl = generateURL(solrRequestUrl, params);
|
solrRequestUrl = generateURL(solrRequestUrl, params);
|
||||||
|
|
||||||
GetMethod get = new GetMethod(solrRequestUrl);
|
HttpGet get = new HttpGet(solrRequestUrl);
|
||||||
new HttpClient().executeMethod(get);
|
HttpResponse response = new DefaultHttpClient().execute(get);
|
||||||
|
|
||||||
InputStream csvOutput = get.getResponseBodyAsStream();
|
InputStream csvOutput = response.getEntity().getContent();
|
||||||
Reader csvReader = new InputStreamReader(csvOutput);
|
Reader csvReader = new InputStreamReader(csvOutput);
|
||||||
List<String[]> rows = new CSVReader(csvReader).readAll();
|
List<String[]> rows = new CSVReader(csvReader).readAll();
|
||||||
String[][] csvParsed = rows.toArray(new String[rows.size()][]);
|
String[][] csvParsed = rows.toArray(new String[rows.size()][]);
|
||||||
|
@@ -15,8 +15,8 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import org.apache.http.HttpException;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -9,10 +9,8 @@ package org.dspace.submit.lookup;
|
|||||||
|
|
||||||
import gr.ekt.bte.core.Record;
|
import gr.ekt.bte.core.Record;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -20,14 +18,18 @@ import java.util.Set;
|
|||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
import org.apache.commons.httpclient.NameValuePair;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.http.HttpException;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.HttpStatus;
|
||||||
|
import org.apache.http.StatusLine;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.utils.URIBuilder;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.params.CoreConnectionPNames;
|
||||||
|
import org.apache.http.params.HttpParams;
|
||||||
import org.dspace.app.util.XMLUtils;
|
import org.dspace.app.util.XMLUtils;
|
||||||
import org.dspace.core.ConfigurationManager;
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
@@ -41,6 +43,11 @@ public class ArXivService
|
|||||||
{
|
{
|
||||||
private int timeout = 1000;
|
private int timeout = 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How long to wait for a connection to be established.
|
||||||
|
*
|
||||||
|
* @param timeout milliseconds
|
||||||
|
*/
|
||||||
public void setTimeout(int timeout)
|
public void setTimeout(int timeout)
|
||||||
{
|
{
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
@@ -79,21 +86,28 @@ public class ArXivService
|
|||||||
throws IOException, HttpException
|
throws IOException, HttpException
|
||||||
{
|
{
|
||||||
List<Record> results = new ArrayList<Record>();
|
List<Record> results = new ArrayList<Record>();
|
||||||
GetMethod method = null;
|
HttpGet method = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new DefaultHttpClient();
|
||||||
client.setTimeout(timeout);
|
HttpParams params = client.getParams();
|
||||||
method = new GetMethod("http://export.arxiv.org/api/query");
|
params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
|
||||||
NameValuePair id = new NameValuePair("id_list", arxivid);
|
|
||||||
NameValuePair queryParam = new NameValuePair("search_query",
|
try {
|
||||||
query);
|
URIBuilder uriBuilder = new URIBuilder("http://export.arxiv.org/api/query");
|
||||||
NameValuePair count = new NameValuePair("max_results",
|
uriBuilder.addParameter("id_list", arxivid);
|
||||||
String.valueOf(max_result));
|
uriBuilder.addParameter("search_query", query);
|
||||||
method.setQueryString(new NameValuePair[] { id, queryParam,
|
uriBuilder.addParameter("max_results", String.valueOf(max_result));
|
||||||
count });
|
method = new HttpGet(uriBuilder.build());
|
||||||
// Execute the method.
|
} catch (URISyntaxException ex)
|
||||||
int statusCode = client.executeMethod(method);
|
{
|
||||||
|
throw new HttpException(ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute the method.
|
||||||
|
HttpResponse response = client.execute(method);
|
||||||
|
StatusLine responseStatus = response.getStatusLine();
|
||||||
|
int statusCode = responseStatus.getStatusCode();
|
||||||
|
|
||||||
if (statusCode != HttpStatus.SC_OK)
|
if (statusCode != HttpStatus.SC_OK)
|
||||||
{
|
{
|
||||||
@@ -101,7 +115,7 @@ public class ArXivService
|
|||||||
throw new RuntimeException("arXiv query is not valid");
|
throw new RuntimeException("arXiv query is not valid");
|
||||||
else
|
else
|
||||||
throw new RuntimeException("Http call failed: "
|
throw new RuntimeException("Http call failed: "
|
||||||
+ method.getStatusLine());
|
+ responseStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -113,7 +127,7 @@ public class ArXivService
|
|||||||
factory.setIgnoringElementContentWhitespace(true);
|
factory.setIgnoringElementContentWhitespace(true);
|
||||||
|
|
||||||
DocumentBuilder db = factory.newDocumentBuilder();
|
DocumentBuilder db = factory.newDocumentBuilder();
|
||||||
Document inDoc = db.parse(method.getResponseBodyAsStream());
|
Document inDoc = db.parse(response.getEntity().getContent());
|
||||||
|
|
||||||
Element xmlRoot = inDoc.getDocumentElement();
|
Element xmlRoot = inDoc.getDocumentElement();
|
||||||
List<Element> dataRoots = XMLUtils.getElementList(xmlRoot,
|
List<Element> dataRoots = XMLUtils.getElementList(xmlRoot,
|
||||||
|
@@ -15,8 +15,8 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import org.apache.http.HttpException;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -9,24 +9,22 @@ package org.dspace.submit.lookup;
|
|||||||
|
|
||||||
import gr.ekt.bte.core.Record;
|
import gr.ekt.bte.core.Record;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import org.apache.http.HttpException;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.HttpStatus;
|
||||||
|
import org.apache.http.StatusLine;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.params.CoreConnectionPNames;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
import org.apache.commons.httpclient.NameValuePair;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.app.util.XMLUtils;
|
import org.dspace.app.util.XMLUtils;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
@@ -38,7 +36,7 @@ import org.w3c.dom.Element;
|
|||||||
public class CiNiiService
|
public class CiNiiService
|
||||||
{
|
{
|
||||||
/** log4j category */
|
/** log4j category */
|
||||||
private static Logger log = Logger.getLogger(CiNiiService.class);
|
private static final Logger log = Logger.getLogger(CiNiiService.class);
|
||||||
|
|
||||||
private int timeout = 1000;
|
private int timeout = 1000;
|
||||||
|
|
||||||
@@ -82,14 +80,16 @@ public class CiNiiService
|
|||||||
private Record search(String id, String appId)
|
private Record search(String id, String appId)
|
||||||
throws IOException, HttpException
|
throws IOException, HttpException
|
||||||
{
|
{
|
||||||
GetMethod method = null;
|
HttpGet method = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new DefaultHttpClient();
|
||||||
client.setTimeout(timeout);
|
client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
|
||||||
method = new GetMethod("http://ci.nii.ac.jp/naid/"+id+".rdf?appid="+appId);
|
method = new HttpGet("http://ci.nii.ac.jp/naid/"+id+".rdf?appid="+appId);
|
||||||
// Execute the method.
|
// Execute the method.
|
||||||
int statusCode = client.executeMethod(method);
|
HttpResponse response = client.execute(method);
|
||||||
|
StatusLine statusLine = response.getStatusLine();
|
||||||
|
int statusCode = statusLine.getStatusCode();
|
||||||
|
|
||||||
if (statusCode != HttpStatus.SC_OK)
|
if (statusCode != HttpStatus.SC_OK)
|
||||||
{
|
{
|
||||||
@@ -97,7 +97,7 @@ public class CiNiiService
|
|||||||
throw new RuntimeException("CiNii RDF is not valid");
|
throw new RuntimeException("CiNii RDF is not valid");
|
||||||
else
|
else
|
||||||
throw new RuntimeException("CiNii RDF Http call failed: "
|
throw new RuntimeException("CiNii RDF Http call failed: "
|
||||||
+ method.getStatusLine());
|
+ statusLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -109,7 +109,7 @@ public class CiNiiService
|
|||||||
factory.setIgnoringElementContentWhitespace(true);
|
factory.setIgnoringElementContentWhitespace(true);
|
||||||
|
|
||||||
DocumentBuilder db = factory.newDocumentBuilder();
|
DocumentBuilder db = factory.newDocumentBuilder();
|
||||||
Document inDoc = db.parse(method.getResponseBodyAsStream());
|
Document inDoc = db.parse(response.getEntity().getContent());
|
||||||
|
|
||||||
Element xmlRoot = inDoc.getDocumentElement();
|
Element xmlRoot = inDoc.getDocumentElement();
|
||||||
|
|
||||||
@@ -144,12 +144,12 @@ public class CiNiiService
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetMethod method = null;
|
HttpGet method = null;
|
||||||
List<String> ids = new ArrayList<String>();
|
List<String> ids = new ArrayList<String>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new DefaultHttpClient();
|
||||||
client.setTimeout(timeout);
|
client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
|
||||||
StringBuilder query = new StringBuilder();
|
StringBuilder query = new StringBuilder();
|
||||||
query.append("format=rss&appid=").append(appId)
|
query.append("format=rss&appid=").append(appId)
|
||||||
.append("&count=").append(maxResults);
|
.append("&count=").append(maxResults);
|
||||||
@@ -166,16 +166,18 @@ public class CiNiiService
|
|||||||
query.append("&year_from=").append(String.valueOf(year));
|
query.append("&year_from=").append(String.valueOf(year));
|
||||||
query.append("&year_to=").append(String.valueOf(year));
|
query.append("&year_to=").append(String.valueOf(year));
|
||||||
}
|
}
|
||||||
method = new GetMethod("http://ci.nii.ac.jp/opensearch/search?"+query.toString());
|
method = new HttpGet("http://ci.nii.ac.jp/opensearch/search?"+query.toString());
|
||||||
// Execute the method.
|
// Execute the method.
|
||||||
int statusCode = client.executeMethod(method);
|
HttpResponse response = client.execute(method);
|
||||||
|
StatusLine statusLine = response.getStatusLine();
|
||||||
|
int statusCode = statusLine.getStatusCode();
|
||||||
if (statusCode != HttpStatus.SC_OK)
|
if (statusCode != HttpStatus.SC_OK)
|
||||||
{
|
{
|
||||||
if (statusCode == HttpStatus.SC_BAD_REQUEST)
|
if (statusCode == HttpStatus.SC_BAD_REQUEST)
|
||||||
throw new RuntimeException("CiNii OpenSearch query is not valid");
|
throw new RuntimeException("CiNii OpenSearch query is not valid");
|
||||||
else
|
else
|
||||||
throw new RuntimeException("CiNii OpenSearch call failed: "
|
throw new RuntimeException("CiNii OpenSearch call failed: "
|
||||||
+ method.getStatusLine());
|
+ statusLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -187,7 +189,7 @@ public class CiNiiService
|
|||||||
factory.setIgnoringElementContentWhitespace(true);
|
factory.setIgnoringElementContentWhitespace(true);
|
||||||
|
|
||||||
DocumentBuilder db = factory.newDocumentBuilder();
|
DocumentBuilder db = factory.newDocumentBuilder();
|
||||||
Document inDoc = db.parse(method.getResponseBodyAsStream());
|
Document inDoc = db.parse(response.getEntity().getContent());
|
||||||
|
|
||||||
Element xmlRoot = inDoc.getDocumentElement();
|
Element xmlRoot = inDoc.getDocumentElement();
|
||||||
List<Element> items = XMLUtils.getElementList(xmlRoot, "item");
|
List<Element> items = XMLUtils.getElementList(xmlRoot, "item");
|
||||||
|
@@ -18,7 +18,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
import org.apache.http.HttpException;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.jdom.JDOMException;
|
import org.jdom.JDOMException;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
@@ -21,11 +21,6 @@ import javax.xml.parsers.DocumentBuilder;
|
|||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
import org.apache.commons.httpclient.NameValuePair;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.app.util.XMLUtils;
|
import org.dspace.app.util.XMLUtils;
|
||||||
@@ -38,6 +33,18 @@ import org.xml.sax.SAXException;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.http.HttpException;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.HttpStatus;
|
||||||
|
import org.apache.http.StatusLine;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.utils.URIBuilder;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.params.CoreConnectionPNames;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Bollini
|
* @author Andrea Bollini
|
||||||
@@ -68,27 +75,32 @@ public class CrossRefService
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GetMethod method = null;
|
HttpGet method = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new DefaultHttpClient();
|
||||||
client.setConnectionTimeout(timeout);
|
client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
|
||||||
method = new GetMethod(
|
|
||||||
"http://www.crossref.org/openurl/");
|
|
||||||
|
|
||||||
NameValuePair pid = new NameValuePair("pid", apiKey);
|
try {
|
||||||
NameValuePair noredirect = new NameValuePair(
|
URIBuilder uriBuilder = new URIBuilder(
|
||||||
"noredirect", "true");
|
"http://www.crossref.org/openurl/");
|
||||||
NameValuePair id = new NameValuePair("id", record);
|
uriBuilder.addParameter("pid", apiKey);
|
||||||
method.setQueryString(new NameValuePair[] { pid,
|
uriBuilder.addParameter("noredirect", "true");
|
||||||
noredirect, id });
|
uriBuilder.addParameter("id", record);
|
||||||
// Execute the method.
|
method = new HttpGet(uriBuilder.build());
|
||||||
int statusCode = client.executeMethod(method);
|
} catch (URISyntaxException ex) {
|
||||||
|
throw new HttpException("Request not sent", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute the method.
|
||||||
|
HttpResponse response = client.execute(method);
|
||||||
|
StatusLine statusLine = response.getStatusLine();
|
||||||
|
int statusCode = statusLine.getStatusCode();
|
||||||
|
|
||||||
if (statusCode != HttpStatus.SC_OK)
|
if (statusCode != HttpStatus.SC_OK)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Http call failed: "
|
throw new RuntimeException("Http call failed: "
|
||||||
+ method.getStatusLine());
|
+ statusLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
Record crossitem;
|
Record crossitem;
|
||||||
@@ -102,8 +114,7 @@ public class CrossRefService
|
|||||||
|
|
||||||
DocumentBuilder db = factory
|
DocumentBuilder db = factory
|
||||||
.newDocumentBuilder();
|
.newDocumentBuilder();
|
||||||
Document inDoc = db.parse(method
|
Document inDoc = db.parse(response.getEntity().getContent());
|
||||||
.getResponseBodyAsStream());
|
|
||||||
|
|
||||||
Element xmlRoot = inDoc.getDocumentElement();
|
Element xmlRoot = inDoc.getDocumentElement();
|
||||||
Element queryResult = XMLUtils.getSingleElement(xmlRoot, "query_result");
|
Element queryResult = XMLUtils.getSingleElement(xmlRoot, "query_result");
|
||||||
@@ -142,57 +153,51 @@ public class CrossRefService
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NameValuePair[] buildQueryPart(String title, String author,
|
|
||||||
int year, int count)
|
|
||||||
{
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
if (StringUtils.isNotBlank(title))
|
|
||||||
{
|
|
||||||
sb.append(title);
|
|
||||||
}
|
|
||||||
sb.append(" ");
|
|
||||||
if (StringUtils.isNotBlank(author))
|
|
||||||
{
|
|
||||||
sb.append(author);
|
|
||||||
}
|
|
||||||
String q = sb.toString().trim();
|
|
||||||
NameValuePair qParam = new NameValuePair("q", title);
|
|
||||||
NameValuePair yearParam = new NameValuePair("year",
|
|
||||||
year != -1 ? String.valueOf(year) : "");
|
|
||||||
NameValuePair countParam = new NameValuePair("rows",
|
|
||||||
count != -1 ? String.valueOf(count) : "");
|
|
||||||
|
|
||||||
NameValuePair[] query = new NameValuePair[] { qParam, yearParam,
|
|
||||||
countParam };
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Record> search(Context context, String title, String authors,
|
public List<Record> search(Context context, String title, String authors,
|
||||||
int year, int count, String apiKey) throws IOException, HttpException
|
int year, int count, String apiKey) throws IOException, HttpException
|
||||||
{
|
{
|
||||||
GetMethod method = null;
|
HttpGet method = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NameValuePair[] query = buildQueryPart(title, authors, year, count);
|
HttpClient client = new DefaultHttpClient();
|
||||||
HttpClient client = new HttpClient();
|
client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
|
||||||
client.setTimeout(timeout);
|
|
||||||
method = new GetMethod("http://search.labs.crossref.org/dois");
|
URIBuilder uriBuilder = new URIBuilder("http://search.labs.crossref.org/dois");
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if (StringUtils.isNotBlank(title))
|
||||||
|
{
|
||||||
|
sb.append(title);
|
||||||
|
}
|
||||||
|
sb.append(" ");
|
||||||
|
if (StringUtils.isNotBlank(authors))
|
||||||
|
{
|
||||||
|
sb.append(authors);
|
||||||
|
}
|
||||||
|
String q = sb.toString().trim();
|
||||||
|
uriBuilder.addParameter("q", q);
|
||||||
|
|
||||||
|
uriBuilder.addParameter("year", year != -1 ? String.valueOf(year) : "");
|
||||||
|
uriBuilder.addParameter("rows", count != -1 ? String.valueOf(count) : "");
|
||||||
|
method = new HttpGet(uriBuilder.build());
|
||||||
|
|
||||||
method.setQueryString(query);
|
|
||||||
// Execute the method.
|
// Execute the method.
|
||||||
int statusCode = client.executeMethod(method);
|
HttpResponse response = client.execute(method);
|
||||||
|
StatusLine statusLine = response.getStatusLine();
|
||||||
|
int statusCode = statusLine.getStatusCode();
|
||||||
|
|
||||||
if (statusCode != HttpStatus.SC_OK)
|
if (statusCode != HttpStatus.SC_OK)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Http call failed:: "
|
throw new RuntimeException("Http call failed:: "
|
||||||
+ method.getStatusLine());
|
+ statusLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
Type listType = new TypeToken<ArrayList<Map>>()
|
Type listType = new TypeToken<ArrayList<Map>>()
|
||||||
{
|
{
|
||||||
}.getType();
|
}.getType();
|
||||||
List<Map> json = gson.fromJson(method.getResponseBodyAsString(),
|
List<Map> json = gson.fromJson(
|
||||||
|
IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8),
|
||||||
listType);
|
listType);
|
||||||
Set<String> dois = new HashSet<String>();
|
Set<String> dois = new HashSet<String>();
|
||||||
for (Map r : json)
|
for (Map r : json)
|
||||||
|
@@ -10,25 +10,18 @@ package org.dspace.submit.lookup;
|
|||||||
import gr.ekt.bte.core.DataLoadingSpec;
|
import gr.ekt.bte.core.DataLoadingSpec;
|
||||||
import gr.ekt.bte.core.Record;
|
import gr.ekt.bte.core.Record;
|
||||||
import gr.ekt.bte.core.RecordSet;
|
import gr.ekt.bte.core.RecordSet;
|
||||||
import gr.ekt.bte.core.StringValue;
|
|
||||||
import gr.ekt.bte.core.Value;
|
import gr.ekt.bte.core.Value;
|
||||||
import gr.ekt.bte.exceptions.MalformedSourceException;
|
import gr.ekt.bte.exceptions.MalformedSourceException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.GenericArrayType;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.http.HttpException;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.submit.util.SubmissionLookupPublication;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Bollini
|
* @author Andrea Bollini
|
||||||
|
@@ -15,8 +15,8 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import org.apache.http.HttpException;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.core.LogManager;
|
import org.dspace.core.LogManager;
|
||||||
@@ -31,7 +31,7 @@ public class PubmedOnlineDataLoader extends NetworkSubmissionLookupDataLoader
|
|||||||
{
|
{
|
||||||
private boolean searchProvider = true;
|
private boolean searchProvider = true;
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(PubmedOnlineDataLoader.class);
|
private static final Logger log = Logger.getLogger(PubmedOnlineDataLoader.class);
|
||||||
|
|
||||||
private PubmedService pubmedService = new PubmedService();
|
private PubmedService pubmedService = new PubmedService();
|
||||||
|
|
||||||
|
@@ -13,6 +13,7 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -20,12 +21,16 @@ import javax.xml.parsers.DocumentBuilder;
|
|||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
import org.apache.commons.httpclient.NameValuePair;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.http.HttpException;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.HttpStatus;
|
||||||
|
import org.apache.http.StatusLine;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.utils.URIBuilder;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.params.CoreConnectionPNames;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.app.util.XMLUtils;
|
import org.dspace.app.util.XMLUtils;
|
||||||
import org.dspace.core.ConfigurationManager;
|
import org.dspace.core.ConfigurationManager;
|
||||||
@@ -42,7 +47,7 @@ import org.xml.sax.SAXException;
|
|||||||
public class PubmedService
|
public class PubmedService
|
||||||
{
|
{
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(PubmedService.class);
|
private static final Logger log = Logger.getLogger(PubmedService.class);
|
||||||
|
|
||||||
private int timeout = 1000;
|
private int timeout = 1000;
|
||||||
|
|
||||||
@@ -96,28 +101,29 @@ public class PubmedService
|
|||||||
List<Record> results = null;
|
List<Record> results = null;
|
||||||
if (!ConfigurationManager.getBooleanProperty(SubmissionLookupService.CFG_MODULE, "remoteservice.demo"))
|
if (!ConfigurationManager.getBooleanProperty(SubmissionLookupService.CFG_MODULE, "remoteservice.demo"))
|
||||||
{
|
{
|
||||||
GetMethod method = null;
|
HttpGet method = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new DefaultHttpClient();
|
||||||
client.setTimeout(timeout);
|
client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
|
||||||
method = new GetMethod(
|
|
||||||
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi");
|
URIBuilder uriBuilder = new URIBuilder(
|
||||||
|
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi");
|
||||||
|
uriBuilder.addParameter("db", "pubmed");
|
||||||
|
uriBuilder.addParameter("datetype", "edat");
|
||||||
|
uriBuilder.addParameter("retmax", "10");
|
||||||
|
uriBuilder.addParameter("term", query);
|
||||||
|
method = new HttpGet(uriBuilder.build());
|
||||||
|
|
||||||
NameValuePair db = new NameValuePair("db", "pubmed");
|
|
||||||
NameValuePair datetype = new NameValuePair("datetype", "edat");
|
|
||||||
NameValuePair retmax = new NameValuePair("retmax", "10");
|
|
||||||
NameValuePair queryParam = new NameValuePair("term",
|
|
||||||
query.toString());
|
|
||||||
method.setQueryString(new NameValuePair[] { db, queryParam,
|
|
||||||
retmax, datetype });
|
|
||||||
// Execute the method.
|
// Execute the method.
|
||||||
int statusCode = client.executeMethod(method);
|
HttpResponse response = client.execute(method);
|
||||||
|
StatusLine statusLine = response.getStatusLine();
|
||||||
|
int statusCode = statusLine.getStatusCode();
|
||||||
|
|
||||||
if (statusCode != HttpStatus.SC_OK)
|
if (statusCode != HttpStatus.SC_OK)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("WS call failed: "
|
throw new RuntimeException("WS call failed: "
|
||||||
+ method.getStatusLine());
|
+ statusLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory
|
DocumentBuilderFactory factory = DocumentBuilderFactory
|
||||||
@@ -131,8 +137,7 @@ public class PubmedService
|
|||||||
{
|
{
|
||||||
builder = factory.newDocumentBuilder();
|
builder = factory.newDocumentBuilder();
|
||||||
|
|
||||||
Document inDoc = builder.parse(method
|
Document inDoc = builder.parse(response.getEntity().getContent());
|
||||||
.getResponseBodyAsStream());
|
|
||||||
|
|
||||||
Element xmlRoot = inDoc.getDocumentElement();
|
Element xmlRoot = inDoc.getDocumentElement();
|
||||||
Element idList = XMLUtils.getSingleElement(xmlRoot,
|
Element idList = XMLUtils.getSingleElement(xmlRoot,
|
||||||
@@ -213,28 +218,34 @@ public class PubmedService
|
|||||||
SAXException
|
SAXException
|
||||||
{
|
{
|
||||||
List<Record> results = new ArrayList<Record>();
|
List<Record> results = new ArrayList<Record>();
|
||||||
GetMethod method = null;
|
HttpGet method = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new DefaultHttpClient();
|
||||||
client.setTimeout(5 * timeout);
|
client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5 * timeout);
|
||||||
method = new GetMethod(
|
|
||||||
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi");
|
|
||||||
|
|
||||||
NameValuePair db = new NameValuePair("db", "pubmed");
|
try {
|
||||||
NameValuePair retmode = new NameValuePair("retmode", "xml");
|
URIBuilder uriBuilder = new URIBuilder(
|
||||||
NameValuePair rettype = new NameValuePair("rettype", "full");
|
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi");
|
||||||
NameValuePair id = new NameValuePair("id", StringUtils.join(
|
uriBuilder.addParameter("db", "pubmed");
|
||||||
pubmedIDs.iterator(), ","));
|
uriBuilder.addParameter("retmode", "xml");
|
||||||
method.setQueryString(new NameValuePair[] { db, retmode,
|
uriBuilder.addParameter("rettype", "full");
|
||||||
rettype, id });
|
uriBuilder.addParameter("id", StringUtils.join(
|
||||||
// Execute the method.
|
pubmedIDs.iterator(), ","));
|
||||||
int statusCode = client.executeMethod(method);
|
method = new HttpGet(uriBuilder.build());
|
||||||
|
} catch (URISyntaxException ex)
|
||||||
|
{
|
||||||
|
throw new RuntimeException("Request not sent", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute the method.
|
||||||
|
HttpResponse response = client.execute(method);
|
||||||
|
StatusLine statusLine = response.getStatusLine();
|
||||||
|
int statusCode = statusLine.getStatusCode();
|
||||||
|
|
||||||
if (statusCode != HttpStatus.SC_OK)
|
if (statusCode != HttpStatus.SC_OK)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("WS call failed: "
|
throw new RuntimeException("WS call failed: " + statusLine);
|
||||||
+ method.getStatusLine());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory
|
DocumentBuilderFactory factory = DocumentBuilderFactory
|
||||||
@@ -245,7 +256,7 @@ public class PubmedService
|
|||||||
|
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
Document inDoc = builder
|
Document inDoc = builder
|
||||||
.parse(method.getResponseBodyAsStream());
|
.parse(response.getEntity().getContent());
|
||||||
|
|
||||||
Element xmlRoot = inDoc.getDocumentElement();
|
Element xmlRoot = inDoc.getDocumentElement();
|
||||||
List<Element> pubArticles = XMLUtils.getElementList(xmlRoot,
|
List<Element> pubArticles = XMLUtils.getElementList(xmlRoot,
|
||||||
|
@@ -12,11 +12,11 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
|
||||||
import gr.ekt.bte.core.DataLoader;
|
import gr.ekt.bte.core.DataLoader;
|
||||||
import gr.ekt.bte.core.Record;
|
import gr.ekt.bte.core.Record;
|
||||||
|
import org.apache.http.HttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Bollini
|
* @author Andrea Bollini
|
||||||
|
Reference in New Issue
Block a user