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

73
gnpdev/crontab/build.xml Normal file
View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="CRONTAB" default="default" basedir=".">
<description>Builds, tests, and runs the project CRONTAB.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="CRONTAB-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

View File

@@ -0,0 +1,4 @@
Manifest-Version: 1.0
Created-By: 1.4.2_04-b05 (Sun Microsystems Inc.)
Ant-Version: Apache Ant 1.6.2

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<session>
<display-name>ProcessServer</display-name>
<ejb-name>ProcessServer</ejb-name>
<home>it.valueteam.crontab.processexecutor.ejb.ProcessServerHome</home>
<remote>it.valueteam.crontab.processexecutor.ejb.ProcessServer</remote>
<ejb-class>it.valueteam.crontab.processexecutor.ejb.ProcessServerBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>ProcessServer</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>NotSupported</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN" "http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd">
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>ProcessServer</ejb-name>
<stateless-session-descriptor>
<pool>
<max-beans-in-free-pool>20</max-beans-in-free-pool>
<initial-beans-in-free-pool>1</initial-beans-in-free-pool>
</pool>
</stateless-session-descriptor>
<enable-call-by-reference>true</enable-call-by-reference>
<jndi-name>ejb/processServer</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
build.xml.data.CRC32=08cd07d2
build.xml.script.CRC32=56941166
build.xml.stylesheet.CRC32=8064a381@1.75.2.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=08cd07d2
nbproject/build-impl.xml.script.CRC32=1b65425f
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48

View File

@@ -0,0 +1,80 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=CRONTAB
application.vendor=giuseppe
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/CRONTAB.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=/home/developer/Documenti/TIM_AOM/DBCFX/FE/gnpapp/lib/
excludes=
file.reference.crontab-src=src
file.reference.weblogic.jar=/bea/wlserver_10.3/server/lib/weblogic.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.weblogic.jar}:\
${reference.SecurityUtility.jar}:\
${libs.DBCFXGO_LIB.classpath}:\
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.6
javac.target=1.6
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=JDK_1.6
project.SecurityUtility=../SecurityUtility
reference.SecurityUtility.jar=${project.SecurityUtility}/dist/SecurityUtility.jar
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=${file.reference.crontab-src}

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>CRONTAB</name>
<explicit-platform explicit-source-supported="true"/>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots/>
</data>
<references xmlns="http://www.netbeans.org/ns/ant-project-references/1">
<reference>
<foreign-project>SecurityUtility</foreign-project>
<artifact-type>jar</artifact-type>
<script>build.xml</script>
<target>jar</target>
<clean-target>clean</clean-target>
<id>jar</id>
</reference>
</references>
</configuration>
</project>

View File

@@ -0,0 +1,29 @@
package it.valueteam.crontab.processexecutor;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author Carlo Poccia
* @version 1.0
*/
public class ProcessException extends Exception {
public ProcessException(String msg) {
super(msg);
}
public ProcessException(Exception e) {
super(e);
}
public ProcessException(Throwable e) {
super(e);
}
public ProcessException(String msg, Exception e) {
super(msg, e);
}
}

View File

