0

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?

  • What happens if you remove the `getClasses()` from the `TestApp`? – James R. Perkins Nov 15 '16 at 00:18
  • What if you use a "normal" exception - i.e. not derived from RuntimeException? As a side note, I've used this in multiple projects and have never had to do what you're doing in the Application class. – stdunbar Nov 15 '16 at 23:07
  • I removed method getClasses() from App, but still doesn't works. I also tried to use for example NotFoundException(jax-rs) or extending my exception from Exception.class. A clue from me is that: the exception mapper works but in incorrect way. If I delete it I get standard exception handling and get stack trace in the web browser at resource url – Hubert Leszczyński Nov 17 '16 at 18:04
  • Ok i resolved the problem but unfortunetly I don't know why. I think deleting "getClass" method was a key but this started to wokr after some time :O – Hubert Leszczyński Nov 17 '16 at 19:17

0 Answers0