Propagating ThreadLocal to a new Thread fetched from a ExecutorService

The set of ThreadLocal instances associated with a thread are held in private members of each Thread. Your only chance to enumerate these is to do some reflection on the Thread; this way, you can override the access restrictions on the thread’s fields. Once you can get the set of ThreadLocal, you could copy in … Read more

Optional @PathParam in Jax-RS

The problem was the lack of whitespace before the colon: @Path(“/mypath{param1: (/param1)?}”) should be: @Path(“/mypath{param1 : (/param1)?}”) Apparently it’s a bug, because the specification makes the whitespace around the colon optional. I also found that I’m not the first bitten by this bug.

PersistenceContext EntityManager injection NullPointerException

An entity manager can only be injected in classes running inside a transaction. In other words, it can only be injected in a EJB. Other classe must use an EntityManagerFactory to create and destroy an EntityManager. Since your TestService is not an EJB, the annotation @PersistenceContext is simply ignored. Not only that, in JavaEE 5, … Read more

Logging request and response in one place with JAX-RS

You can create filters and easily bind them to the endpoints you need to log, keeping your endpoints lean and focused on the business logic. Defining a name binding annotation To bind filters to your REST endpoints, JAX-RS provides the meta-annotation @NameBinding and it can be used as following: @NameBinding @Retention(RUNTIME) @Target({TYPE, METHOD}) public @interface … Read more

How to choose between Jersey, Apache Wink and JBoss RESTEasy? [closed]

JAX-RS Implementations Jersey Reference Implementation Usually the most cutting edge Supports true asynchronous (ie web sockets etc…) connections through either Atmosphere or 2.0 version. Has support for Spring and standard injection containers (ie @Inject). Glassfish bundles it. Its much more modular than the other JAX-RS projects. It has a kick ass URI Builder Does not … Read more

Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

The problem is the JSON – this cannot, by default, be deserialized into a Collection because it’s not actually a JSON Array – that would look like this: [ { “name”: “Test order1”, “detail”: “ahk ks” }, { “name”: “Test order2”, “detail”: “Fisteku” } ] Since you’re not controlling the exact process of deserialization (RestEasy … Read more

Java 8 LocalDate Jackson format

I was never able to get this to work simple using annotations. To get it to work, I created a ContextResolver for ObjectMapper, then I added the JSR310Module (update: now it is JavaTimeModule instead), along with one more caveat, which was the need to set write-date-as-timestamp to false. See more at the documentation for the … Read more