チームで Jersey Web アプリケーションに取り組んでいましたが、プロジェクトが大きくなるにつれて、Tomcat から Grizzly に切り替えて、プロジェクトの一部を異なるポート番号にデプロイできるようにすることにしました。私が今見つけたのは、私たちが持っているカスタム例外処理が今はうまくいかず、代わりに常に grizzly html ページを取得することです。
例外の例:
public class DataNotFoundException extends RuntimeException{
private static final long serialVersionUID = -1622261264080480479L;
public DataNotFoundException(String message) {
super(message);
System.out.println("exception constructor called"); //this prints
}
}
マッパー:
@Provider
public class DataNotFoundExceptionMapper implements ExceptionMapper<DataNotFoundException>{
public DataNotFoundExceptionMapper() {
System.out.println("mapper constructor called"); //doesnt print
}
@Override
public Response toResponse(DataNotFoundException ex) {
System.out.println("toResponse called"); //doesnt print
ErrorMessage errorMessage = new ErrorMessage(ex.getMessage(), 404, "No documentation yet.");
return Response.status(Status.NOT_FOUND)
.entity(errorMessage)
.build();
//ErrorMessage is a simple POJO with 2 string and 1 int field
}
}
問題の原因がどこにあるのかわかりません。必要に応じて、より多くの情報/コードを提供できます。何が問題なのですか、何を試すことができますか?
編集:
Main.class:
public class Main {
/**
* Main method.
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
...
List<ServerInfo> serverList = new ArrayList<ServerInfo>();
serverList.add(new ServerInfo(
"api",8450,
new ResourceConfig().registerClasses(
the.package.was.here.ApiResource.class)
));
for(ServerInfo server : serverList) {
server.start();
}
System.out.println("Press enter to exit...");
System.in.read();
for(ServerInfo server : serverList) {
server.stop();
}
}
}
EDIT2:この質問に
基づいて、このServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, "true"
プロパティを使用してみましたが、少ししか役に立ちませんでした。例外が発生したときにまだ html grizzly ページを取得していますが、ページの本文に例外 (+ スタック トレース) が表示されます。