Exception and logging generator

Maven plugin and project commons to generate internationalized exceptions and logging informations

License

License

Categories

Categories

Logging Application Layer Libs
GroupId

GroupId

de.andreasgerhard
ArtifactId

ArtifactId

exception-logging-generator
Last Version

Last Version

0.1
Release Date

Release Date

Type

Type

pom
Description

Description

Exception and logging generator
Maven plugin and project commons to generate internationalized exceptions and logging informations
Project URL

Project URL

https://github.com/angerhard/exception-logging-generator
Source Code Management

Source Code Management

https://github.com/angerhard/exception-logging-generator

Download exception-logging-generator

How to add to project

<!-- https://jarcasting.com/artifacts/de.andreasgerhard/exception-logging-generator/ -->
<dependency>
    <groupId>de.andreasgerhard</groupId>
    <artifactId>exception-logging-generator</artifactId>
    <version>0.1</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/de.andreasgerhard/exception-logging-generator/
implementation 'de.andreasgerhard:exception-logging-generator:0.1'
// https://jarcasting.com/artifacts/de.andreasgerhard/exception-logging-generator/
implementation ("de.andreasgerhard:exception-logging-generator:0.1")
'de.andreasgerhard:exception-logging-generator:pom:0.1'
<dependency org="de.andreasgerhard" name="exception-logging-generator" rev="0.1">
  <artifact name="exception-logging-generator" type="pom" />
</dependency>
@Grapes(
@Grab(group='de.andreasgerhard', module='exception-logging-generator', version='0.1')
)
libraryDependencies += "de.andreasgerhard" % "exception-logging-generator" % "0.1"
[de.andreasgerhard/exception-logging-generator "0.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • exception-logging-generator-mavenplugin

exception-logging-generator

Java code generator for exceptions and logging

Which problem has to be solved?

Plan your class design considering security, error handling, logging and i18n frondend messages. You have to write a xml file containing class name and messages (frontend, backend). This tool generates the exception code.

A small scripple as big picture
Design security and transparency

Anyone who logs in to your system uses a wrong password, an expired account or without any roles to use your application should be informed. To prevent an security hole, you will report in every case "Member name or password wrong" (or "HALT! Zugang verboten!" in german), for the backend you want to report any information about the incident. These informations are separated in this framework.

Microservice relevant

The exception will generate a json payload containing all messages in every language you have defined. This payload can be used by the frontend to retrieve the correct message.

Examples
<?xml version="1.0" encoding="UTF-8" ?>
<messages
        masterException="com.andreasgerhard.exception.BusinessException"
        masterExceptionInherit="java.lang.RuntimeException"
        default="en">
    <message name="Customer" domain="CUSTOMER.001">
        <exception package="com.andreasgerhard.exception"
                   inherit="com.andreasgerhard.exception.BusinessRuntimeException" returnCode="500"/>
        <frontendMessages>
            <frontendMessage locale="de">Es ist ein Fehler bei der Kundenbearbeitung aufgetreten.</frontendMessage>
            <frontendMessage locale="en">An error has been occured during a customer operation.</frontendMessage>
        </frontendMessages>
        <backendMessage>General failure, please check cause.</backendMessage>
    </message>
    <message name="CustomerNotFound" domain="CUSTOMER.002">
        <exception package="com.andreasgerhard.exception"
                   inherit="CustomerException"
                   returnCode="404"/>
        <frontendMessages>
            <frontendMessage locale="de">Der Kunde mit der ID {id:Integer} wurde nicht gefunden.</frontendMessage>
            <frontendMessage locale="en">A customer with id {id:Integer} could not be found.</frontendMessage>
        </frontendMessages>
        <backendMessage>Customer not found with ID {id:Integer}.</backendMessage>
    </message>
    <message name="CustomerCreated" domain="CUSTOMER.003">
        <frontendMessages>
            <frontendMessage locale="de">Ein neuer Kunde mit der ID {id:Integer} wurde angelegt.</frontendMessage>
            <frontendMessage locale="en">Created a new customer with id {id:Integer}.</frontendMessage>
        </frontendMessages>
        <backendMessage>A new customer has been created with id {id:Integer} and name {name:String}.</backendMessage>
    </message>
    <message name="CustomerLoggedIn" domain="CUSTOMER.004">
        <exception package="com.andreasgerhard.exception"
                   inherit="CustomerException"
                   returnCode="404"/>
        <frontendMessages>
            <frontendMessage locale="de">Der Kunde mit der ID {id:Integer} konnte sich nicht einloggen. Fehlermeldung System: {message:String}; Code {code:Long}.</frontendMessage>
            <frontendMessage locale="en">A customer with id {id:Integer} could not logged in. Error message {message:String}; Code {code:Long}.</frontendMessage>
        </frontendMessages>
        <backendMessage>Customer not found with ID {id:Integer}.</backendMessage>
    </message>
</messages>

will lead to alt text

Versions

Version
0.1