First Commit - Source Code from Reply

This commit is contained in:
vincenzofariello
2024-05-13 12:54:14 +02:00
parent 73e32a5020
commit a15aee1f08
11184 changed files with 1065913 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
/*
* Created on Mar 30, 2005
*
* MNP [project testopiv]
* Copyright (c) 2005
*
* @author Giovanni Amici
* @version 1.0
*/
package test;
/**
* @author Giovanni
*
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.io.RandomAccessFile;
public class Sender {
public static final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><LISTA_MNP_RECORD xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"MNP.xsd\"><FILENAME>" +
"<MITTENTE>TIMG</MITTENTE>" +
"<DATA>2005-06-25</DATA>" +
"<ORA>14:30:00</ORA>" +
"<DESTINATARIO>OPIV</DESTINATARIO>" +
"<ID_FILE>00001</ID_FILE>" +
"</FILENAME>" +
"<ATTIVAZIONE><TIPO_MESSAGGIO>1</TIPO_MESSAGGIO><CODICE_OPERATORE_RECIPIENT>TIMG</CODICE_OPERATORE_RECIPIENT><CODICE_OPERATORE_DONATING>OPIV</CODICE_OPERATORE_DONATING><CODICE_RICHIESTA_RECIPIENT>000000000000000001</CODICE_RICHIESTA_RECIPIENT><MSISDN>883280000001</MSISDN><ICCID_SERIAL_NUMBER>0000000000000000001</ICCID_SERIAL_NUMBER><CODICE_FISCALE_PARTITA_IVA>SRTMCC75C52A345Q</CODICE_FISCALE_PARTITA_IVA><CODICE_PRE_POST_PAGATO>PRP</CODICE_PRE_POST_PAGATO><CODICE_ANALOGICO_DIGITALE>D</CODICE_ANALOGICO_DIGITALE><DATA_CUT_OVER>2100-01-01</DATA_CUT_OVER><NOME_CLIENTE>ANTONELLA</NOME_CLIENTE><COGNOME_CLIENTE>AMICI</COGNOME_CLIENTE><TIPO_DOCUMENTO>PA</TIPO_DOCUMENTO><NUMERO_DOCUMENTO>AQ5633392Z</NUMERO_DOCUMENTO><IMSI>000000000000001</IMSI></ATTIVAZIONE>" +
"</LISTA_MNP_RECORD>";
public Sender() {
}
public static void main(String args[]) {
try {
System.out.println("Inizio test invio..nuovo");
if (args.length > 0) {
sendFile(args[0]);
} else {
simpleSend();
}
System.out.println("Test invio completato con successo!!");
} catch (Exception e) {
System.out.println("Errore test invio:");
e.printStackTrace();
}
}
public static void simpleSend() throws Exception {
test.XMLSender.sendXML(xml, "1", "TIMG20050330122748OPIV00001", "OPIV");
}
public static void sendFile(String fileName) throws Exception {
RandomAccessFile in = null;
try {
in = new RandomAccessFile(fileName, "r");
long len = in.length();
byte[] arr = new byte[(int) len];
in.readFully(arr);
String xml = new String(arr).trim();
System.out.println("I:" + fileName.lastIndexOf('/') + " F:" + fileName.lastIndexOf('.'));
String name = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.lastIndexOf('.'));
String cod_olo = name.substring(18, 22);
System.out.println("***********************************");
System.out.println("Sending:");
System.out.println("XML: <" + xml + ">");
System.out.println("TYPE: <1>");
System.out.println("NAME: <" + name + ">");
System.out.println("OLO: <" + cod_olo + ">");
test.XMLSender.sendXML(xml, "1", name, cod_olo);
System.out.println("Sending.. END");
System.out.println("***********************************");
} catch (Exception ex) {
System.out.println("Exception:");
ex.printStackTrace();
throw ex;
} finally {
try {
if (in != null) in.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,330 @@
package test;
/**
* Title: TEST INTEROPERATORE
* Description: Mobile Number Portability
* Copyright: Copyright (c) 2002
* Company: ObjectWay spa
* @author
*/
/************************************************************/
// la classe <20> identica a quella di MNP a parte i log di sicurezza
/***********************************************************/
import mnp.utility.CustomSSLSocketFactory;
import mnp.utility.Resources;
import javax.net.ssl.*;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.cert.Certificate;
public class XMLSender {
static URL sendServ;
private static String address;
private static boolean httpsFlag;
private static boolean sslFlag;
static {
try {
address = Resources.getInternalSenderURL();
System.out.println("ADDRESS: ["+address+"]");
sendServ = new URL(address);
httpsFlag = Resources.getInternalHttpsFlag();
System.out.println("HTTPS FLAG: ["+httpsFlag+"]");
sslFlag = Resources.getInternalSslFlag();
System.out.println("SSL FLAG: ["+sslFlag+"]");
} catch (Exception ex) {
System.out.println("Impossibile inizializzare XMLSender.....Controllare proprieta' InternalSenderURL");
}
}
/**
* Chiamata alla servlet SendServlet per l'invio effettivo
*/
public static void sendXML(String filexml, String tipofile, String filename, String codOlo) throws Exception {
int timeout = Resources.getHttpTimeOut();
String response = null;
URL wlsUrl;
// A.P. Modifica per RU_42: eliminazione header verso H3GI (veramente brutto!!)
if (codOlo.equals("H3GI")) {
filexml = stripHeader(filexml);
}
// END
System.out.println("Sending: " + filename + " to FE....");
// CODIFICA: (1 step): Sostituzione caratteri non ammessi con XML
filexml = mnp.utility.functions.xmlString(filexml);
//String test = "\n******* CODIFICA: (1 step:XML)\nfilexml=" + filexml + "&filename=" + filename + "&tipofile=" + tipofile + "&codOlo=" + codOlo;
// CODIFICA: (2 step): Codifica per HTML
filexml = URLEncoder.encode(filexml, "UTF-8");
//test = "\n******* CODIFICA: (2 step:HTTP)\nfilexml=" + filexml + "&filename=" + filename + "&tipofile=" + tipofile + "&codOlo=" + codOlo;
String query = "filexml=" + filexml + "&filename=" + filename + "&tipofile=" + tipofile + "&codOlo=" + codOlo;
//KIT200507
//separazione http e https perche' devono essere usate classi diverse
//causa problemi di memoria
//HTTPS:
if (httpsFlag) {
try {
wlsUrl = new URL(sendServ, address, new com.ibm.net.ssl.internal.www.protocol.https.Handler());
} catch (MalformedURLException ex) {
ex.printStackTrace();
throw ex;
}
System.out.println("wlsUrl " + wlsUrl);
com.ibm.net.ssl.internal.www.protocol.https.HttpsURLConnection sconnection = (com.ibm.net.ssl.internal.www.protocol.https.HttpsURLConnection) wlsUrl.openConnection();
// Caricamento Certificati
if (sslFlag) {
FileInputStream fis = null;
FileInputStream fist = null;
try {
System.out.println("Inizio caricamento certificati per SSL");
String keystore = Resources.getKeyStore("mnpserver1");
String truststore = Resources.getTrustKeyStore();
String keypwd = Resources.getPrivateKeyAliasPwd("mnpserver1");
String IBMJSSEProvider = "IBMJSSE2";
//manager del keystore della Private Key
String alg = KeyManagerFactory.getDefaultAlgorithm();
KeyManagerFactory kmFact = KeyManagerFactory.getInstance(alg, IBMJSSEProvider); //<-- il provider!
fis = new FileInputStream(keystore);
KeyStore ks = KeyStore.getInstance("jks");
ks.load(fis, null);
fis.close();
kmFact.init(ks, keypwd.toCharArray());
KeyManager[] kms = kmFact.getKeyManagers();
//manager del keystore delle CA
String algt = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmFact = TrustManagerFactory.getInstance(algt, IBMJSSEProvider); //<-- il provider!
fist = new FileInputStream(truststore);
KeyStore kst = KeyStore.getInstance("jks");
kst.load(fist, null);
fist.close();
tmFact.init(kst);
TrustManager[] tms = tmFact.getTrustManagers();
//creazione del context SSL
SSLContext sslContext;
sslContext = SSLContext.getInstance("SSL_TLS", IBMJSSEProvider);
sslContext.init(kms, tms, null);
//open connection
sconnection = (com.ibm.net.ssl.internal.www.protocol.https.HttpsURLConnection) wlsUrl.openConnection();
//set del Socket Factory alla connessione https
SSLSocketFactory factory = sslContext.getSocketFactory();
CustomSSLSocketFactory csf = new CustomSSLSocketFactory(factory, timeout);
sconnection.setSSLSocketFactory(csf);
sconnection.setDefaultSSLSocketFactory(csf);
System.out.println("Caricamento certificati per SSL completato");
} catch (IOException ex) {
System.out.println("ERRORE caricamento certificati per SSL");
throw ex;
} finally {
try {
if (fis != null) fis.close();
if (fist != null) fist.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
// Set request method
sconnection.setRequestMethod("POST");
// Apertura canali e scrittura file
sconnection.setDoOutput(true);
sconnection.setDoInput(true);
OutputStreamWriter wout = null;
try {
try {
sconnection.connect();
wout = new OutputStreamWriter(sconnection.getOutputStream());
wout.write(query);
wout.flush();
response = sconnection.getResponseMessage();
System.out.println(" RESPONSE ["+response+"]");
} catch (IOException ex) {
int responseCode = sconnection.getResponseCode();
if (responseCode == java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT) {
// TimeOut nella connessione FE - AOM
throw new InterruptedIOException("Timeout nella connessione fra Front-End e AOM");
} else {
throw ex;
}
}
if (response == null || !response.equalsIgnoreCase("OK")) {
throw new Exception("Bad Response: " + response);
}
} catch (Exception ex1) {
System.out.println("Invio di " + filename + " fallito: " + ex1.getMessage());
throw ex1;
} finally {
securityLogAction(filename, address, "OK".equalsIgnoreCase(response));
try {
sconnection.disconnect();
wout.close();
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("Sending: " + filename + " to FE... DONE, with response: " + response);
}
//HTTP
else {
weblogic.net.http.HttpURLConnection connection = null;
if (httpsFlag) {
System.setProperty("java.protocol.handler.pkgs", "weblogic.net");
connection = new weblogic.net.http.HttpsURLConnection(sendServ);
} else {
connection = new weblogic.net.http.HttpURLConnection(sendServ);
}
// Caricamento Certificati
if (httpsFlag && sslFlag) {
FileInputStream f = null;
try {
KeyStore ks = KeyStore.getInstance("jks");
f = new FileInputStream(Resources.getKeyStore("mnpserver1"));
ks.load(f, null);
PrivateKey key = (PrivateKey) ks.getKey(Resources.getPrivateKeyAlias("mnpserver1"), Resources.getPrivateKeyAliasPwd("mnpserver1").toCharArray());
Certificate[] certChain = ks.getCertificateChain(Resources.getPrivateKeyAlias("mnpserver1"));
((weblogic.net.http.HttpsURLConnection) connection).loadLocalIdentity(certChain, key);
System.out.println("Caricamento certificati per SSL completato");
} catch (IOException ex) {
System.out.println("ERRORE caricamento certificati per SSL");
throw ex;
} finally {
try {
if (f != null)
f.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
//set timeout
connection.setTimeout(timeout);
// Set request method
connection.setRequestMethod("POST");
//connection.setRequestProperty("content", "xml");
// Apertura canali e scrittura file
connection.setDoOutput(true);
connection.setDoInput(true);
OutputStreamWriter wout = null;
try {
try {
connection.connect();
wout = new OutputStreamWriter(connection.getOutputStream());
wout.write(query);
wout.flush();
response = connection.getResponseMessage();
} catch (java.io.InterruptedIOException tex) {
// TimeOut nella connessione BE - FE
throw new InterruptedIOException("Timeout nella connessione con il Front-end");
} catch (IOException ex) {
int responseCode = connection.getResponseCode();
if (responseCode == java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT) {
// TimeOut nella connessione FE - AOM
throw new InterruptedIOException("Timeout nella connessione fra Front-End e AOM");
} else {
throw ex;
}
}
if (response == null || !response.equalsIgnoreCase("OK")) {
throw new Exception("Bad Response: " + response);
}
} catch (Exception ex1) {
System.out.println("Invio di " + filename + " fallito: " + ex1.getMessage());
throw ex1;
} finally {
securityLogAction(filename, address, "OK".equalsIgnoreCase(response));
try {
connection.disconnect();
wout.close();
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("Sending: " + filename + " to FE... DONE, with response: " + response);
}
}
/**
* A.P. MODIFICA PER H3GI
* Elimina dal tag ACKNOWLEDGE o LISTAMNPRECORD la stringa
* xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"MNP.xsd\"
*
* @param fileXMLString File XML da cui togliere la Stringa
*/
private static final String stripHeader(String fileXMLString) {
String pre = null;
String post = null;
if (fileXMLString.indexOf("ACKNOWLEDGE") != -1) {
pre = fileXMLString.substring(0, fileXMLString.indexOf("<ACKNOWLEDGE"));
pre = pre + "<ACKNOWLEDGE>";
fileXMLString = fileXMLString.substring(fileXMLString.indexOf("<ACKNOWLEDGE"), fileXMLString.length());
} else {
pre = fileXMLString.substring(0, fileXMLString.indexOf("<LISTA_MNP_RECORD"));
pre = pre + "<LISTA_MNP_RECORD>";
fileXMLString = fileXMLString.substring(fileXMLString.indexOf("<LISTA_MNP_RECORD"), fileXMLString.length());
}
post = fileXMLString.substring(fileXMLString.indexOf(">") + 1, fileXMLString.length());
return pre + post;
}
public static void main(String[] args) {
RandomAccessFile in = null;
try {
in = new RandomAccessFile("c:/JBuilder4/tomcat/webapps/mnp/src/testXML/OPIV20020624120600TIMG02030.xml", "r");
long len = in.length();
byte[] arr = new byte[(int) len];
in.readFully(arr);
String xml = new String(arr).trim();
String name = "OPIV20020624120600TIMG02030";
String cod_olo = name.substring(0, 4);
System.out.println("Sending:\n********* XML:\n" + xml +
"\n********* TYPE:\n 1" +
"\n********* NAME:\n" + name +
"\n********* OLO:\n" + cod_olo);
sendXML(xml, "1", name, cod_olo);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (in != null) in.close();
} catch (Exception ex) {
}
}
}
public static void securityLogAction(String oggetto, String parametro, boolean isOK) {
// nothing to do!!!
}
}