From eb1ac437b47373637ed9ecbb0336c84678a96bc1 Mon Sep 17 00:00:00 2001 From: junior9919 <18186131274@189.cn> Date: Tue, 20 Oct 2015 22:07:35 +0800 Subject: [PATCH] 1. Change user command package name; 2. Log exception message only in controller; 3. Redefine error message in controller and service. --- .../halo/wechat/config/applicationContext-servlet.xml | 6 +----- .../halo/wechat/config/applicationContext-wechat.xml | 10 ---------- .../mvc/controllers/WeChatMessageController.java | 6 +++--- .../wechat/mvc/services/impls/MessageServiceImpl.java | 8 ++++---- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/com/halo/wechat/config/applicationContext-servlet.xml b/src/com/halo/wechat/config/applicationContext-servlet.xml index 4487ca9..17cf5ca 100644 --- a/src/com/halo/wechat/config/applicationContext-servlet.xml +++ b/src/com/halo/wechat/config/applicationContext-servlet.xml @@ -26,17 +26,13 @@ expression="execution(* com.halo.wechat.mvc.services.impls.MessageServiceImpl.checkSignature(..))" /> - - + expression="execution(* com.*.wechat.mvc.commands.*.*(..)) and args(..)" /> - - - - - diff --git a/src/com/halo/wechat/mvc/controllers/WeChatMessageController.java b/src/com/halo/wechat/mvc/controllers/WeChatMessageController.java index df61f72..f323a6b 100644 --- a/src/com/halo/wechat/mvc/controllers/WeChatMessageController.java +++ b/src/com/halo/wechat/mvc/controllers/WeChatMessageController.java @@ -46,20 +46,20 @@ public void handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) thr try { messageService.processMessage(arg0, arg1); } catch (ServiceException e) { - throw new ControllerException("An error occured when process message. ", e); + throw new ControllerException("Process message service exception. ", e); } } else { try { messageService.checkSignature(arg0, arg1); } catch (ServiceException e) { - throw new ControllerException("An error occured when check signature. ", e); + throw new ControllerException("Check signature service exception. ", e); } } } else { try { messageService.processMessage(arg0, arg1); } catch (ServiceException e) { - throw new ControllerException("An error occured when process message. ", e); + throw new ControllerException("Process message service exception. ", e); } } } diff --git a/src/com/halo/wechat/mvc/services/impls/MessageServiceImpl.java b/src/com/halo/wechat/mvc/services/impls/MessageServiceImpl.java index a6c8dc1..9b805ae 100644 --- a/src/com/halo/wechat/mvc/services/impls/MessageServiceImpl.java +++ b/src/com/halo/wechat/mvc/services/impls/MessageServiceImpl.java @@ -41,7 +41,7 @@ public void checkSignature(HttpServletRequest request, HttpServletResponse respo try { signatureAbility.checkSignature(request, response); } catch (CapabilityException e) { - throw new ServiceException("An error occured when check signature, see log in " + signatureAbility.getClass().getName()); + throw new ServiceException("Check signature failed.", e); } } @@ -56,20 +56,20 @@ public void processMessage(HttpServletRequest request, HttpServletResponse respo try { receiveMessage = messageAbility.receiveMessage(request); } catch (CapabilityException | NullSaoException e) { - throw new ServiceException("An error occured when receive message. ", e); + throw new ServiceException("Receive message process failed. ", e); } Message responseMessage = null; try { responseMessage = messageAbility.executeCommand(command, receiveMessage); } catch (CapabilityException e) { - throw new ServiceException("An error occured when execute user command. ", e); + throw new ServiceException("Execute user command failed. ", e); } try { messageAbility.responseMessage(response, responseMessage); } catch (CapabilityException | NullSaoException e) { - throw new ServiceException("An error occured when write response message. ", e); + throw new ServiceException("Response message failed. ", e); } }