Skip to content

Commit

Permalink
1. Change user command package name; 2. Log exception message only in…
Browse files Browse the repository at this point in the history
… controller; 3. Redefine error message in controller and service.
  • Loading branch information
junior9919 committed Oct 20, 2015
1 parent 26f5d5a commit eb1ac43
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 22 deletions.
6 changes: 1 addition & 5 deletions src/com/halo/wechat/config/applicationContext-servlet.xml
Expand Up @@ -26,17 +26,13 @@
expression="execution(* com.halo.wechat.mvc.services.impls.MessageServiceImpl.checkSignature(..))" />
<aop:before pointcut-ref="serviceCheckSignature" method="logBeforeServiceCheckSignature" />
<aop:after pointcut-ref="serviceCheckSignature" method="afterMethod" />
<aop:after-throwing pointcut-ref="serviceCheckSignature"
method="afterThrowing" throwing="e" />
<aop:pointcut id="serviceProcessMessage"
expression="execution(* com.halo.wechat.mvc.services.impls.MessageServiceImpl.processMessage(..))" />
<aop:before pointcut-ref="serviceProcessMessage" method="logBeforeServiceProcessMessage" />
<aop:after pointcut-ref="serviceProcessMessage" method="afterMethod" />
<aop:after-throwing pointcut-ref="serviceProcessMessage"
method="afterThrowing" throwing="e" />
<!-- 执行用户命令对象方法的切点 -->
<aop:pointcut id="commandMethod"
expression="execution(* com.user.wechat.mvc.commands.UserCommand.*(..)) and args(..)" />
expression="execution(* com.*.wechat.mvc.commands.*.*(..)) and args(..)" />
<aop:before pointcut-ref="commandMethod" method="logBeforeCommandProcess" />
<aop:after pointcut-ref="commandMethod" method="afterMethod" />
<aop:after-throwing pointcut-ref="commandMethod"
Expand Down
10 changes: 0 additions & 10 deletions src/com/halo/wechat/config/applicationContext-wechat.xml
Expand Up @@ -93,34 +93,24 @@
expression="execution(* com.halo.wechat.saos.XmlSao.*(..)) and args(..)" />
<aop:before pointcut-ref="saoMethod" method="beforeMethod" />
<aop:after pointcut-ref="saoMethod" method="afterMethod" />
<aop:after-throwing pointcut-ref="saoMethod"
method="afterThrowing" throwing="e" />
<!-- 工具类方法切点 -->
<aop:pointcut id="domTemplateGet"
expression="execution(* com.halo.wechat.xml.utils.DomTemplate.get(..))" />
<aop:before pointcut-ref="domTemplateGet" method="logBeforeDomTemplateGet" />
<aop:after pointcut-ref="domTemplateGet" method="afterMethod" />
<aop:after-throwing pointcut-ref="domTemplateGet"
method="afterThrowing" throwing="e" />
<aop:pointcut id="springUtilsMethod"
expression="execution(* com.halo.spring.utils.*.*(..)) and args(..)" />
<aop:before pointcut-ref="springUtilsMethod" method="beforeMethod" />
<aop:after pointcut-ref="springUtilsMethod" method="afterMethod" />
<aop:after-throwing pointcut-ref="springUtilsMethod"
method="afterThrowing" throwing="e" />
<aop:pointcut id="httpUtilsMethod"
expression="execution(* com.halo.http.utils.*.*(..)) and args(..)" />
<aop:before pointcut-ref="httpUtilsMethod" method="beforeMethod" />
<aop:after pointcut-ref="httpUtilsMethod" method="afterMethod" />
<aop:after-throwing pointcut-ref="httpUtilsMethod"
method="afterThrowing" throwing="e" />
<!-- 微信能力接口类方法切点 -->
<aop:pointcut id="abilityMethod"
expression="execution(* com.halo.wechat.capabilities.abilities.*.*(..)) and args(..)" />
<aop:before pointcut-ref="abilityMethod" method="beforeMethod" />
<aop:after pointcut-ref="abilityMethod" method="afterMethod" />
<aop:after-throwing pointcut-ref="abilityMethod"
method="afterThrowing" throwing="e" />
<aop:pointcut id="signatureEncode"
expression="execution(* com.halo.wechat.capabilities.SignatureCapability.encodeParameters(..))" />
<aop:before pointcut-ref="signatureEncode" method="logBeforeSignatureEncode" />
Expand Down
Expand Up @@ -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);
}
}
}
Expand Down
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down

0 comments on commit eb1ac43

Please sign in to comment.