用Spring,smppapi,mina, commons ssl快速实现安全的smp(3)

作者:lizongbo
版权声明:可以任意转载,转载时请务必以超链接形式标明文章和作者信息及本版权声明


接上一篇: http://618119.com/archives/2007/11/29/34.html
针对每个SMPPPacket的处理,将其以接口方式进行处理,接口定义如下:

 

  1. package com.lizongbo.smpp.server;   
  2. import org.apache.mina.common.IoSession;   
  3. import ie.omk.smpp.message.SMPPPacket;   
  4. import ie.omk.smpp.BadCommandIDException;   
  5. public interface SMPPPacketHandler {   
  6. void process(IoSession session, SMPPPacket packet) throws  
  7. BadCommandIDException;   
  8. }  
package com.lizongbo.smpp.server;
import org.apache.mina.common.IoSession;
import ie.omk.smpp.message.SMPPPacket;
import ie.omk.smpp.BadCommandIDException;
public interface SMPPPacketHandler {
void process(IoSession session, SMPPPacket packet) throws
BadCommandIDException;
}

 

SMPPServerSessionHandler中通过commandid来找到相应的handler,然后进行处理.

 

  1. package com.lizongbo.smpp.server;   
  2. import java.util.*;   
  3. import org.apache.mina.common.*;   
  4. import ie.omk.smpp.*;   
  5. import ie.omk.smpp.message.*;   
  6. import ie.omk.smpp.version.*;   
  7. public class SMPPServerSessionHandler   
  8. extends IoHandlerAdapter {   
  9. private Map<Long,   
  10. SMPPPacketHandler> handles = null;   
  11. private int readerIdleTimeout = 120;   
  12. public void sessionOpened(IoSession session) throws Exception {   
  13. session.setIdleTime(IdleStatus.READER_IDLE, readerIdleTimeout);   
  14. }   
  15. public void messageReceived(IoSession session, Object message) throws  
  16. Exception {   
  17. SMPPPacket packet = (SMPPPacket) message;   
  18. // System.out.println(”收到消息” + packet);   
  19. int id = packet.getCommandId();   
  20. if (!SMPPVersion.getDefaultVersion().isSupported(id)) {   
  21. StringBuffer err = new StringBuffer(120)   
  22. .append(SMPPVersion.getDefaultVersion().toString())   
  23. .append(” does not support command ID 0x”)   
  24. .append(Integer.toHexString(id));   
  25. throw new VersionException(err.toString());   
  26. }   
  27. long l = id & 0×00000000FFFFFFFFl;   
  28. // Integer.decode(”0×80000005″)要出错,被迫用Long类型,   
  29. //因此在这里需要将整数的id通过高位补0来实现,而不能直接进行强类型转换   
  30. SMPPPacketHandler handler = handles.get(Long.valueOf(l));   
  31. if (handler != null) {   
  32. handler.process(session, packet);   
  33. }   
  34. else {   
  35. //System.out.println(”丢弃的消息为:” +  id + packet);   
  36. //throw new BadCommandIDException();   
  37. }   
  38. }   
  39. public Map getHandles() {   
  40. return handles;   
  41. }   
  42. public int getReaderIdleTimeout() {   
  43. return readerIdleTimeout;   
  44. }   
  45. public void setHandles(Map handles) {   
  46. this.handles = handles;   
  47. }   
  48. public void setReaderIdleTimeout(int readerIdleTimeout) {   
  49. this.readerIdleTimeout = readerIdleTimeout;   
  50. }   
  51. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值