1 |
32307
|
claudio.at
|
package eu.dnetlib.data.download;
|
2 |
26600
|
sandro.lab
|
|
3 |
40523
|
claudio.at
|
import java.security.KeyManagementException;
|
4 |
|
|
import java.security.NoSuchAlgorithmException;
|
5 |
45027
|
alessia.ba
|
import java.security.Security;
|
6 |
40523
|
claudio.at
|
import java.security.cert.CertificateException;
|
7 |
|
|
import java.util.ArrayList;
|
8 |
|
|
import java.util.List;
|
9 |
|
|
import javax.annotation.Resource;
|
10 |
|
|
import javax.net.ssl.*;
|
11 |
|
|
import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
12 |
|
|
|
13 |
32499
|
sandro.lab
|
import eu.dnetlib.data.download.rmi.DownloadItem;
|
14 |
|
|
import eu.dnetlib.data.download.rmi.DownloadService;
|
15 |
|
|
import eu.dnetlib.data.download.rmi.DownloadServiceException;
|
16 |
|
|
import eu.dnetlib.data.download.rmi.DownloadServiceFeeder;
|
17 |
37002
|
sandro.lab
|
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException;
|
18 |
26600
|
sandro.lab
|
import eu.dnetlib.enabling.tools.AbstractBaseService;
|
19 |
|
|
import eu.dnetlib.enabling.tools.blackboard.NotificationHandler;
|
20 |
39411
|
claudio.at
|
import org.apache.commons.logging.Log;
|
21 |
|
|
import org.apache.commons.logging.LogFactory;
|
22 |
|
|
import org.springframework.beans.factory.annotation.Required;
|
23 |
|
|
import org.springframework.beans.factory.annotation.Value;
|
24 |
26600
|
sandro.lab
|
|
25 |
|
|
/**
|
26 |
|
|
* The Class DownloadServiceImpl.
|
27 |
|
|
*/
|
28 |
|
|
public class DownloadServiceImpl extends AbstractBaseService implements DownloadService {
|
29 |
|
|
|
30 |
39411
|
claudio.at
|
/**
|
31 |
|
|
* The Constant END_QUEUE.
|
32 |
|
|
*/
|
33 |
26600
|
sandro.lab
|
public static final DownloadItem END_QUEUE = new DownloadItem();
|
34 |
|
|
|
35 |
32499
|
sandro.lab
|
public static final String END_QUEUE_STRING = "END_DOWNLOAD";
|
36 |
32020
|
sandro.lab
|
|
37 |
39411
|
claudio.at
|
/**
|
38 |
|
|
* The Constant log.
|
39 |
|
|
*/
|
40 |
|
|
private static final Log log = LogFactory.getLog(DownloadServiceImpl.class);
|
41 |
42001
|
alessia.ba
|
private static int DEFAULT_CONNECT_TIMEOUT_MS = 5000;
|
42 |
|
|
private static int DEFAULT_READ_TIMEOUT_MS = 5000;
|
43 |
39411
|
claudio.at
|
/**
|
44 |
|
|
* The download plugin enumerator.
|
45 |
|
|
*/
|
46 |
30077
|
sandro.lab
|
@Resource
|
47 |
40523
|
claudio.at
|
private DownloadPluginEnumeratorImpl downloadPluginEnumerator;
|
48 |
39411
|
claudio.at
|
@Resource
|
49 |
|
|
private DownloadServiceFeeder downloadfeeder;
|
50 |
|
|
/**
|
51 |
|
|
* The notification handler.
|
52 |
|
|
*/
|
53 |
26600
|
sandro.lab
|
private NotificationHandler notificationHandler;
|
54 |
32499
|
sandro.lab
|
@Value("${services.download.http.sslcheck}")
|
55 |
|
|
private boolean checkCerts;
|
56 |
45027
|
alessia.ba
|
@Value("${services.download.https.protocols}")
|
57 |
|
|
private String httpsProtocols;
|
58 |
32307
|
claudio.at
|
|
59 |
26600
|
sandro.lab
|
/*
|
60 |
|
|
* (non-Javadoc)
|
61 |
33251
|
sandro.lab
|
*
|
62 |
26600
|
sandro.lab
|
* @see eu.dnetlib.data.download.rmi.DownloadService#downloadFromResultSet(javax.xml.ws.wsaddressing.W3CEndpointReference,
|
63 |
|
|
* java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
64 |
|
|
*/
|
65 |
|
|
@Override
|
66 |
|
|
public void downloadFromResultSet(final W3CEndpointReference resultSet,
|
67 |
|
|
final String plugin,
|
68 |
|
|
final String objectStoreID,
|
69 |
|
|
final String protocol,
|
70 |
|
|
final String mimeType) throws DownloadServiceException {
|
71 |
|
|
|
72 |
39411
|
claudio.at
|
log.info(String.format("download using plugin '%s' , protocol '%s' into ObjectStore '%s'", plugin, protocol, objectStoreID));
|
73 |
37002
|
sandro.lab
|
try {
|
74 |
42001
|
alessia.ba
|
downloadfeeder.download(resultSet.toString(), plugin, objectStoreID, protocol, mimeType, 5, null, null, DEFAULT_CONNECT_TIMEOUT_MS,
|
75 |
42081
|
alessia.ba
|
DEFAULT_READ_TIMEOUT_MS, 0);
|
76 |
37002
|
sandro.lab
|
} catch (ObjectStoreServiceException e) {
|
77 |
|
|
log.error(e);
|
78 |
|
|
}
|
79 |
32307
|
claudio.at
|
log.info(String.format("download completed using plugin '%s' , protocol '%s' into ObjectStore '%s'", plugin, protocol, objectStoreID));
|
80 |
26600
|
sandro.lab
|
}
|
81 |
|
|
|
82 |
|
|
/**
|
83 |
|
|
* {@inheritDoc}
|
84 |
30077
|
sandro.lab
|
*
|
85 |
26600
|
sandro.lab
|
* @see eu.dnetlib.enabling.tools.AbstractBaseService#notify(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
86 |
|
|
*/
|
87 |
|
|
@Override
|
88 |
|
|
public void notify(final String subscriptionId, final String topic, final String isId, final String message) {
|
89 |
|
|
getNotificationHandler().notified(subscriptionId, topic, isId, message);
|
90 |
|
|
}
|
91 |
|
|
|
92 |
32499
|
sandro.lab
|
@Override
|
93 |
|
|
public void start() {
|
94 |
|
|
if (!checkCerts) {
|
95 |
45027
|
alessia.ba
|
log.info("disabling SSL check ...");
|
96 |
32499
|
sandro.lab
|
new Thread(new Runnable() {
|
97 |
32307
|
claudio.at
|
|
98 |
32499
|
sandro.lab
|
@Override
|
99 |
|
|
public void run() {
|
100 |
|
|
disableSslVerification();
|
101 |
|
|
}
|
102 |
|
|
}).start();
|
103 |
|
|
}
|
104 |
45348
|
claudio.at
|
//Security.insertProviderAt(new BouncyCastleProvider(),1);
|
105 |
|
|
//System.setProperty("https.protocols", httpsProtocols);
|
106 |
32499
|
sandro.lab
|
}
|
107 |
32307
|
claudio.at
|
|
108 |
32499
|
sandro.lab
|
private void disableSslVerification() {
|
109 |
|
|
try {
|
110 |
|
|
// Create a trust manager that does not validate certificate chains
|
111 |
|
|
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
|
112 |
32307
|
claudio.at
|
|
113 |
32499
|
sandro.lab
|
@Override
|
114 |
|
|
public void checkClientTrusted(final java.security.cert.X509Certificate[] x509Certificates, final String s) throws CertificateException {
|
115 |
32307
|
claudio.at
|
|
116 |
32499
|
sandro.lab
|
}
|
117 |
32307
|
claudio.at
|
|
118 |
32499
|
sandro.lab
|
@Override
|
119 |
|
|
public void checkServerTrusted(final java.security.cert.X509Certificate[] x509Certificates, final String s) throws CertificateException {
|
120 |
32307
|
claudio.at
|
|
121 |
32499
|
sandro.lab
|
}
|
122 |
32307
|
claudio.at
|
|
123 |
32499
|
sandro.lab
|
@Override
|
124 |
|
|
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
125 |
|
|
return null;
|
126 |
|
|
}
|
127 |
|
|
} };
|
128 |
32307
|
claudio.at
|
|
129 |
32499
|
sandro.lab
|
// Install the all-trusting trust manager
|
130 |
|
|
SSLContext sc = SSLContext.getInstance("SSL");
|
131 |
|
|
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
132 |
|
|
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
133 |
32307
|
claudio.at
|
|
134 |
32499
|
sandro.lab
|
// Create all-trusting host name verifier
|
135 |
|
|
HostnameVerifier allHostsValid = new HostnameVerifier() {
|
136 |
|
|
|
137 |
|
|
@Override
|
138 |
|
|
public boolean verify(final String hostname, final SSLSession session) {
|
139 |
|
|
return true;
|
140 |
|
|
}
|
141 |
|
|
};
|
142 |
|
|
|
143 |
|
|
// Install the all-trusting host verifier
|
144 |
|
|
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
|
145 |
|
|
log.info("disabled SSL check");
|
146 |
|
|
} catch (NoSuchAlgorithmException e) {
|
147 |
|
|
log.error(e.getMessage(), e);
|
148 |
|
|
} catch (KeyManagementException e) {
|
149 |
|
|
log.error(e.getMessage(), e);
|
150 |
|
|
}
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
/**
|
154 |
26600
|
sandro.lab
|
* @return the downloadfeeder
|
155 |
|
|
*/
|
156 |
|
|
public DownloadServiceFeeder getDownloadfeeder() {
|
157 |
|
|
return downloadfeeder;
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
/**
|
161 |
39411
|
claudio.at
|
* @param downloadfeeder the downloadfeeder to set
|
162 |
26600
|
sandro.lab
|
*/
|
163 |
|
|
public void setDownloadfeeder(final DownloadServiceFeeder downloadfeeder) {
|
164 |
|
|
this.downloadfeeder = downloadfeeder;
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
/**
|
168 |
|
|
* @return the notificationHandler
|
169 |
|
|
*/
|
170 |
|
|
public NotificationHandler getNotificationHandler() {
|
171 |
|
|
return notificationHandler;
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
/**
|
175 |
39411
|
claudio.at
|
* @param notificationHandler the notificationHandler to set
|
176 |
26600
|
sandro.lab
|
*/
|
177 |
|
|
@Required
|
178 |
|
|
public void setNotificationHandler(final NotificationHandler notificationHandler) {
|
179 |
|
|
this.notificationHandler = notificationHandler;
|
180 |
|
|
}
|
181 |
|
|
|
182 |
30077
|
sandro.lab
|
@Override
|
183 |
|
|
public List<String> listPlugins() throws DownloadServiceException {
|
184 |
|
|
|
185 |
|
|
List<String> result = new ArrayList<String>();
|
186 |
|
|
result.addAll(downloadPluginEnumerator.getAll().keySet());
|
187 |
|
|
return result;
|
188 |
|
|
}
|
189 |
|
|
|
190 |
26600
|
sandro.lab
|
}
|