@@ -0,0 +1,134 @@
package it.valueteam.crontab.processexecutor;
import it.valueteam.crontab.processexecutor.ejb.*;
import it.valueteam.crontab.processexecutor.utility.*;
import javax.naming.Context;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.*;
import it.valueteam.crontab.utility.ClusterRoundRobinServiceLocator;
/**
* <p>Title: Mobile Number Portability </p>
* <p>Description: Classe client per l'esecuzione di processi </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author Carlo Poccia
* @version 1.0
*/
public class ProcessExecutor {
private static final String JNDI_NAME ="ejb/processServer";
public ProcessExecutor() {}
/**
* Esegue un processo invocato da un client interno all'application server
*
* @param args String[] - Parametri di esecuzione del processo
* @throws ProcessException - Eccezione applicativa rilanciata al client
*/
public void executeProcess(String[] args) throws ProcessException {
Properties pNull=null;
executeProcess(args,pNull);
}
/**
* Esegue un processo invocato da un client esterno all'application server
*
* @param args String[] - Parametri di esecuzione del processo
* @param env Properties - Contiene le environment variables per la connessione al server
* @throws ProcessException - Eccezione applicativa rilanciata al client
*/
public void executeProcess(String[] args,Properties env) throws ProcessException {
ProcessServerHome processServerHome = null;
ProcessServer processServer = null;
try {
processServerHome = (ProcessServerHome) lookup(env);
processServer = processServerHome.create();
processServer.executeProcess(args);
}
catch (Throwable ex) {
ex.printStackTrace();
throw new ProcessException("Impossibile eseguire il processo: " + args[0] + (args.length>1?" con parametro " + args[1]:""));
}
}
/**
* Esegue un processo invocato da un client esterno\interno all'application server soggetto a load balancing
*
* @param args String[] - Parametri di esecuzione del processo
* @param env ClusterEnvironment - Contiene le environment variables per la connessione al cluster
* @throws ProcessException - Eccezione applicativa rilanciata al client
*/
public void executeProcess(String[] args, ClusterEnvironment env) throws ProcessException {
ProcessServerHome processServerLocalHome = null;
ProcessServer processServer = null;
try {
processServerLocalHome =
(ProcessServerHome) ClusterRoundRobinServiceLocator.getInstance(
env.getInitialContextFactory(),
env.getSecurityPrincipal(),
env.getSecurityPrincipal(),
env.getCluster_address()
).getRemoteEJB(JNDI_NAME, ProcessServerHome.class);
processServer = processServerLocalHome.create();
processServer.executeProcess(args);
}
catch (Throwable ex) {
ex.printStackTrace();
throw new ProcessException("Impossibile eseguire il processo: " + args[0] + (args.length>1?" con parametro " + args[1]:""));
}
}
/**
* Esegue la jndi lookup del ProcessServerBean al quale delegare l'esecuzione del processo.
*
* @param env Properties - Contiene le environment variables per la creazione del jndi context
* @return ProcessServerHome - Home Interface del ProcessServerBean
* @throws Exception
*/
private ProcessServerHome lookup(Properties env) throws Exception {
Context ctx = null;
ProcessServerHome processServerHome = null;
try {
if (env==null)
ctx = new InitialContext();
else
ctx = new InitialContext(env);
Object ref = ctx.lookup(JNDI_NAME);
processServerHome = (ProcessServerHome)PortableRemoteObject.narrow(ref, ProcessServerHome.class);
}
catch (Exception ex) {
System.out.println("ECCEZIONE durante il reperimento dell'istanza del EJB: " + this.JNDI_NAME);
ex.printStackTrace();
throw ex;
}
finally {
try {
if (ctx != null) {
ctx.close();
}
}
catch (NamingException ex) {
System.out.println("InitialContext già chiuso");
}
}
return processServerHome;
}
}

View File

@@ -0,0 +1,15 @@
package it.valueteam.crontab.processexecutor;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author Carlo Poccia
* @version 1.0
*/
public interface ProcessIF {
public void execute(String[] args) throws Exception;
public boolean requiredTX();
}

View File

@@ -0,0 +1,53 @@
package it.valueteam.crontab.processexecutor.client;
import it.valueteam.crontab.processexecutor.*;
import javax.naming.Context;
import java.util.Properties;
import it.valueteam.crontab.utility.Resources;
/**
* <p>Title: </p>
*
* <p>Description: Classe che si occupa di invocare il modulo di esecuzione dei processi </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: Valuetean </p>
* @author Mario Giurlanda
* @version 1.0
*/
public class SimpleRunProcess {
public static void main(String args[]) {
SimpleRunProcess runner = new SimpleRunProcess();
runner.run(args);
}
/**
* run
*/
private static void run(String args[]) {
//Creo un istanza del ProcessExecutor al quale delegare l'esecuzione del processo
ProcessExecutor exec = new ProcessExecutor();
try {
exec.executeProcess(args,getJndiProperties());
}
catch (ProcessException ex) {
System.out.println(ex.getMessage());
}
}
private static Properties getJndiProperties(){
Properties ht = new Properties();
ht.put(Context.INITIAL_CONTEXT_FACTORY, Resources.getFE_WLSERVER_CONTEXT_FACTORY());
ht.put(Context.PROVIDER_URL, Resources.getFE_WLSERVER_DBCFX_URL());
return ht;
}
}

