Skip to content

Commit e560b39

Browse files
Multi module configuration added for
GenericListCatalogConfig (and extending types like MiniFilter).
1 parent 287d3ca commit e560b39

File tree

6 files changed

+134
-13
lines changed

6 files changed

+134
-13
lines changed

fj-core/src/main/java/org/fugerit/java/core/cfg/xml/GenericListCatalogConfig.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ are accessed through the method getGeneralProps()
3535
-->
3636
<data-catalog-config key1="value1" key2="value">
3737
38+
<!--
39+
Some additional configurations could be loaded through configuration files.
40+
All modules will be loaded before the main configuration file.
41+
-->
42+
<module-list>
43+
<module id="module-01" mode="cl" src="class/load/path/to/module"/>
44+
</module-list>
3845
3946
<!--
4047
data list ids are accessed
@@ -120,6 +127,38 @@ public GenericListCatalogConfig( String attTagDataList, String attTagData ) {
120127

121128
public static final String ATT_TAG_TYPE_STRING = "java.lang.String";
122129

130+
public static final String ATT_TAG_MODULE_LIST = "module-list";
131+
132+
public static final String ATT_TAG_MODULE = "module";
133+
134+
/**
135+
* Configuration attribute for module 'id'
136+
*/
137+
public static final String ATT_TAG_MODULE_CONF_ID = "id";
138+
139+
/**
140+
* Configuration attribute for module load 'mode'
141+
*/
142+
public static final String ATT_TAG_MODULE_CONF_MODE = "mode";
143+
144+
145+
/**
146+
* Value for module load mode by class loader
147+
*/
148+
public static final String ATT_TAG_MODULE_CONF_MODE_CL = "cl";
149+
150+
151+
/**
152+
* Configuration attribute for module src path
153+
*/
154+
public static final String ATT_TAG_MODULE_CONF_PATH = "path";
155+
156+
/**
157+
* Configuration attribute for module unsafe module
158+
* (if unsafe='true' load exception would be ignored and main configuration will proceed )
159+
*/
160+
public static final String ATT_TAG_MODULE_CONF_UNSAFE = "unsafe";
161+
123162
protected String attTagDataList;
124163
protected String attTagData;
125164

@@ -225,6 +264,37 @@ public void configure(Element tag) throws ConfigException {
225264
this.dataMap.put( idList , listCurrent );
226265
this.orderedId.add( idList );
227266
}
267+
268+
NodeList moduleListTag = tag.getElementsByTagName( ATT_TAG_MODULE_LIST );
269+
for ( int l=0; l<moduleListTag.getLength(); l++ ) {
270+
Element currentModuleList = (Element)moduleListTag.item( l );
271+
NodeList moduleTag = currentModuleList.getElementsByTagName( ATT_TAG_MODULE );
272+
for ( int m=0; m<moduleTag.getLength(); m++ ) {
273+
Element currentModule = (Element)moduleTag.item( m );
274+
String id = currentModule.getAttribute( ATT_TAG_MODULE_CONF_ID );
275+
String mode = currentModule.getAttribute( ATT_TAG_MODULE_CONF_MODE );
276+
String path = currentModule.getAttribute( ATT_TAG_MODULE_CONF_PATH );
277+
String unsafe = currentModule.getAttribute( ATT_TAG_MODULE_CONF_UNSAFE );
278+
if ( ATT_TAG_MODULE_CONF_MODE_CL.equalsIgnoreCase( mode ) ) {
279+
logger.info( "Loading module id="+id+" mode="+mode+" path="+path );
280+
try {
281+
InputStream is = ClassHelper.loadFromDefaultClassLoader( path );
282+
Document currentModuleDoc = DOMIO.loadDOMDoc( is );
283+
Element rootTag = currentModuleDoc.getDocumentElement();
284+
this.configure( rootTag );
285+
} catch (Exception e) {
286+
if ( "true".equalsIgnoreCase( unsafe ) ) {
287+
logger.warn( "Module "+id+" load failed, exception suppressed as it's marked 'unsafe'", e );
288+
} else {
289+
throw new ConfigException( "Error loadind module : "+id );
290+
}
291+
}
292+
} else {
293+
throw new ConfigException( "Usupported module load mode : "+mode );
294+
}
295+
}
296+
}
297+
228298
}
229299

