I encountered a strange problem with my wildfly-swarm application. I've got an JAX-RS Service, Annotation and RequestFilter defined like this
FooService.java
@Path("/foo")
@RequestScoped
@Api(value = "foo")
public class FooService extends BaseService {
@GET
@Produces({MediaType.APPLICATION_JSON})
@ApiOperation(...)
@ApiResponses(...)
@Secured({UserGroup.USER})
public Response getBar(@ApiParam(...) @QueryParam("id") int id) {
return Response.ok("bar").build();
}
}
BaseService.java
public class BaseService {
...
}
Secured.java
@NameBinding
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Secured {
UserGroup[] value() default {};
}
FooFilter.java
@Secured
@Provider
@Priority(Priorities.AUTHENTICATION)
public class FooFilter extends BaseService implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext requestContext) {
...
}
}
As far as I understand FooFilter.filter() should be called everytime GET/foo is requested. With Wildfly 12 everything works just fine, but running my wildfly-swarm app FooFilter.filter() is never invoked. Any suggestions why?
Just to be complete, here are my dependencies from my pom file.
<!-- Java EE 7 dependency --> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency> <!-- WildFly Swarm Fractions --> <dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>cdi</artifactId> </dependency> <dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>ejb</artifactId> </dependency> <dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>jaxrs</artifactId> </dependency> <dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>jpa</artifactId> <exclusions> <exclusion> <groupId>org.wildfly.swarm</groupId> <artifactId>h2</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>transactions</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${version.mysql}</version> </dependency>
Thanks in advance!
Stupid me. I got it working. I just added
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<>();
//Filter
classes.add(FooFilter.class);
return classes;
}
to my Application class. Wildfly swarm is based an Wildfly 11 and not 12. 11 uses RestEasy 3.0.24 as JAX-RS implementation, 12 uses RestEasy 3.5.
It seems that RestEasy 3.0.24 needs to register a RequestFilter manually, whereas 3.5 does not need to.