I have web resource
@Path("/test")
public class Test {
private TestService service;
@GET
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public Response hello() {
service = new TestService();
// String o = service.helloWorld();
Boolean a = true;
if (a)
throw new ExampleException();
return Response.ok().build();
}
}
My app config class
@ApplicationPath("/rest")
public class TestApp extends Application {
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(Test.class);
/** you need to add ExceptionMapper class as well **/
s.add(ExampleExceptionMaper.class);
return s;
}
}
Exception
public class ExampleException extends RuntimeException implements Serializable {
/**
*
*/
private static final long serialVersionUID = 6844337827096329241L;
public ExampleException() {
super("Test");
}
}
Exception mapper
@Provider
public class ExampleExceptionMaper implements ExceptionMapper<ExampleException> {
@Override
public Response toResponse(ExampleException arg0) {
return Response.status(404).build();
}
}
In my example Exception mapper doesn't works. I tried to cofigure it by java(adding Exception mapper class to hashmap in app config) or in web.xml (including it in context-param). My wildfly code ends work at Java 8 class: ThreadPoolExecutor.class. I think wildfly ends all its tasks on my example request on url of the resource. I code before throwing exception works fine, but after it doesn't return any response on my test request.
Anyone help?