4040import org .apache .commons .cli .HelpFormatter ;
4141import org .apache .commons .cli .Options ;
4242import org .apache .commons .cli .ParseException ;
43+ import org .apache .logging .log4j .LogManager ;
44+ import org .apache .logging .log4j .Logger ;
4345import org .bouncycastle .jce .provider .BouncyCastleProvider ;
4446import org .kopi .ebics .exception .EbicsException ;
4547import org .kopi .ebics .exception .NoDownloadDataAvailableException ;
6668 *
6769 */
6870public class EbicsClient {
71+ private static File getRootDir () {
72+ return new File (
73+ System .getProperty ("user.home" ) + File .separator + "ebics" + File .separator + "client" );
74+ }
75+
76+ static {
77+ // this is for the logging config
78+ System .setProperty ("ebicsBasePath" , getRootDir ().getAbsolutePath ());
79+ }
6980
81+ private static final Logger logger = LogManager .getLogger (EbicsClient .class );
7082 private final Configuration configuration ;
7183 private final Map <String , User > users = new HashMap <>();
7284 private final Map <String , Partner > partners = new HashMap <>();
@@ -93,7 +105,7 @@ public EbicsClient(Configuration configuration, ConfigProperties properties) {
93105 this .properties = properties ;
94106 Messages .setLocale (configuration .getLocale ());
95107 this .messages = new Messages (Constants .APPLICATION_BUNDLE_NAME , configuration .getLocale ());
96- configuration . getLogger () .info (messages .getString ("init.configuration" ));
108+ logger .info (messages .getString ("init.configuration" ));
97109 configuration .init ();
98110 }
99111
@@ -110,7 +122,7 @@ private EbicsSession createSession(User user, Product product) {
110122 * the concerned user
111123 */
112124 public void createUserDirectories (EbicsUser user ) {
113- configuration . getLogger () .info (
125+ logger .info (
114126 messages .getString ("user.create.directories" , user .getUserId ()));
115127 IOUtils .createDirectories (configuration .getUserDirectory (user ));
116128 IOUtils .createDirectories (configuration .getTransferTraceDirectory (user ));
@@ -187,7 +199,7 @@ public User createUser(URL url, String bankName, String hostId, String partnerId
187199 String userId , String name , String email , String country , String organization ,
188200 boolean useCertificates , boolean saveCertificates , PasswordCallback passwordCallback )
189201 throws Exception {
190- configuration . getLogger () .info (messages .getString ("user.create.info" , userId ));
202+ logger .info (messages .getString ("user.create.info" , userId ));
191203
192204 Bank bank = createBank (url , bankName , hostId , useCertificates );
193205 Partner partner = createPartner (bank , partnerId );
@@ -206,10 +218,10 @@ public User createUser(URL url, String bankName, String hostId, String partnerId
206218 partners .put (partner .getPartnerId (), partner );
207219 banks .put (bank .getHostId (), bank );
208220
209- configuration . getLogger () .info (messages .getString ("user.create.success" , userId ));
221+ logger .info (messages .getString ("user.create.success" , userId ));
210222 return user ;
211223 } catch (Exception e ) {
212- configuration . getLogger () .error (messages .getString ("user.create.error" ), e );
224+ logger .error (messages .getString ("user.create.error" ), e );
213225 throw e ;
214226 }
215227 }
@@ -236,7 +248,7 @@ private void createLetters(EbicsUser user, boolean useCertificates)
236248 */
237249 public User loadUser (String hostId , String partnerId , String userId ,
238250 PasswordCallback passwordCallback ) throws Exception {
239- configuration . getLogger () .info (messages .getString ("user.load.info" , userId ));
251+ logger .info (messages .getString ("user.load.info" , userId ));
240252
241253 try {
242254 Bank bank ;
@@ -257,10 +269,10 @@ public User loadUser(String hostId, String partnerId, String userId,
257269 users .put (userId , user );
258270 partners .put (partner .getPartnerId (), partner );
259271 banks .put (bank .getHostId (), bank );
260- configuration . getLogger () .info (messages .getString ("user.load.success" , userId ));
272+ logger .info (messages .getString ("user.load.success" , userId ));
261273 return user ;
262274 } catch (Exception e ) {
263- configuration . getLogger () .error (messages .getString ("user.load.error" ), e );
275+ logger .error (messages .getString ("user.load.error" ), e );
264276 throw e ;
265277 }
266278 }
@@ -274,9 +286,9 @@ public User loadUser(String hostId, String partnerId, String userId,
274286 */
275287 public void sendINIRequest (User user , Product product ) throws Exception {
276288 String userId = user .getUserId ();
277- configuration . getLogger () .info (messages .getString ("ini.request.send" , userId ));
289+ logger .info (messages .getString ("ini.request.send" , userId ));
278290 if (user .isInitialized ()) {
279- configuration . getLogger () .info (messages .getString ("user.already.initialized" , userId ));
291+ logger .info (messages .getString ("user.already.initialized" , userId ));
280292 return ;
281293 }
282294 EbicsSession session = createSession (user , product );
@@ -286,9 +298,9 @@ public void sendINIRequest(User user, Product product) throws Exception {
286298 try {
287299 keyManager .sendINI (null );
288300 user .setInitialized (true );
289- configuration . getLogger () .info (messages .getString ("ini.send.success" , userId ));
301+ logger .info (messages .getString ("ini.send.success" , userId ));
290302 } catch (Exception e ) {
291- configuration . getLogger () .error (messages .getString ("ini.send.error" , userId ), e );
303+ logger .error (messages .getString ("ini.send.error" , userId ), e );
292304 throw e ;
293305 }
294306 }
@@ -304,9 +316,9 @@ public void sendINIRequest(User user, Product product) throws Exception {
304316 */
305317 public void sendHIARequest (User user , Product product ) throws Exception {
306318 String userId = user .getUserId ();
307- configuration . getLogger () .info (messages .getString ("hia.request.send" , userId ));
319+ logger .info (messages .getString ("hia.request.send" , userId ));
308320 if (user .isInitializedHIA ()) {
309- configuration . getLogger ()
321+ logger
310322 .info (messages .getString ("user.already.hia.initialized" , userId ));
311323 return ;
312324 }
@@ -318,18 +330,18 @@ public void sendHIARequest(User user, Product product) throws Exception {
318330 keyManager .sendHIA (null );
319331 user .setInitializedHIA (true );
320332 } catch (Exception e ) {
321- configuration . getLogger () .error (messages .getString ("hia.send.error" , userId ), e );
333+ logger .error (messages .getString ("hia.send.error" , userId ), e );
322334 throw e ;
323335 }
324- configuration . getLogger () .info (messages .getString ("hia.send.success" , userId ));
336+ logger .info (messages .getString ("hia.send.success" , userId ));
325337 }
326338
327339 /**
328340 * Sends a HPB request to the ebics server.
329341 */
330342 public void sendHPBRequest (User user , Product product ) throws Exception {
331343 String userId = user .getUserId ();
332- configuration . getLogger () .info (messages .getString ("hpb.request.send" , userId ));
344+ logger .info (messages .getString ("hpb.request.send" , userId ));
333345
334346 EbicsSession session = createSession (user , product );
335347 KeyManagement keyManager = new KeyManagement (session );
@@ -339,9 +351,9 @@ public void sendHPBRequest(User user, Product product) throws Exception {
339351
340352 try {
341353 keyManager .sendHPB ();
342- configuration . getLogger () .info (messages .getString ("hpb.send.success" , userId ));
354+ logger .info (messages .getString ("hpb.send.success" , userId ));
343355 } catch (Exception e ) {
344- configuration . getLogger () .error (messages .getString ("hpb.send.error" , userId ), e );
356+ logger .error (messages .getString ("hpb.send.error" , userId ), e );
345357 throw e ;
346358 }
347359 }
@@ -358,7 +370,7 @@ public void sendHPBRequest(User user, Product product) throws Exception {
358370 public void revokeSubscriber (User user , Product product ) throws Exception {
359371 String userId = user .getUserId ();
360372
361- configuration . getLogger () .info (messages .getString ("spr.request.send" , userId ));
373+ logger .info (messages .getString ("spr.request.send" , userId ));
362374
363375 EbicsSession session = createSession (user , product );
364376 KeyManagement keyManager = new KeyManagement (session );
@@ -369,11 +381,11 @@ public void revokeSubscriber(User user, Product product) throws Exception {
369381 try {
370382 keyManager .lockAccess ();
371383 } catch (Exception e ) {
372- configuration . getLogger () .error (messages .getString ("spr.send.error" , userId ), e );
384+ logger .error (messages .getString ("spr.send.error" , userId ), e );
373385 throw e ;
374386 }
375387
376- configuration . getLogger () .info (messages .getString ("spr.send.success" , userId ));
388+ logger .info (messages .getString ("spr.send.success" , userId ));
377389 }
378390
379391 /**
@@ -392,7 +404,7 @@ public void sendFile(File file, User user, Product product, EbicsOrderType order
392404 try {
393405 transferManager .sendFile (IOUtils .getFileContent (file ), orderType , orderAttribute );
394406 } catch (IOException | EbicsException e ) {
395- configuration . getLogger ()
407+ logger
396408 .error (messages .getString ("upload.file.error" , file .getAbsolutePath ()), e );
397409 throw e ;
398410 }
@@ -421,7 +433,7 @@ public void fetchFile(File file, User user, Product product, EbicsOrderType orde
421433 // don't log this exception as an error, caller can decide how to handle
422434 throw e ;
423435 } catch (Exception e ) {
424- configuration . getLogger () .error (messages .getString ("download.file.error" ), e );
436+ logger .error (messages .getString ("download.file.error" ), e );
425437 throw e ;
426438 }
427439 }
@@ -438,36 +450,36 @@ public void quit() {
438450 try {
439451 for (User user : users .values ()) {
440452 if (user .needsSave ()) {
441- configuration . getLogger ()
453+ logger
442454 .info (messages .getString ("app.quit.users" , user .getUserId ()));
443455 configuration .getSerializationManager ().serialize (user );
444456 }
445457 }
446458
447459 for (Partner partner : partners .values ()) {
448460 if (partner .needsSave ()) {
449- configuration . getLogger ()
461+ logger
450462 .info (messages .getString ("app.quit.partners" , partner .getPartnerId ()));
451463 configuration .getSerializationManager ().serialize (partner );
452464 }
453465 }
454466
455467 for (Bank bank : banks .values ()) {
456468 if (bank .needsSave ()) {
457- configuration . getLogger ()
469+ logger
458470 .info (messages .getString ("app.quit.banks" , bank .getHostId ()));
459471 configuration .getSerializationManager ().serialize (bank );
460472 }
461473 }
462474 } catch (EbicsException e ) {
463- configuration . getLogger () .info (messages .getString ("app.quit.error" ));
475+ logger .info (messages .getString ("app.quit.error" ));
464476 }
465477
466478 clearTraces ();
467479 }
468480
469481 public void clearTraces () {
470- configuration . getLogger () .info (messages .getString ("app.cache.clear" ));
482+ logger .info (messages .getString ("app.cache.clear" ));
471483 configuration .getTraceManager ().clear ();
472484 }
473485
@@ -614,8 +626,7 @@ public static void main(String[] args) throws Exception {
614626
615627 CommandLine cmd = parseArguments (options , args );
616628
617- File defaultRootDir = new File (System .getProperty ("user.home" ) + File .separator + "ebics"
618- + File .separator + "client" );
629+ File defaultRootDir = getRootDir ();
619630 File ebicsClientProperties = new File (defaultRootDir , "ebics.txt" );
620631 EbicsClient client = createEbicsClient (defaultRootDir , ebicsClientProperties );
621632
0 commit comments