eclipse-ee4j / eclipse-ee4j/jersey

Ignore/default methods in the resource interface

Open
#4,183 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

Hello,

Is there any way to ignore methods declared in a resource interface? The use case is adding a default method that catches a NotFoundException and returns an Optional.

Would prefer to not have to catch JAX-RS specific exceptions in the business layer and also avoid checked exceptions by using an Optional here, example:

```
@Path("/")
interface RestService {
@Path("/string") @GET
String getString();

default Optional getStringOptional() {
try {
return Optional.of(getString());
} catch (NotFoundException e) {
return Optional.empty();
}
}
}
```
I don't see why default methods are being proxied. The example fails because getStringOptional is not a "resource method", if resource annotations are added then a proxy is created and the default method never called.

The initial approach was to create a ClientResponseFilter that threw a custom 404 exception that isn't tied to the JAX-RS spec. This didn't work because we're using the CXF client and any exceptions thrown from a filter is wrapped.

Have not tried throwing exceptions from a filter when using the Jersey client, I'd like to avoid that because I got even more issues with it, compared to CXF. JNDI lookups failing etc.. not the rabbit hole I wanted to explore.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.