First Commit from Source Code Reply

This commit is contained in:
vincenzofariello
2024-05-09 17:40:24 +02:00
parent 11e3b57c5b
commit 107a016cb9
35225 changed files with 1111346 additions and 1 deletions

View File

@@ -0,0 +1,147 @@
package it.valueteam.gnpsim.sender;
import java.util.*;
import it.valueteam.gnp.service.*;
import it.valueteam.gnpsim.utility.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import tim.infobus.data.IBData;
import it.valueteam.gnpsim.obj.SystemMap;
public class IBSender {
private static Properties propIB = SimConfFile.getInstance().ReadSection(
"InfobusIN");
public IBSender() {
}
public static final void main(String[] args) throws Exception {
IBSender sender = new IBSender();
if (args.length < 1)
throw new Exception("Parametri insufficenti");
int system = Integer.parseInt(args[0]);
String serviceName = null;
if (args.length == 2) {
serviceName = args[1];
}
String readingPath = null;
switch (system) {
case SystemMap.SISTEMA_CRMB:
readingPath = propIB.getProperty("GEN_PATH_CRMB");
System.out.println("Reading folder " + readingPath);
sender.sendFiles(readingPath, system, serviceName);
break;
case SystemMap.SISTEMA_CRMR:
readingPath = propIB.getProperty("GEN_PATH_CRMR");
sender.sendFiles(readingPath,system, serviceName);
break;
case SystemMap.SISTEMA_CRMR_HZ:
readingPath = propIB.getProperty("GEN_PATH_CRMB_HZ");
sender.sendHZFiles(readingPath,system);
break;
case SystemMap.SISTEMA_CRMB_DONOR:
readingPath = propIB.getProperty("GEN_PATH_CRMB_DONOR");
sender.sendFiles(readingPath,system, serviceName);
break;
case SystemMap.SISTEMA_CRMR_DONOR:
readingPath = propIB.getProperty("GEN_PATH_CRMR_DONOR");
sender.sendFiles(readingPath,system, serviceName);
break;
}
}
private void sendHZFiles(String readingPath, int system) throws Exception {
String[] toSend = IOUtility.readFileXML(readingPath);
for (int i = 0; i < toSend.length; i++) {
sendHZRequest(toSend[i], system);
}
}
private void sendFiles(String readingPath, int system, String serviceName) throws Exception {
String[] toSend = IOUtility.readFileXML(readingPath);
for (int i = 0; i < toSend.length; i++) {
sendRequest(toSend[i], system, serviceName);
}
}
public void sendRequest(String tracciato, int system) throws Exception {
sendRequest(tracciato, system, null);
}
public void sendRequest(String tracciato, int system, String ibServiceName) throws Exception {
String jndiName = SystemMap.getServiceFromSimValue(system);
switch (system) {
case SystemMap.SISTEMA_CRMR:
case SystemMap.SISTEMA_CRMB:
AcqServiceHome acqServiceHome = (AcqServiceHome) PortableRemoteObject.narrow(getHomeIbIn(jndiName), AcqServiceHome.class);
AcqService service = acqServiceHome.create();
service.richiestaCRM(createIBData(system, tracciato, ibServiceName));
break;
case SystemMap.SISTEMA_CRMB_DONOR:
case SystemMap.SISTEMA_CRMR_DONOR:
VerificaCSResponseHome verificaCSResponseHome = (VerificaCSResponseHome) PortableRemoteObject.narrow(getHomeIbIn(jndiName), VerificaCSResponseHome.class);
VerificaCSResponse csResponse = verificaCSResponseHome.create();
csResponse.esitoVerificaCS(createIBData(system, tracciato, ibServiceName));
break;
default:
throw new Exception("Sistema sconociuto");
}
}
public void sendHZRequest(String tracciato, int system) throws Exception {
String jndiName = SystemMap.getServiceFromSimValue(system);
AcqServiceHZHome acqServiceHome = (AcqServiceHZHome) PortableRemoteObject.narrow(getHomeIbIn(jndiName), AcqServiceHZHome.class);
AcqServiceHZ service = acqServiceHome.create();
service.richiestaCRM(createIBData(system, tracciato, null));
}
private IBData createIBData(int system, String tracciato, String ibServiceName) throws Exception {
IBData ibData = new IBData();
byte[] bDati = tracciato.getBytes();
ibData.setData(bDati);
ibData.setSystem(SystemMap.getSystemFromSimValue(system));
if (ibServiceName != null) {
ibData.setService( ibServiceName );
}
return ibData;
}
private static Object getHomeIbIn(String jndiName) throws Exception {
Context ctx = getServerContextForIBIN();
Object ref = ctx.lookup(jndiName);
return ref;
}
private static Context getServerContextForIBIN() throws Exception {
Hashtable<String, String> ht = new Hashtable<String, String>();
Context ctx = null;
ht.put(Context.INITIAL_CONTEXT_FACTORY, propIB
.getProperty("initialContextFactory"));
ht.put(Context.SECURITY_PRINCIPAL, propIB.getProperty("user"));
ht.put(Context.SECURITY_CREDENTIALS, propIB.getProperty("password"));
ht.put(Context.PROVIDER_URL, propIB.getProperty("url"));
ctx = new InitialContext(ht);
return ctx;
}
}

