Révision bf9c3717
Ajouté par Remy Menard il y a environ 11 ans
ETa/ETa-Callback/ETa-Callback-Sender/src/main/java/fr/unicaen/iota/eta/callback/sender/CallbackOperationsModule.java | ||
---|---|---|
import java.io.*;
|
||
import java.net.HttpURLConnection;
|
||
import java.net.MalformedURLException;
|
||
import java.net.SocketTimeoutException;
|
||
import java.net.URL;
|
||
import java.security.KeyStore;
|
||
import java.security.SecureRandom;
|
||
import java.sql.DriverManager;
|
||
import java.sql.SQLException;
|
||
import java.util.Properties;
|
||
import javax.jms.*;
|
||
import javax.net.ssl.HttpsURLConnection;
|
||
import javax.net.ssl.KeyManagerFactory;
|
||
import javax.net.ssl.SSLContext;
|
||
import javax.net.ssl.TrustManager;
|
||
import javax.net.ssl.X509TrustManager;
|
||
import javax.net.ssl.TrustManagerFactory;
|
||
import javax.xml.XMLConstants;
|
||
import javax.xml.parsers.DocumentBuilder;
|
||
import javax.xml.parsers.DocumentBuilderFactory;
|
||
... | ... | |
}
|
||
|
||
/**
|
||
* Connects to the Message Broker, gets and sends events to users.
|
||
* Connects to the Message Broker, gets and sends events to user.
|
||
*
|
||
* @throws JMSException If an error receiving or sending message occurred.
|
||
* @throws MalformedURLException If a destination url is malformed.
|
||
... | ... | |
try {
|
||
int response = send(docText, dest);
|
||
LOG.info("Event sent.");
|
||
} catch (SocketTimeoutException e) {
|
||
} catch (IOException e) {
|
||
} catch (Exception e) {
|
||
Session prodS = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
|
||
Destination sendDest = prodS.createQueue(Constants.ACTIVEMQ_QUEUE_NAME);
|
||
MessageProducer producer = prodS.createProducer(sendDest);
|
||
TextMessage messageToSend = prodS.createTextMessage();
|
||
messageToSend.setText(docText);
|
||
producer.send(messageToSend);
|
||
LOG.info("Fails to send event: event resent.");
|
||
String msg = "Fails to send event to " + dest + " : event resent.";
|
||
if (LOG.isDebugEnabled()) {
|
||
LOG.debug(msg, e);
|
||
}
|
||
else {
|
||
LOG.info(msg);
|
||
}
|
||
}
|
||
message.acknowledge();
|
||
}
|
||
... | ... | |
* @param dest The destination to send the data to.
|
||
* @return The response code.
|
||
* @throws MalformedURLException If the destination url is not conformed.
|
||
* @throws SocketTimeoutException
|
||
* @throws IOException If a communication error occurred.
|
||
* @throws Exception
|
||
*/
|
||
public int send(String data, String dest)
|
||
throws MalformedURLException, SocketTimeoutException, IOException, Exception {
|
||
throws MalformedURLException, IOException, Exception {
|
||
// set up connection and send data to given destination
|
||
URL serviceUrl;
|
||
try {
|
||
... | ... | |
response = connection.getResponseCode();
|
||
connection.disconnect();
|
||
return response;
|
||
} catch (SocketTimeoutException e) {
|
||
throw e;
|
||
} catch (IOException e) {
|
||
throw new IOException("Unable to send results of subscribed query to '"
|
||
+ dest + "'", e);
|
||
throw new IOException("Unable to send results of subscribed query to '" + dest + "'", e);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Opens a connection to the EPCIS capture interface.
|
||
* Opens a connection to the user interface.
|
||
* @param url The address on which a connection will be opened.
|
||
* @return The HTTP connection object.
|
||
* @throws IOException If an error occurred connecting to the interface.
|
||
* @throws Exception
|
||
*/
|
||
private HttpURLConnection getConnection(String url) throws IOException {
|
||
System.setProperty("javax.net.ssl.keyStore", Constants.PKS_FILENAME);
|
||
System.setProperty("javax.net.ssl.keyStorePassword", Constants.PKS_PASSWORD);
|
||
System.setProperty("javax.net.ssl.trustStore", Constants.TRUST_PKS_FILENAME);
|
||
System.setProperty("javax.net.ssl.trustStorePassword", Constants.TRUST_PKS_PASSWORD);
|
||
private HttpURLConnection getConnection(String url) throws IOException, Exception {
|
||
if (Constants.PKS_FILENAME != null && Constants.PKS_PASSWORD != null
|
||
&& Constants.TRUST_PKS_FILENAME != null && Constants.TRUST_PKS_PASSWORD != null) {
|
||
System.setProperty("javax.net.ssl.keyStore", Constants.PKS_FILENAME);
|
||
System.setProperty("javax.net.ssl.keyStorePassword", Constants.PKS_PASSWORD);
|
||
System.setProperty("javax.net.ssl.trustStore", Constants.TRUST_PKS_FILENAME);
|
||
System.setProperty("javax.net.ssl.trustStorePassword", Constants.TRUST_PKS_PASSWORD);
|
||
}
|
||
URL serviceUrl = new URL(url);
|
||
HttpURLConnection connection = (HttpURLConnection) serviceUrl.openConnection();
|
||
|
||
if (Constants.PKS_FILENAME != null) {
|
||
KeyStore keyStore = KeyStore.getInstance(Constants.PKS_FILENAME.endsWith(".p12") ? "PKCS12" : "JKS");
|
||
keyStore.load(new FileInputStream(new File(Constants.PKS_FILENAME)), Constants.PKS_PASSWORD.toCharArray());
|
||
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
|
||
keyManagerFactory.init(keyStore, Constants.PKS_PASSWORD.toCharArray());
|
||
KeyStore trustStore = KeyStore.getInstance(Constants.TRUST_PKS_FILENAME.endsWith(".p12") ? "PKCS12" : "JKS");
|
||
trustStore.load(new FileInputStream(new File(Constants.TRUST_PKS_FILENAME)), Constants.TRUST_PKS_PASSWORD.toCharArray());
|
||
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509");
|
||
trustManagerFactory.init(trustStore);
|
||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());
|
||
((HttpsURLConnection) connection).setSSLSocketFactory(sslContext.getSocketFactory());
|
||
}
|
||
|
||
connection.setRequestProperty("content-type", "text/xml");
|
||
connection.setRequestMethod("POST");
|
||
connection.setReadTimeout(200);
|
Formats disponibles : Unified diff
Version 1.99
- a few bugs fixed!
- new testing application to capture events
- new options to the command line to configure the public/private keys
for TLS and for signature
- new method more accurate than "traceEPC": the events are sorted by
EPCIS
- New options added to the command line
- user can be identified by alias, if the DN of his certificate is
incompatible with the LDAP directory
- new shell script to configure the LDAP directory (same
functionnalities as IoTa-Installer)
- installs and configures LaMBDa
- finer certificate mangagement
- EpcILoN correctly subscribe with TLS to ETa
- new figure for LaMBDa
- shows data flows between PHI and YPSilon
- sets DS and DSeTa in different schemas