3737import org .apache .commons .cli .CommandLine ;
3838import org .apache .commons .cli .CommandLineParser ;
3939import org .apache .commons .cli .DefaultParser ;
40- import org . apache . commons . cli . HelpFormatter ;
40+
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 ;
43+ import org .apache .commons .cli .help .HelpFormatter ;
4544import org .bouncycastle .jce .provider .BouncyCastleProvider ;
4645import org .kopi .ebics .exception .EbicsException ;
4746import org .kopi .ebics .exception .NoDownloadDataAvailableException ;
6059import org .kopi .ebics .session .OrderType ;
6160import org .kopi .ebics .session .Product ;
6261import org .kopi .ebics .utils .Constants ;
62+ import org .slf4j .Logger ;
63+ import org .slf4j .LoggerFactory ;
6364
6465/**
6566 * The ebics client application. Performs necessary tasks to contact the ebics
@@ -76,8 +77,8 @@ private static File getRootDir() {
7677 // this is for the logging config
7778 System .setProperty ("ebicsBasePath" , getRootDir ().getAbsolutePath ());
7879 }
80+ private static final Logger log = LoggerFactory .getLogger (EbicsClient .class );
7981
80- private static final Logger logger = LogManager .getLogger (EbicsClient .class );
8182 private final Configuration configuration ;
8283 private final Map <String , User > users = new HashMap <>();
8384 private final Map <String , Partner > partners = new HashMap <>();
@@ -104,7 +105,7 @@ public EbicsClient(Configuration configuration, ConfigProperties properties) {
104105 this .properties = properties ;
105106 Messages .setLocale (configuration .getLocale ());
106107 this .messages = new Messages (Constants .APPLICATION_BUNDLE_NAME , configuration .getLocale ());
107- logger .info (messages .getString ("init.configuration" ));
108+ log .info (messages .getString ("init.configuration" ));
108109 configuration .init ();
109110 }
110111
@@ -121,7 +122,7 @@ private EbicsSession createSession(User user, Product product) {
121122 * the concerned user
122123 */
123124 public void createUserDirectories (EbicsUser user ) {
124- logger .info (
125+ log .info (
125126 messages .getString ("user.create.directories" , user .getUserId ()));
126127 IOUtils .createDirectories (configuration .getUserDirectory (user ));
127128 IOUtils .createDirectories (configuration .getTransferTraceDirectory (user ));
@@ -198,7 +199,7 @@ public User createUser(URL url, String bankName, String hostId, String partnerId
198199 String userId , String name , String email , String country , String organization ,
199200 boolean useCertificates , boolean saveCertificates , PasswordCallback passwordCallback )
200201 throws Exception {
201- logger .info (messages .getString ("user.create.info" , userId ));
202+ log .info (messages .getString ("user.create.info" , userId ));
202203
203204 Bank bank = createBank (url , bankName , hostId , useCertificates );
204205 Partner partner = createPartner (bank , partnerId );
@@ -217,10 +218,10 @@ public User createUser(URL url, String bankName, String hostId, String partnerId
217218 partners .put (partner .getPartnerId (), partner );
218219 banks .put (bank .getHostId (), bank );
219220
220- logger .info (messages .getString ("user.create.success" , userId ));
221+ log .info (messages .getString ("user.create.success" , userId ));
221222 return user ;
222223 } catch (Exception e ) {
223- logger .error (messages .getString ("user.create.error" ), e );
224+ log .error (messages .getString ("user.create.error" ), e );
224225 throw e ;
225226 }
226227 }
@@ -245,7 +246,7 @@ private void createLetters(EbicsUser user, boolean useCertificates)
245246 */
246247 public User loadUser (String hostId , String partnerId , String userId ,
247248 PasswordCallback passwordCallback ) throws Exception {
248- logger .info (messages .getString ("user.load.info" , userId ));
249+ log .info (messages .getString ("user.load.info" , userId ));
249250
250251 try {
251252 Bank bank ;
@@ -266,10 +267,10 @@ public User loadUser(String hostId, String partnerId, String userId,
266267 users .put (userId , user );
267268 partners .put (partner .getPartnerId (), partner );
268269 banks .put (bank .getHostId (), bank );
269- logger .info (messages .getString ("user.load.success" , userId ));
270+ log .info (messages .getString ("user.load.success" , userId ));
270271 return user ;
271272 } catch (Exception e ) {
272- logger .error (messages .getString ("user.load.error" ), e );
273+ log .error (messages .getString ("user.load.error" ), e );
273274 throw e ;
274275 }
275276 }
@@ -282,9 +283,9 @@ public User loadUser(String hostId, String partnerId, String userId,
282283 */
283284 public void sendINIRequest (User user , Product product ) throws Exception {
284285 String userId = user .getUserId ();
285- logger .info (messages .getString ("ini.request.send" , userId ));
286+ log .info (messages .getString ("ini.request.send" , userId ));
286287// if (user.isInitialized()) {
287- // logger .info(messages.getString("user.already.initialized", userId));
288+ // log .info(messages.getString("user.already.initialized", userId));
288289// return;
289290// }
290291 EbicsSession session = createSession (user , product );
@@ -294,9 +295,9 @@ public void sendINIRequest(User user, Product product) throws Exception {
294295 try {
295296 keyManager .sendINI (null );
296297 user .setInitialized (true );
297- logger .info (messages .getString ("ini.send.success" , userId ));
298+ log .info (messages .getString ("ini.send.success" , userId ));
298299 } catch (Exception e ) {
299- logger .error (messages .getString ("ini.send.error" , userId ), e );
300+ log .error (messages .getString ("ini.send.error" , userId ), e );
300301 throw e ;
301302 }
302303 }
@@ -311,7 +312,7 @@ public void sendINIRequest(User user, Product product) throws Exception {
311312 */
312313 public void sendHIARequest (User user , Product product ) throws Exception {
313314 String userId = user .getUserId ();
314- logger .info (messages .getString ("hia.request.send" , userId ));
315+ log .info (messages .getString ("hia.request.send" , userId ));
315316// if (user.isInitializedHIA()) {
316317// logger
317318// .info(messages.getString("user.already.hia.initialized", userId));
@@ -325,18 +326,18 @@ public void sendHIARequest(User user, Product product) throws Exception {
325326 keyManager .sendHIA (null );
326327 user .setInitializedHIA (true );
327328 } catch (Exception e ) {
328- logger .error (messages .getString ("hia.send.error" , userId ), e );
329+ log .error (messages .getString ("hia.send.error" , userId ), e );
329330 throw e ;
330331 }
331- logger .info (messages .getString ("hia.send.success" , userId ));
332+ log .info (messages .getString ("hia.send.success" , userId ));
332333 }
333334
334335 /**
335336 * Sends a HPB request to the ebics server.
336337 */
337338 public void sendHPBRequest (User user , Product product ) throws Exception {
338339 String userId = user .getUserId ();
339- logger .info (messages .getString ("hpb.request.send" , userId ));
340+ log .info (messages .getString ("hpb.request.send" , userId ));
340341
341342 EbicsSession session = createSession (user , product );
342343 KeyManagement keyManager = new KeyManagement (session );
@@ -346,9 +347,9 @@ public void sendHPBRequest(User user, Product product) throws Exception {
346347
347348 try {
348349 keyManager .sendHPB ();
349- logger .info (messages .getString ("hpb.send.success" , userId ));
350+ log .info (messages .getString ("hpb.send.success" , userId ));
350351 } catch (Exception e ) {
351- logger .error (messages .getString ("hpb.send.error" , userId ), e );
352+ log .error (messages .getString ("hpb.send.error" , userId ), e );
352353 throw e ;
353354 }
354355 }
@@ -365,7 +366,7 @@ public void sendHPBRequest(User user, Product product) throws Exception {
365366 public void revokeSubscriber (User user , Product product ) throws Exception {
366367 String userId = user .getUserId ();
367368
368- logger .info (messages .getString ("spr.request.send" , userId ));
369+ log .info (messages .getString ("spr.request.send" , userId ));
369370
370371 EbicsSession session = createSession (user , product );
371372 KeyManagement keyManager = new KeyManagement (session );
@@ -376,11 +377,11 @@ public void revokeSubscriber(User user, Product product) throws Exception {
376377 try {
377378 keyManager .lockAccess ();
378379 } catch (Exception e ) {
379- logger .error (messages .getString ("spr.send.error" , userId ), e );
380+ log .error (messages .getString ("spr.send.error" , userId ), e );
380381 throw e ;
381382 }
382383
383- logger .info (messages .getString ("spr.send.success" , userId ));
384+ log .info (messages .getString ("spr.send.success" , userId ));
384385 }
385386
386387 /**
@@ -399,7 +400,7 @@ public void sendFile(File file, User user, Product product, EbicsOrderType order
399400 try {
400401 transferManager .sendFile (IOUtils .getFileContent (file ), orderType , orderAttribute );
401402 } catch (IOException | EbicsException e ) {
402- logger
403+ log
403404 .error (messages .getString ("upload.file.error" , file .getAbsolutePath ()), e );
404405 throw e ;
405406 }
@@ -428,7 +429,7 @@ public void fetchFile(File file, User user, Product product, EbicsOrderType orde
428429 // don't log this exception as an error, caller can decide how to handle
429430 throw e ;
430431 } catch (Exception e ) {
431- logger .error ("{} {}" , messages .getString ("download.file.error" ), e .getMessage (), e );
432+ log .error ("{} {}" , messages .getString ("download.file.error" ), e .getMessage (), e );
432433 throw e ;
433434 }
434435 }
@@ -445,36 +446,36 @@ public void quit() {
445446 try {
446447 for (User user : users .values ()) {
447448 if (user .needsSave ()) {
448- logger
449+ log
449450 .info (messages .getString ("app.quit.users" , user .getUserId ()));
450451 configuration .getSerializationManager ().serialize (user );
451452 }
452453 }
453454
454455 for (Partner partner : partners .values ()) {
455456 if (partner .needsSave ()) {
456- logger
457+ log
457458 .info (messages .getString ("app.quit.partners" , partner .getPartnerId ()));
458459 configuration .getSerializationManager ().serialize (partner );
459460 }
460461 }
461462
462463 for (Bank bank : banks .values ()) {
463464 if (bank .needsSave ()) {
464- logger
465+ log
465466 .info (messages .getString ("app.quit.banks" , bank .getHostId ()));
466467 configuration .getSerializationManager ().serialize (bank );
467468 }
468469 }
469470 } catch (EbicsException e ) {
470- logger .info (messages .getString ("app.quit.error" ));
471+ log .info (messages .getString ("app.quit.error" ));
471472 }
472473
473474 clearTraces ();
474475 }
475476
476477 public void clearTraces () {
477- logger .info (messages .getString ("app.cache.clear" ));
478+ log .info (messages .getString ("app.cache.clear" ));
478479 configuration .getTraceManager ().clear ();
479480 }
480481
@@ -511,14 +512,15 @@ private User createUser(ConfigProperties properties, PasswordCallback pwdHandler
511512 userCountry , userOrg , useCertificates , saveCertificates , pwdHandler );
512513 }
513514
514- private static CommandLine parseArguments (Options options , String [] args ) throws ParseException {
515+ private static CommandLine parseArguments (Options options , String [] args )
516+ throws ParseException , IOException {
515517 CommandLineParser parser = new DefaultParser ();
516518 options .addOption (null , "help" , false , "Print this help text" );
517519 CommandLine line = parser .parse (options , args );
518520 if (line .hasOption ("help" )) {
519- HelpFormatter formatter = new HelpFormatter ();
521+ HelpFormatter formatter = HelpFormatter . builder (). get ();
520522 System .out .println ();
521- formatter .printHelp (EbicsClient .class .getSimpleName (), options );
523+ formatter .printHelp (EbicsClient .class .getSimpleName (), "" , options , "" , true );
522524 System .out .println ();
523525 System .exit (0 );
524526 }
0 commit comments