こことインターネットですでに検索しましたが、問題の解決策が見つかりませんでした。
カスタム例外ハンドラーを使用して、すべての Java 例外をインターセプトし、それらを特定の方法で処理したいと考えています (特定のステータスを応答に設定し、次に一般的な Ajax エラーで呼び出します。それらは処理され、JS ダイアログは次のようになります。特定のメッセージで作成されます)。
だから私は自分のアクションを作成しました:
public class DefaultExceptionHandlerAction extends ExceptionMappingInterceptor {
/** The class logger. */
private static final Logger LOGGER = Logger.getLogger(DefaultExceptionHandlerAction.class);
@Override
protected void publishException(ActionInvocation invocation, ExceptionHolder exceptionHolder) {
LOGGER.error("Global Exception msg: "+ exceptionHolder.getException().getMessage(), exceptionHolder.getException());
String message = "error msg for client";
HttpServletResponse response = ServletActionContext.getResponse();
response.reset();
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
PrintWriter out = null;
try {
response.setCharacterEncoding("UTF-8");
out = response.getWriter();
out.print(message);
} catch (IOException ioe) {
LOGGER.error("IOException in printMessage : " + ioe.getMessage(), ioe);
} finally {
if (out != null) {
out.flush();
out.close();
}
}
}
}
これに加えて、私の struts.xml には次のものがあります。
<interceptor name="exception" class="com.travelsoft.orchestra.b2b.configuration.DefaultExceptionHandlerAction" />
<interceptor-stack name="securedStack">
<interceptor-ref name="exception" />
<interceptor-ref name="defaultStack" />
<interceptor-ref name="i18n" />
<interceptor-ref name="login" />
</interceptor-stack>
<global-results>
<result name="exception">/defaultExceptionHandler.action</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="exception" />
</global-exception-mappings>
ある特定のアクションでは、コード内で直接 null ポインター例外を強制しました。もちろん、このアクションはsecuredStack
インターセプターを使用しています。
このアクションを実行すると、未定ループが発生します。
JavaScript:
error : function(jqXHR, textStatus, errorThrown) {
// all other errors
var contentDialog = $("<div/>",{ "id":"contentDialog"});
contentDialog.html(jqXHR.responseText);
contentDialog.dialog({
title : 'Erreur',
modal : true,
zIndex: 8888,
resizable: false,
close: function(event, ui) {
$(this).dialog("destroy").remove();
},
buttons:{"OK": function() {
$(this).dialog("close");}}
});
},...