[英]How to get informations of request on ExceptionMapper of Jersey
當我拋出Throwable時,我想將請求的信息保存在硬盤上以進行調試。 這是可能的?
例如:
@Provider
public class DefaultExceptionMapper implements ExceptionMapper<Throwable> {
@Override
public Response toResponse(Throwable exception) {
exception.printStackTrace();
JSONObject msg = new JSONObject();
msg.put("msg", "Try again.");
// i need something like this
JSONObject request = SuperEspecialClass.getActualRequest().parseToJSON();
request.saveOnHardDriveForDebugLater();
/**request contains -> all headers
request contains -> all parameters
request contains -> body
request contains -> method
request contains -> URI
like this :
{
url : '/url',
method : '',
headers : [],
params : [],
body : ''
}*/
return Response
.serverError()
.entity(msg)
.build();
}
}
使用@Context HttpServletRequest
的表單參數不見了。 而且主體不是通過request.getReader()
。
可能沒有官方API可以再次獲取輸入參數,這將意味着再次讀取請求InputStream。
您可以實現一個攔截器 ,該攔截器在進行請求之前保存方法參數,並在出現異常的情況下進行檢索。 您必須特別注意攔截器的線程安全性:您不想混合來自不同請求的異常和參數。 另請注意,在反序列化,驗證或請求匹配期間可能會發生異常,在這種情況下,您根本沒有參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.