2018-12-03 10:44:14 +08:00
|
|
|
package com.gzzn.omms.msgexchangeapi.msghandler;
|
|
|
|
|
|
2018-12-04 11:37:45 +08:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.lang.reflect.Method;
|
2018-12-03 10:44:14 +08:00
|
|
|
|
2018-12-05 18:05:50 +08:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-12-03 10:44:14 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
2018-12-06 14:35:12 +08:00
|
|
|
import com.gzzn.omms.msgexchangeapi.entity.Cminmsg;
|
2018-12-07 15:29:28 +08:00
|
|
|
import com.gzzn.omms.msgexchangeapi.entity.msg.MSG;
|
|
|
|
|
import com.gzzn.omms.msgexchangeapi.service.exchange.IExchangeService;
|
2018-12-03 10:44:14 +08:00
|
|
|
|
2018-12-06 16:38:47 +08:00
|
|
|
@Service("msgHandlerDispatcher")
|
2018-12-03 10:44:14 +08:00
|
|
|
public class MsgHandlerDispatcher {
|
2018-12-05 18:05:50 +08:00
|
|
|
private Logger logger = LoggerFactory.getLogger(MsgHandlerDispatcher.class);
|
|
|
|
|
|
2018-12-03 10:44:14 +08:00
|
|
|
@Autowired
|
|
|
|
|
IExchangeService exchangeService;
|
|
|
|
|
|
2018-12-06 14:35:12 +08:00
|
|
|
public HandlerResult dispatch(Cminmsg cminmsg)
|
2018-12-03 10:44:14 +08:00
|
|
|
{
|
2018-12-07 15:29:28 +08:00
|
|
|
MSG msg = exchangeService.xmlstrToObject(cminmsg.getCminmsgsClobMsg(), MSG.class);
|
|
|
|
|
String type = msg.getMETA().getTYPE().name();
|
|
|
|
|
String subType = msg.getMETA().getSTYP().name();
|
2018-12-03 10:44:14 +08:00
|
|
|
|
2018-12-04 11:37:45 +08:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Class clazzHandler = Class.forName(getHandlerClassName(type,subType));
|
|
|
|
|
Object classObject = clazzHandler.newInstance();
|
2018-12-06 14:35:12 +08:00
|
|
|
Method runMethod = clazzHandler.getMethod("run", Cminmsg.class);
|
|
|
|
|
HandlerResult result = (HandlerResult) runMethod.invoke(classObject, cminmsg);
|
2018-12-04 11:37:45 +08:00
|
|
|
return result;
|
|
|
|
|
} catch (ClassNotFoundException
|
|
|
|
|
| InstantiationException
|
|
|
|
|
| IllegalAccessException
|
|
|
|
|
| NoSuchMethodException
|
|
|
|
|
| SecurityException
|
|
|
|
|
| IllegalArgumentException
|
|
|
|
|
| InvocationTargetException e) {
|
2018-12-05 18:05:50 +08:00
|
|
|
//throw new RuntimeException(e);
|
|
|
|
|
logger.error("消息处理失败:{}",e.getMessage());
|
|
|
|
|
return HandlerResult.failure();
|
2018-12-04 11:37:45 +08:00
|
|
|
}
|
|
|
|
|
}//end function
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取handler 类的名称
|
|
|
|
|
* @param type
|
|
|
|
|
* @param subType
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String getHandlerClassName(String type , String subType)
|
|
|
|
|
{
|
|
|
|
|
StringBuffer buffer = new StringBuffer();
|
|
|
|
|
buffer.append("com.gzzn.omms.msgexchangeapi.msghandler" );
|
|
|
|
|
buffer.append(".");
|
2018-12-04 14:53:50 +08:00
|
|
|
buffer.append(type.toLowerCase());
|
2018-12-04 11:37:45 +08:00
|
|
|
buffer.append(".");
|
|
|
|
|
buffer.append(subType);
|
|
|
|
|
buffer.append("Handler");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return buffer.toString();
|
|
|
|
|
} //end function
|
|
|
|
|
|
2018-12-03 10:44:14 +08:00
|
|
|
}
|