Totalul afișărilor de pagină

duminică, 22 februarie 2015

Easy to use encryption library for java

If you are looking for an easy to user encryption library, the lightest that I found was jcrypt :
<dependency>
    <groupId>org.mindrot</groupId>
    <artifactId>jbcrypt</artifactId>
    <version>0.3m</version>
</dependency>

BCrypt.hashpw(password, BCrypt.gensalt(10));
BCrypt.checkpw(pwd1, pwd2);

I need to  specify that I do not need a very secure one because I am not handling sensitive data.


duminică, 15 februarie 2015

Slf4j compatibility issues with Dropwizard and Hibernate annotations

While writing a project using dropwizard(0.7.1) and hibernate annotations(3.5.5-Final) I ran into a problem with the versions of slf4j which is a dependency of both but with different versions. dropwizard uses v1.7.6 and hibernate uses 1.5.8.

The solution was to add in the pom file the following dependency:
<dependency>
      <groupId>io.dropwizard</groupId>
      <artifactId>dropwizard-core</artifactId>
      <version>0.7.1</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <artifactId>slf4j-api</artifactId>
          <groupId>org.slf4j</groupId>
        </exclusion>
      </exclusions>
    </dependency>

sâmbătă, 22 noiembrie 2014

Dropwizard intro

Dropwizard is a lightweight, production-ready Java framework. I've used it at my previous jobs to create micro web services. The learning curve is really, really lean.

I will try to create some use cases with code examples,like authentication, bundles, health checks, metrics and also add code for examples..

I think their webpage is enough for everyone that wants to use Dropwizard to understand what is a resource, a configuration class, a health check or a bundle so I will not explain that here.

Be careful at the indentation of your conf.yml file, it can get you in trouble.

For starters you can take the code from here and play with the examples:
Dropwizard git repository

Log4j 2

Log4j project was stopped, and Logback took its place. But now there is also log4j2!!!! This is a short presentation of log4j2.

Logger components :

Logger
  • Gathers the events associated to it
  • Verifies that these events are suitable to be logged( right logging level, filters)
  • Passes them to the appropriate appender to be formatted (layout) and written to the appropriate target.





Filter

  • Allows log events to be evaluated according to some conditions.
  • For log4j2 it can be set at four levels :
    • Context wide
    • Logger
    • Appender
    • Appender reference(determine if a log event should be routed to another)


Log events
  • Contains information that will be used for logging such as :
    • Message
    • Level
    • Timestamp
    • Name of logger
    • Location
    • Thread name



Layout

  • Objects used for formatting log events
  • Returns an array of bytes-> most layouts should have the Charset property set





Appender

  • Has the responsibility of delivering log events to the appropriate target.
  • These objects can wrap other appenders to route the log events to them.



Log4j2 new stuff:
  • Requires at least java 6
  • Filters at every level
  • Removing the need for verifying if the logging level is enabled or disabled
  • Message is saved as array of bytes, not as String
  • Async Appenders and Loggers
    • Requires disruptor.jar(lock free inter-thread communication library) and log4jContextSelector set (Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector)
    • Can be used both async loggers and sync loggers in the same configuration 
    • Benefits : lower latency, higher throughput(6-68 times more messages than the sync logger), flush the disk at the end of a batch.
  • Drawbacks : exceptions occurring during the logging process are lost
  • Plugins : 
    • annotations are used to define new filters, appenders, loggers, layouts


  • Json and xml configuration files, reconfiguration using jconsole and GUI client
    • To configure log4j using json files, the following jars are needed :
      • jackson-core-2.2.1.jar
      • jackson-databind-2.2.1.jar
  • Log4j2 vs Log4j1 vs Logback performance