View File

@@ -0,0 +1,10 @@
package it.valueteam.crontab.processexecutor.ejb;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
import it.valueteam.crontab.processexecutor.ProcessException;
public interface ProcessServer extends EJBObject {
public void executeProcess(String[] processArgs) throws RemoteException,ProcessException;
}

View File

@@ -0,0 +1,170 @@
package it.valueteam.crontab.processexecutor.ejb;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;
import org.apache.log4j.Logger;
import it.valueteam.crontab.processexecutor.*;
import javax.transaction.UserTransaction;
import javax.naming.*;
import it.valueteam.crontab.utility.*;
import org.apache.log4j.*;
import java.io.FileInputStream;
import java.util.*;
import it.valueteam.crontab.processexecutor.utility.*;
public class ProcessServerBean implements SessionBean {
SessionContext sessionContext;
public static Logger logger ;
public void ejbCreate() throws CreateException {
System.out.println("Inizializzazione del log per il ProcessServerBean");
try {
Properties pp = new Properties();
pp.load(new FileInputStream(Resources.getPROCESS_EXEC_LOG_CONF_FILE()));
LogManager.resetConfiguration();
PropertyConfigurator.configure(pp);
Logger.getRootLogger().info("Logger configured");
logger = Logger.getLogger(ProcessServerBean.class.getName());
System.out.println("Inizializzazione log completata");
}
catch (Exception ex) {
System.out.println(
"Errore durante l'inizializzazione del log per il ProcessServerBean");
ex.printStackTrace();
}
System.out.println("-> ProcessServerBean.ejbCreate() HC: " + hashCode());
}
public void ejbRemove() {
System.out.println("-> ProcessServerBean.ejbRemove() HC: " + hashCode());
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
public void executeProcess(String[] processArgs) throws ProcessException{
logger.info("start executeProcess");
ProcessIF process=null;
String args[]=null;
UserTransaction utx=null;
try {
if(checkFestivita(processArgs)){
logger.info("Processo non eseguito per festività");
}
else{
logger.info("Esecuzione Processo, lancio script");
for (int i = 0; i < processArgs.length; i++)
logger.info("i parametri sono: " + processArgs[i]);
process = ProcessFactory.getProcess(processArgs[0]);
// prendo i parametri del processo;
args = new String[processArgs.length - 1];
System.arraycopy(processArgs, 1, args, 0, processArgs.length - 1);
// controllo se il process deve essere chiamato in transazione;
if (process.requiredTX()) {
//prendo la transazione dal Service locator
//e chiamo il process in transazione
utx = getUserTransaction();
try {
utx.begin();
process.execute(args);
utx.commit();
}
catch (Throwable ex1) {
logger.info("Fine esecuzione processo con eccezioni");
if (utx != null)
utx.rollback();
throw ex1;
}
}
else {
process.execute(args);
logger.info("Fine esecuzione processo");
}
} //chiusura del'else non è festività
}
catch (Throwable ex) {
logger.info("Fine esecuzione processo con eccezioni");
ex.printStackTrace();
throw new ProcessException(ex);
}
}
private boolean checkFestivita(String[] processArgs) {
logger.info("start checkFestivita'");
if(Resources.isFestivo(new EventTime())) {
logger.info("si tratta di festivo");
if(!isBatchToExecuteInFest(processArgs)) {
//non si tratta di un batch da eseguire nei festivi, dunque essendo un giorno fesivi non verrà eseguito
logger.info("Non e' un batch da eseguire nei festivi, il batch non verra' eseguito");
return true;
}
}
logger.info("checkFestivita e' false, Il batch va eseguito");
return false;
}
//check sui batch da eseguire anche nei
private boolean isBatchToExecuteInFest(String[] processArgs) {
logger.info("start isBatchToExecuteInFest");
String batchName = processArgs[0];
logger.info("batchName "+ batchName);
List<String> listBatchToExecuteInFest = Resources.getAllBatchToExecuteInFest();
if(listBatchToExecuteInFest != null) {
logger.info("listBatchToExecuteInFest "+ listBatchToExecuteInFest.toString());
}
return listBatchToExecuteInFest.contains(batchName);
}
/**
* getUserTransaction
*
* @return UserTransaction
*/
private UserTransaction getUserTransaction() throws NamingException {
try {
Context ic = new InitialContext();
UserTransaction utx = (UserTransaction) ic.lookup(
"javax.transaction.UserTransaction");
return utx;
}
catch (NamingException ex) {
throw ex;
}
}
}

View File

@@ -0,0 +1,9 @@
package it.valueteam.crontab.processexecutor.ejb;
import javax.ejb.EJBHome;
import javax.ejb.CreateException;
import java.rmi.RemoteException;
public interface ProcessServerHome extends EJBHome {
public ProcessServer create() throws CreateException, RemoteException;
}

View File

@@ -0,0 +1,60 @@
package it.valueteam.crontab.processexecutor.utility;
/**
* /**
* <p>Title: Mobile Number Portability </p>
* <p>Description:</p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: Valueteam </p>
* @author Mario Giurlanda
* @version 1.0
*/
public class ClusterEnvironment {
private String initialContextFactory;
private String securityPrincipal;
private String securityCrendential;
//indirizzi dei nodi del cluster
private String cluster_address;
public ClusterEnvironment(String iCf, String sP, String sC, String cA) {
this.initialContextFactory = iCf;
this.securityPrincipal = sP;
this.securityCrendential = sC;
this.cluster_address = cA;
}
public String getSecurityCrendential() {
return securityCrendential;
}
public String getSecurityPrincipal() {
return securityPrincipal;
}
public String getCluster_address() {
return cluster_address;
}
public void setInitialContextFactory(String initialContextFactory) {
this.initialContextFactory = initialContextFactory;
}
public void setSecurityCrendential(String securityCrendential) {
this.securityCrendential = securityCrendential;
}
public void setSecurityPrincipal(String securityPrincipal) {
this.securityPrincipal = securityPrincipal;
}
public void setCluster_address(String cluster_address) {
this.cluster_address = cluster_address;
}
public String getInitialContextFactory() {
return initialContextFactory;
}
}

View File

@@ -0,0 +1,40 @@
package it.valueteam.crontab.processexecutor.utility;
import it.valueteam.crontab.processexecutor.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author Carlo Poccia
* @version 1.0
*/
public class ProcessFactory {
private ProcessFactory() {
}
public static ProcessIF getProcess(String processArgs) throws
ProcessException {
ProcessIF process = null;
Class c = null;
try {
if ( (processArgs == null)){// || (processArgs.length == 0)) {
throw new IllegalArgumentException();
}
c = Class.forName(processArgs.trim());
process = (ProcessIF) c.newInstance();
return process;
}
catch (Exception ex) {
System.out.println("CAUSA : "+ex.getCause());
System.out.println("LOCALIZED MESSAGE : "+ex.getLocalizedMessage());
ex.printStackTrace();
throw new ProcessException(ex);
}
}
}

View File

@@ -0,0 +1,201 @@
package it.valueteam.crontab.utility;
import java.util.*;
import javax.naming.*;
import javax.rmi.*;
/**
*
* <p>Title: ClusterRoundRobinServiceLocator </p>
* <p>Description: Questa classe di utilità viene utilizzata
* per il reperimento dell'istanza del TimerExecutorEJB secondo
* l'algoritmo RoundRobin eliminando la server affinity del cluster BEA</p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author C.A.
* @version 1.0
*/
public class ClusterRoundRobinServiceLocator {
// unica istanza del componente
private static ClusterRoundRobinServiceLocator onlyInstance;
private String initial_context_factory;
private String user;
private String password;
//indirizzi dei nodi del cluster
private List server_address;
//indice che mantiene lo stato dell'ultimo server chiamato all'interno del List server_address
private int indexOfServerName;
/**
* il costruttore è privato perchè è un Singleton
*/
private ClusterRoundRobinServiceLocator(String contextFactory, String user,
String pwd, String cluster_address) throws
Exception {
if (!checkParameter(contextFactory, user, pwd, cluster_address))
throw new Exception(
"Errore durante l'inizializzazione del componente. I parametri in ingresso "
+ "non sono valorizzati corretamente");
init(contextFactory, user, pwd, cluster_address);
}
/**
* ritorna l'unica istanza del ClusterRoundRobinServiceLocator
* @return ClusterRoundRobinServiceLocator
*/
public static ClusterRoundRobinServiceLocator getInstance(String
contextFactory, String user, String pwd, String cluster_address) throws
Exception {
if (onlyInstance == null)
onlyInstance = new ClusterRoundRobinServiceLocator(contextFactory, user,
pwd, cluster_address);
return onlyInstance;
}
/**
* Ritorna l'home interface del TimerExecutorEJB secondo l'algoritmo RoundRobin
* eliminando la server affinity del cluster BEA
* @return Object : l'home interface del TimerExecutorEJB
*/
public java.lang.Object getRemoteEJB(String jndiName, Class homeClass) throws
Exception {
Object home = null;
for (int i = 0; i < server_address.size(); i++) {
home = getEJBHome(getNextServerCall(), jndiName,homeClass);
if (home != null)
break;
}
if (home == null)
throw new Exception(
"Impossibile recuperare l'istanza del componente " + jndiName);
return home;
}
/**
* inizializza la classe con i dati per il reperimento del context
*
* @param contextFactory String
* @param user String
* @param pwd String
* @param cluster_ad String
* @param server_ads String[]
*/
private void init(String contextFactory, String user, String pwd,
String cluster_ad) {
String address_prefix = "t3://";
//init degli indirizzi dei nodi del cluster
server_address = new ArrayList();
StringTokenizer strTok = new StringTokenizer(cluster_ad, ",");
int i = 0;
while (strTok.hasMoreElements()) {
if (i == 0)
server_address.add(strTok.nextElement());
else
server_address.add(address_prefix + strTok.nextElement());
i++;
}
this.initial_context_factory = contextFactory;
this.user = user;
this.password = pwd;
indexOfServerName = -1;
}
/**
* Controlla che i parametri passati siano validi
*
* @param contextFactory String
* @param user String
* @param pwd String
* @param cluster_ad String
* @param server_ads String[]
*/
private boolean checkParameter(String contextFactory, String user, String pwd,
String cluster_ad) {
if (contextFactory == null || user == null || pwd == null || cluster_ad == null)
return false;
else
return true;
}
/**
* Ritorna il prossimo nodo su cui recuperare il servizio TimerExecutorEJB
* @throws Exception
*/
private synchronized String getNextServerCall() throws Exception {
indexOfServerName++;
if (indexOfServerName >= server_address.size())
indexOfServerName = 0;
return ( (String) server_address.get(indexOfServerName));
}
/**
* Ritorna il contesto del nodo su cui richiamare il servizio EJB
* @throws NamingException
* @return Context
*/
private Context getServerContext(String url_provider) throws Exception {
Hashtable ht = new Hashtable();
Context ctx = null;
ht.put(Context.INITIAL_CONTEXT_FACTORY, initial_context_factory);
ht.put(Context.SECURITY_PRINCIPAL, user);
ht.put(Context.SECURITY_CREDENTIALS, password);
ht.put(Context.PROVIDER_URL, url_provider);
ctx = new InitialContext(ht);
return ctx;
}
/**
* Ritorna l'home interface del TimerExecutorEJB
* @param url_provider String
* @return Object
*/
private Object getEJBHome(String url_provider, String jndiName,
Class homeClass) {
Context ctx = null;
Object obj = null;
try {
ctx = getServerContext(url_provider);
Object ref = ctx.lookup(jndiName);
obj = PortableRemoteObject.narrow(ref, homeClass);
}
catch (Exception ex) {
System.out.println(
"ECCEZIONE durante il reperimento dell'istanza del EJB: " + jndiName +
" sul nodo : " + url_provider);
ex.printStackTrace();
}
finally {
try {
if (ctx != null) {
ctx.close();
}
}
catch (NamingException ex) {
System.out.println("InitialContext già chiuso");
}
}
return obj;
}
}

View File

@@ -0,0 +1,200 @@
package it.valueteam.crontab.utility;
import java.io.*;
import java.util.*;
public class EventTime
implements Serializable {
public EventTime(Date d) {
this.cal = new GregorianCalendar();
this.cal.setTime(d);
}
public EventTime(long timeInMillis) {
this.cal = new GregorianCalendar();
this.cal.setTime(new Date(timeInMillis));
}
public EventTime(Calendar cal) {
this.cal = new GregorianCalendar();
this.cal.setTime(cal.getTime());
}
public EventTime() {
this.cal = new GregorianCalendar();
}
public EventTime(int year, int mounth, int date) {
this.cal = new GregorianCalendar();
this.cal.set(year, mounth, date);
}
public EventTime(int hour, int minute, int second, int milli) {
this.cal = new GregorianCalendar();
this.cal.set(Calendar.HOUR_OF_DAY, hour);
this.cal.set(Calendar.MINUTE, minute);
this.cal.set(Calendar.SECOND, second);
}
public EventTime(EventTime evt) {
this.cal = new GregorianCalendar();
this.cal.setTime(evt.getTime());
}
public void approxToMinute() {
this.cal.set(Calendar.SECOND, 0);
this.cal.set(Calendar.MILLISECOND, 0);
}
public boolean before(EventTime evt) {
return this.cal.before(evt.cal);
}
public boolean equals(EventTime evt) {
return this.cal.equals(evt.cal);
}
public boolean after(EventTime evt) {
return this.cal.after(evt.cal);
}
public static EventTime max(EventTime evt1, EventTime evt2) {
long v1 = evt1.getTimeInMillis();
long v2 = evt2.getTimeInMillis();
return (v1 < v2) ? evt2 : evt1;
}
public static EventTime min(EventTime evt1, EventTime evt2) {
long v1 = evt1.getTimeInMillis();
long v2 = evt2.getTimeInMillis();
return (v1 < v2) ? evt1 : evt2;
}
public EventTime getRelEvent(int field, int value) {
EventTime newEvt = new EventTime(this);
newEvt.set(field, value);
return newEvt;
}
public EventTime getRelEvent(int hour, int minute, int second, int millis) {
EventTime newEvt = new EventTime(this);
newEvt.set(Calendar.HOUR_OF_DAY, hour);
newEvt.set(Calendar.MINUTE, minute);
newEvt.set(Calendar.SECOND, second);
newEvt.set(Calendar.MILLISECOND, millis);
return newEvt;
}
public EventTime getRelEvent(int year, int month, int date) {
EventTime newEvt = new EventTime(this);
newEvt.set(Calendar.YEAR, year);
newEvt.set(Calendar.MONTH, month);
newEvt.set(Calendar.DATE, date);
return newEvt;
}
public EventTime getAdded(int field, int value) {
EventTime evt = new EventTime(this);
evt.cal.add(field, value);
return evt;
}
public void add(int field, int value) {
this.cal.add(field, value);
}
public void set(int field, int value) {
this.cal.set(field, value);
}
public static Iterator iterator(EventTime min, EventTime max, int field,
int step) {
return new EventTimeIterator(min, max, field, step);
}
public int get(int field) {
return this.cal.get(field);
}
public long getTimeInMillis() {
return this.cal.getTime().getTime();
}
public void truncAtMinute() {
this.cal.set(Calendar.SECOND, 0);
this.cal.set(Calendar.MILLISECOND, 0);
}
public Date getTime() {
return this.cal.getTime();
}
protected static class EventTimeIterator
implements Iterator {
private final EventTime min;
private final EventTime max;
private EventTime cursor = null;
private final int step;
private final int field;
public EventTimeIterator(final EventTime min, final EventTime max,
final int field, final int step) {
this.cursor = new EventTime(min);
this.min = min;
this.max = max;
this.field = field;
this.step = step;
}
public boolean hasNext() {
if (cursor == null)return false;
return cursor.before(max);
}
public void remove() {
throw new UnsupportedOperationException();
}
public Object next() {
if (cursor == null)return null;
EventTime res = new EventTime(cursor.cal);
cursor.add(field, step);
return res;
}
}
private GregorianCalendar cal = null;
/**
* Metodo per aggiungere giorni solari alla data passata in input (formato yyyy-MM-dd)
* @param inputDate
* @param numGiorni
* @return
* @throws java.lang.Exception
*/
public static java.util.Date aggiungiGiorniSolari(java.util.Date data,
int numGiorni) throws Exception {
try {
//Impostazione del timezone
TimeZone tz = TimeZone.getTimeZone("Europe/Rome");
Calendar calendar = new GregorianCalendar(tz);
//Calendario impostato alla data in input
calendar.setTime(data);
//Giorni aggiunti
calendar.add(calendar.DAY_OF_MONTH, numGiorni);
// System.out.println("DATA : " + calendar.getTime());
return calendar.getTime();
}
catch (Exception ex) {
ex.printStackTrace();
throw ex;
}
}
}

View File

@@ -0,0 +1,285 @@
package it.valueteam.crontab.utility;
import java.util.*;
import java.io.*;
import it.valueteam.securityutility.CryptoUtility;
/**
* Gestione delle properties di crontab
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2017</p>
* <p>Company: </p>
* @version 2.0 2017/08/10 audit Fortify T0 - corretta gestione streams
*/
public class Resources {
private static Properties props = null;
private static String prefix = "";
//private static Random Rdm = new Random();
static java.text.SimpleDateFormat orario=new java.text.SimpleDateFormat("HH:mm");
static java.text.SimpleDateFormat giorno=new java.text.SimpleDateFormat("MMM d, yyyy ");
//private static Logger log;
private static String propertiesPath = null;
static{
init();
}
private Resources() {
//log = new Logger();
}
private static void init(){
Properties appoProps = new Properties();
FileInputStream fInput = null;
try {
propertiesPath= System.getProperty("crontab_path_properties");
System.out.println("Path delle Properties ottenuto: "+propertiesPath);
fInput = new FileInputStream(propertiesPath);
appoProps.load(fInput);
//props = CryptoUtility.getInstance().getCleanProperties(appoProps);
try {
props = CryptoUtility.getInstance().getCleanProperties(appoProps);
} catch (Exception ex1) {
System.out.println("[it.valueteam.crontab.utility.Resources] FAIL lettura properties cifrato ["+ex1.getClass().getName()+"] - " + ex1.getMessage());
ex1.printStackTrace();
if (null != fInput) {
try {
fInput.close();
fInput = null;
}
catch (IOException e) {
fInput = null;
System.out.println("[it.valueteam.crontab.utility.Resources] FAIL in release stream cifrato ["+e.getClass().getName()+"] - " + e.getMessage());
}
}
fInput = new FileInputStream(propertiesPath);
props = new Properties();
props.load(fInput);
}
prefix = props.getProperty("prefix");
}
catch (Exception ex) {
System.out.println("[it.valueteam.crontab.utility.Resources] FAIL lettura properties ["+ex.getClass().getName()+"] - " + ex.getMessage());
}
finally {
if (null != fInput)
try {
fInput.close();
fInput = null;
}
catch (IOException ex1) {
fInput = null;
System.out.println("[it.valueteam.crontab.utility.Resources] FAIL in release stream generico ["+ex1.getClass().getName()+"] - " + ex1.getMessage());
}
}
}
private static String getProperty(String name)
{
String res = props.getProperty(prefix + "." + name);
if(res == null)
res = props.getProperty("*." + name);
return res;
}
private static String get3DesProperty(String name) {
String res = props.getProperty(CryptoUtility.TRIPLE_DES_PREFIX + prefix +"." + name);
if (res == null)
res = props.getProperty("*." + name);
return res;
}
/*
* CARLO 03-02-2003
* aggiunto metodo Trim(String) richiemato da tutti i metodi
* Se null->null altrimenti trimmo
* */
private static final String Trim(String valore){
if (valore!=null)
return valore.trim();
else return null;
}
public static String getPROCESS_EXEC_LOG_CONF_FILE(){
if(props==null)
init();
return getProperty("PROCESS_EXEC_LOG_CONF_FILE");
}
public static Hashtable getAllFestivita()
{
Hashtable festivita = new Hashtable();
if (props == null)
init();
Enumeration keys = props.propertyNames();
while (keys.hasMoreElements())
{
String key = Trim( (String) keys.nextElement());
if (key.startsWith(prefix + ".FESTIVITA"))
festivita.put(key, props.getProperty(key));
}
return festivita;
}
public static boolean isFestivo(EventTime event)
{
boolean isFestivity = false;
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(event.getTime());
int giorno = cal.get(Calendar.DAY_OF_MONTH);
int mese = cal.get(Calendar.MONTH) + 1;
//Controlla che non sia un luned<65> di Pasqua
if (getFestivitaPasquale() == cal.get(Calendar.DAY_OF_YEAR))
isFestivity = true;
Hashtable festivita = Resources.getAllFestivita();
Enumeration keys = festivita.keys();
//Controlla che non sia una festivita
while (keys.hasMoreElements())
{
String dataFestivita = (String) festivita.get( (String) keys.nextElement());
// AA. 11/11/03 Aggiunta verifica sul sabato e domenica festivi
if (dataFestivita.equalsIgnoreCase("SABATO"))
{
if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
isFestivity = true;
}
else
if (dataFestivita.equalsIgnoreCase("DOMENICA"))
{
if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
isFestivity = true;
}
else
{
int giornoFestivita = Integer.parseInt(dataFestivita.substring(0,
dataFestivita.indexOf("/")));
int meseFestivita = Integer.parseInt(dataFestivita.substring(
dataFestivita.indexOf("/") + 1));
if (giorno == giornoFestivita && mese == meseFestivita)
isFestivity = true;
}
}
return isFestivity;
}
private static int getFestivitaPasquale()
{
GregorianCalendar gc = new GregorianCalendar();
int anno = gc.get(Calendar.YEAR);
Integer integer = new Integer(anno);
double A = integer.doubleValue();
double bisest = 0;
if ( (A % 4 == 0) && (A % 100 != 0) || (A % 400 == 0))
bisest = 1;
double n = A % 19;
double c = Math.floor(A / 100);
double u = A % 100;
double s = Math.floor(c / 4);
double t = c % 4;
double p = Math.floor( (c + 8) / 25);
double q = Math.floor( (c - p + 1) / 3);
double e = (19 * n + c - s - q + 15) % 30;
double b = Math.floor(u / 4);
double d = u % 4;
double l = (32 + 2 * t + 2 * b - e - d) % 7;
double h = Math.floor( (n + 11 * e + 22 * l) / 451);
double m = Math.floor( (e + l - 17 * h + 114) / 31);
double j = (e + l - 17 * h + 114) % 31;
j = j + 1;
double xpasqua = 59 + bisest;
if (m == 3)
xpasqua = xpasqua + j;
if (m == 4)
xpasqua = xpasqua + 31 + j;
//double xcarnevale = xpasqua - 49;
//double xmartedigrasso = xpasqua - 47;
//double xceneri = xpasqua - 46;
double xlunedidipasqua = xpasqua + 1;
//double xpalme = xpasqua - 7;
//double xascensione = xpasqua + 39;
//double xpentecoste = xpasqua + 49;
//double xtrinita = xpasqua + 56;
//double xcorpusdomini = xpasqua + 60;
//double hgiorno = 0;
Double dou = new Double(xlunedidipasqua);
return dou.intValue();
}
public static String getFE_WLSERVER_DBCFX_URL(){
if(props==null)
init();
return getProperty("FE.WLSERVER.DBCFX.URL");
}
public static String getFE_WLSERVER_CONTEXT_FACTORY(){
if(props==null)
init();
return getProperty("FE.WLSERVER.CONTEXT.FACTORY");
}
public static String getFE_WLSERVER_USER(){
if(props==null)
init();
return getProperty("FE.WLSERVER.USER");
}
public static String getFE_WLSERVER_USER_PWD(){
if(props==null)
init();
return get3DesProperty("FE.WLSERVER.USER.PWD");
}
public static List<String> getAllBatchToExecuteInFest()
{
List<String> listBatchToExecuteInFest = new ArrayList<String>();
if (props == null)
init();
Enumeration<?> keys = props.propertyNames();
while (keys.hasMoreElements())
{
String key = Trim( (String) keys.nextElement());
if (key.startsWith(prefix + ".BATCH_EXEC_IN_FESTIVITA")) {
listBatchToExecuteInFest.add(props.getProperty(key));
}
}
return listBatchToExecuteInFest;
}
}