230300
/**

fj-core/src/test/java/test/org/fugerit/java/core/util/filterchain/TestMiniFilter.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22

33
import static org.junit.Assert.fail;
44

5+
import java.util.Iterator;
6+
57
import org.fugerit.java.core.lang.helpers.ClassHelper;
68
import org.fugerit.java.core.util.filterchain.MiniFilterChain;
79
import org.fugerit.java.core.util.filterchain.MiniFilterConfig;
810
import org.fugerit.java.core.util.filterchain.MiniFilterContext;
911
import org.fugerit.java.core.util.filterchain.MiniFilterData;
1012
import org.junit.Test;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
1115

1216
public class TestMiniFilter {
1317

18+
private final static Logger logger = LoggerFactory.getLogger( TestMiniFilter.class );
19+
1420
private static final String CONF_PATH = "core/util/filterchain/minifilter-test-config.xml";
1521

1622
public static MiniFilterConfig init() {
@@ -33,22 +39,22 @@ public void testWorker( String chainId, boolean okOnException ) {
3339
boolean success = false;
3440
String message = "OK";
3541
try {
36-
System.out.println( "TEST START >>> "+chainId );
42+
logger.info( "TEST START >>> "+chainId );
3743
MiniFilterChain chain = CONFIG.getChainCache( chainId );
3844
MiniFilterContext context = new MiniFilterContext();
3945
MiniFilterData data = new MiniFilterData() {};
4046
int res = chain.apply( context , data );
41-
System.out.println( "TEST END >>> "+chainId+" >> res:"+res );
47+
logger.info( "TEST END >>> "+chainId+" >> res:"+res );
4248
success = !okOnException;
4349
} catch (Exception e) {
44-
System.out.println( e.toString() );
50+
logger.info( e.toString() );
4551
message = e.getMessage();
4652
success = okOnException;
4753
}
4854
if ( !success ) {
4955
fail( "Error : "+message );
5056
} else {
51-
System.out.println( "Test was success "+chainId );
57+
logger.info( "Test was success "+chainId );
5258
}
5359
}
5460

@@ -81,5 +87,27 @@ public void testChainBaseLoadSafe00() {
8187
public void testChainBaseLoadSafe01() {
8288
this.testWorker( "chain-base-loadsafe-01" );
8389
}
84-
90+
91+
@Test
92+
public void testChainModule01() {
93+
this.testWorker( "chain-module01-test-01" );
94+
}
95+
96+
@Test
97+
public void testChainModule02() {
98+
this.testWorker( "chain-module02-test-01" );
99+
}
100+
101+
@Test
102+
public void testPrintConfig() {
103+
logger.info( "**********************************************" );
104+
logger.info( "**********************************************" );
105+
Iterator<String> it = CONFIG.getIdSet().iterator();
106+
while ( it.hasNext() ) {
107+
logger.info( "id '"+it.next()+"'" );
108+
}
109+
logger.info( "**********************************************" );
110+
logger.info( "**********************************************" );
111+
}
112+
85113
}

fj-core/src/test/resources/core/util/filterchain/minifilter-test-config.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
<!-- sample configuration file for filter chain -->
44

5+
<module-list>
6+
<module id="module-01" mode="cl" path="core/util/filterchain/minifilter-test-module01.xml"/>
7+
<module id="module-02" mode="cl" path="core/util/filterchain/minifilter-test-module02.xml"/>
8+
<module id="module-03" mode="cl" path="core/util/filterchain/minifilter-test-module03.xml" unsafe="true"/>
9+
</module-list>
10+
511
<data-list id="chain-base-continue">
612
<data id="step-01" defaultBehaviour="CONTINUE"
713
description="Step 01 Continue (this one will be printed)"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<data-catalog-config type="org.fugerit.java.core.util.filterchain.MiniFilterConfigEntry">
2+
3+
<data-list id="chain-module01-test-01">
4+
<data id="step-01-module-01" defaultBehaviour="CONTINUE"
5+
description="Step 01 Continue (this one will be printed)"
6+
type="test.org.fugerit.java.core.util.filterchain.ContinueStep"/>
7+
<data id="step-02-module-01" defaultBehaviour="CONTINUE"
8+
description="Step 02 Skip (this one will be printed)"
9+
type="test.org.fugerit.java.core.util.filterchain.SkipStep"/>
10+
</data-list>
11+
12+
</data-catalog-config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<data-catalog-config type="org.fugerit.java.core.util.filterchain.MiniFilterConfigEntry">
2+
3+
<data-list id="chain-module02-test-01">
4+
<data id="step-01-module-02" defaultBehaviour="CONTINUE"
5+
description="Step 01 Continue (this one will be printed)"
6+
type="test.org.fugerit.java.core.util.filterchain.ContinueStep"/>
7+
<data id="step-02-module-02" defaultBehaviour="CONTINUE"
8+
description="Step 02 Skip (this one will be printed)"
9+
type="test.org.fugerit.java.core.util.filterchain.SkipStep"/>
10+
</data-list>
11+
12+
</data-catalog-config>
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
log4j.rootLogger=INFO,CONSOLE
2-
3-
4-
#log4j.logger.it.sogei.tracciamento.filtro.TracerFilter=DEBUG
5-
62
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
7-
#log4j.appender.CONSOLE.threshold=DEBUG
83
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
9-
#log4j.appender.CONSOLE.layout.ConversionPattern=[%c] [%d] - %m%n
10-
#log4j.appender.CONSOLE.layout.ConversionPattern=[%d] [server:%X{serverName}] [applicazione:%X{applicationName}] %m%n
11-
log4j.appender.CONSOLE.layout.ConversionPattern=[%d] - classe:%X{callerClass} - metodo:%X{callerMethod} - %m%n
4+
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd}-%t-%x-%-5p-%-10c:%m%n

0 commit comments

Comments
 (0)