View File

@@ -0,0 +1,144 @@
package it.valueteam.gnpsim.sender;
import it.valueteam.gnpsim.utility.SimConfFile;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;
public class SOAPSender {
private static Properties propWSPitagora = SimConfFile.getInstance().ReadSection("WS_Pitagora");
private static Properties propWSCRMA = SimConfFile.getInstance().ReadSection("WS_CRMA");
private static final int MIN_PARAMS_NUMBER = 1;
private static final int PARAM_SISTEMA_IDX = 0;
private static final int PARAM_SISTEMA_PITAGORA = 1;
private static final int PARAM_SISTEMA_CRMA = 2;
private URL url;
private String filepath;
private SOAPSender(Properties props)
throws Exception
{
// Create the connection where we're going to send the file.
url = new URL(props.getProperty("WS_ENDPOINT"));
filepath = props.getProperty("GEN_PATH");
}
public static void main(String[] args) throws Exception {
if(args.length < MIN_PARAMS_NUMBER)
throw new Exception("Numero parametri insufficiente. Consultare la documentazione");
SOAPSender sender = null;
int sistema = Integer.parseInt(args[PARAM_SISTEMA_IDX]);
switch(sistema)
{
case PARAM_SISTEMA_PITAGORA:
sender = new SOAPSender(propWSPitagora);
break;
case PARAM_SISTEMA_CRMA:
sender = new SOAPSender(propWSCRMA);
break;
default:
throw new Exception("Sistema sconosciuto");
}
sender.sendAllFiles();
}
// copy method from From E.R. Harold's book "Java I/O"
public static void copy(InputStream in, OutputStream out)
throws IOException {
// do not allow other threads to read from the
// input or write to the output while copying is
// taking place
synchronized (in) {
synchronized (out) {
byte[] buffer = new byte[256];
while (true) {
int bytesRead = in.read(buffer);
if (bytesRead == -1) break;
out.write(buffer, 0, bytesRead);
}
}
}
}
private void sendAllFiles()
throws Exception
{
File directory = new File(filepath);
String[] fileNames = directory.list();
for(int i=0; i < fileNames.length; ++i)
{
sendFile(fileNames[i]);
File filesent = new File(filepath+fileNames[i]);
filesent.delete();
}
}
private void sendFile(String fileName)
throws Exception
{
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
// Open the input file. After we copy it to a byte array, we can see
// how big it is so that we can set the HTTP Cotent-Length
// property. (See complete e-mail below for more on this.)
String xmlFile2Send = filepath + fileName;
System.out.println("Invio messaggio SOAP contenuto nel file " + xmlFile2Send);
System.out.println("All'indirizzo " + url);
FileInputStream fin = new FileInputStream(xmlFile2Send);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
// Copy the SOAP file to the open connection.
copy(fin,bout);
fin.close();
byte[] b = bout.toByteArray();
// Set the appropriate HTTP parameters.
httpConn.setRequestProperty( "Content-Length",
String.valueOf( b.length ) );
httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8");
// httpConn.setRequestProperty("SOAPAction",SOAPAction);
httpConn.setRequestMethod( "POST" );
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
// Everything's set up; send the XML that was read in to b.
OutputStream out = httpConn.getOutputStream();
out.write( b );
out.close();
// Read the response and write it to standard out.
InputStreamReader isr =
new InputStreamReader(httpConn.getInputStream());
BufferedReader in = new BufferedReader(isr);
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}