Generate root CA private key: openssl genrsa -des3 -out rootCA.key 2048 Create root CA certificate: openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1825 -out rootCA.pem Generate private key: openssl genrsa -des3 -out my-private.key 2048 Create certificate CSR from private key: openssl req -new -sha256 -key my-private.key -out my-signature-request.csr Sign certificate by root CA: openssl x509 -req -in my-signature-request.csr…
Asynchronous execution with ExecutorService. Runnable, Callable, Future, CountDownLatch.
ExecutorService Build in API, which running of asynchronous tasks makes simple. Create it with factory method from Executors class: Assign a task in one of 3 ways: submit(task) – provide Runnable or Callable task as an argument. Returns Future invokeAny(taskList) – provide collection of Callable tasks. Tries to execute all tasks, returns response from one of successfully executed. invokeAll(taskList) –…
Java functional interface. Lambda, Consumer, Supplier, Predicate.
Functional interface – an interface with single abstract method. Optionally marked with @FunctionalInterface annotation. Lambda – functional interface with a method, which receives and returns value Supplier – function, which does not receive value, but returns one. Mostly used for lazy value generation. Consumer – function, which receive value, but does not return. Mostly used for side…
Some useful Docker stuff
Some common commands necessary to build and run own docker image in a container: Command Description Example docker pull [image_name] Pulls image from default docker registry: //hub.docker.com/ docker pull ubuntu docker ps [options] List running containers. Add -a for all available container. docker ps -a docker container create [options] [image_name] [comand] Creates container with pulled image. Add –name to provide…
Sample of H2 in-memory database, Hibernate and JNDI in Jetty
In this post I’m about to figure out how to use the following things in Java project: How to leverage in-memory H2 database? Particularly configuring it in maven pom.xml How to to initialize and use H2 database via Hibernate? How to use JNDI naming for DB connectivity on Jetty? As a base for sample project I’ll take a tiny webservice…
How to use Jetty to run Java web application locally?
Development of enterprise level web applications always cause some extra effort to setup various components locally. For example, if production environment runs big and robust Web Application server, like IBM WebSphere or Oracle WebLogic, you might don’t want to install and run it locally. Either for performance, configuration or licensing obstacles. There is a reasonable alternative to run and debug…
How to run Oracle SQLcl client directly as a Java class (skip sql.exe)?
Oracle SQL Developer Command Line (SQLcl) is a free command line interface for Oracle Database. It allows you to interactively or batch execute SQL and PL/SQL. SQLcl provides in-line editing, statement completion, and command recall for a feature-rich experience, all while also supporting your previously written SQL*Plus scripts. Here is what is said about this tool by Oracle. As an…
How to configure Flying Saucer and OpenPDF to load CSS from java resources classpath?
This post is a follow-up of the previous one about How to convert HTML to PDF in Java ? The latter is about how to use Flying Saucer and OpenPDF libraries to convert Html content to PDF. The sample in there was simply using resources by providing system path to necessary files. In the real world you can’t go like this.…
How to convert HTML to PDF in Java ?
There is so common requirement to generate PDF for some online content or reporting data. Also there is number of ways doing it. For example you could deliver it by leveraging headless browser (like Chrome or an older, already not supported but verified by time – PhantomJs) or use some dedicated back-end library. Differences between the latter are most likely…
JUnit test and mock private methods with PowerMock
First of all it might sound a bit strange – test private method. Why shall I do it – its private, not exposed and tend to change or disappear at all during some code refactoring. Although we might need to mock private method to dissociate from whatever it does, all the complexity, just use an output it supposed to produce.…