我有一个 REST Web 服务,有时可以工作,有时会失败。也就是说,我的响应对象有几个子对象,包括一个有几组相关数据的子对象。这些子对象的数量取决于入站参数集。
如果我提交应该得到失败响应的用户 ID/密码;即,错误的用户 ID 或无效密码,响应按预期返回。
如果我提交了应该成功的用户 id / pw,并且没有返回复杂的对象,则响应会按预期返回。
最后,如果我提交了一个用户 id / pw,该用户 id / pw 应该返回一个附加到响应的复杂对象数组,我会收到一个日志记录静默失败,并重定向到 500 页。有一段时间,我收到关于主要复杂对象上的子对象和 Hibernate Session 关闭/不可用问题的投诉。我尝试初始化整个世界,这“帮助”了我不再从 Hibernate 获得关于子对象上的会话问题的详细异常日志记录,但我仍然被重定向到 500 页而根本没有任何日志记录。为了弄清楚这是否是嵌套/隐藏会话问题的问题,我尝试附加一个手工创建的对象,但仍然得到 500 页。
下面是我的控制器代码,它在某些情况下有效,但如果 EnergyAudit[] 数组填充了任何内容,则会失败。
@RequestMapping(method= RequestMethod.GET,value="login")
public @ResponseBody LoginResponse login(@RequestParam("userName") String userNameIn, @RequestParam("password") String passwordIn){
LoginResponse theResponse = new LoginResponse();
try{
logger.info("Entering login for username: "+ userNameIn + " and pw: "+ passwordIn);
// CREATE!
EnergyAuditUser theUser;
try{
// DO A BUNCH OF STUFF TO VALIDATE THEY ARE AN OK USER LEFT OUT FOR OUR PURPOSES HERE.
// OK. IF WE GOT HERE, THEN WE CAN ASSUME THAT THERE IS A USER
// AND THEY GAVE US TEH GOOD DATA. GOOD JOB, USER!
theResponse.setSuccessOrFailureSw(Constants.SUCCESS);
theResponse.setResponseMessage("Successfully logged in!");
theResponse.setTheUser(theUser);
// NOW, IF THE USER IS NOT A REACH USER, WE WANT TO SUBMIT BACK ANY AUDITS
// REACH USERS WILL HAVE ANOTHER TRANSACTION SET TO ALLOW THEM TO PICK AND CHOOSE
// FROM THE DAYS AUDITS!
if (theUser.getEnergyAuditUserType().equalsIgnoreCase(EnergyAuditUser.COT_AUDITOR_TYPE)){
// WE SHOULD GET ANY AND ALL OPEN, ASSIGNED AUDITS FOR THIS USER.
EnergyAudit[] assignedAudits = auditService.getAssignedEnergyAuditsForUser(theUser.getEnergyAuditUserId(), false,false, true, false);
// theResponse.setEnergyAudits(assignedAudits);
// NOTE THAT HERE I ATTEMPTED TO CREATE A NON-BOUND AUDIT TO EVALUATE IF THE SILENT FAILURE WAS HIBERNATE SESSION RELATED. NO LOVE!
EnergyAudit bogusAudit = new EnergyAudit();
bogusAudit.setStartingInsulationRvalue(32);
bogusAudit.setStreetAddress("123 Chiefy Street");
bogusAudit.setAuditDate(new java.util.Date());
EnergyAudit[] bogusResults = new EnergyAudit[1];
bogusResults[0] = bogusAudit;
theResponse.setEnergyAudits(bogusResults);
}
// THIS USER / LOSER OUGHT TO BE GOOD TO GO!
return theResponse;
让我发疯的是,我的控制台没有给我任何关于这里发生的事情的信息。非常感谢任何见解。
布莱恩