December 6, 2023

RESTful Java client with java.net.URL

In this tutorial, we show you how to create a RESTful Java client with Java build-in HTTP client library. It’s simple to use and good enough to perform basic operations for REST service. The RESTful services from last “Jackson + JAX-RS” article will be reused, and we will use “java.net.URL” and “java.net.HttpURLConnection” to create a simple Java client to send “GET” and “POST” request.

RESTful Java client with java.net.URL Read More

How to load logging.properties for java.util.logging

In Java Logging APIs or java.util.logging, we use system property java.util.logging.config.file to define the location of the logging.properties file. Normally, we put the logging.properties at the src/main/resources, and project compile or build will copy it to the root of the classpath. And we can use LogManager or System.setProperty to load the logging.properties programmatically.

How to load logging.properties for java.util.logging Read More

Jersey and HK2 dependency injection (auto scanning)

This article shows how to use HK2 dependency injection framework in Jersey and enable auto-scanning auto-discovery of the declared @Contract and @Service components. Jersey, by default, uses HK2 (Hundred-Kilobyte Kernel) for dependency injection. And the HK2 is an implementation of JSR-330(Dependency Injection for Java). For Jersey and HK2 development, we only need to declare jersey-hk2.

Jersey and HK2 dependency injection (auto scanning) Read More