lizongbo at 618119.com 工作,生活,Android,前端,Linode,Ubuntu,nginx,java,apache,tomcat,Resin,mina,Hessian,XMPP,RPC

2007年12月13日

用Spring,smppapi,apache mina, commons ssl快速实现安全的smpp smsc (五)

Filed under: Java,SSL — 标签:, , , , , , , , — lizongbo @ 08:43

接上一篇: http://618119.com/archives/2007/12/06/39.html

为 DefaultIoFilterChainBuilder 增加filter:

[code]
import org.apache.mina.filter.LoggingFilter;
import javax.net..SSLContext;
import org.apache.mina.filter.SSLFilter;
import org.apache.mina.common.DefaultIoFilterChainBuilder;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.commons.ssl.*;
import java.io.*;
import java.security.*;
import com.lizongbo..ssl.SMPPSSLContextFactory;
import com.lizongbo.smpp.server.codec.SMPPProtocolCodecFactory;

public static final int PORT = 5432;
public static final int CONNECT_TIMEOUT = 3; // seconds
private static final boolean USE_SSL = true;
private static final boolean USE_LOG = false;
private static final boolean USE_COMPRESS = false;
private static final boolean USE_THREADPOOL = false;
/**
添加服务端的ssl支持
*/
public static void addServerSSLSupport(DefaultIoFilterChainBuilder chain) throws
Exception {
if (USE_SSL) {
SSLContext sslc = SMPPSSLContextFactory.getInstance(true);
SSLFilter sslFilter = new SSLFilter(sslc);
sslFilter.setNeedClientAuth(true);//
//sslFilter.setWantClientAuth(true);
sslFilter.setEnabledCipherSuites(new String[] {
“TLS_RSA_WITH_AES_256_CBC_SHA”
“SSL_RSA_WITH_RC4_128_MD5″//,
“TLS_RSA_WITH_AES_128_CBC_SHA”,
“TLS_DHE_RSA_WITH_AES_128_CBC_SHA”,
“TLS_DHE_DSS_WITH_AES_128_CBC_SHA”,
“TLS_RSA_WITH_AES_256_CBC_SHA”,
“TLS_DHE_RSA_WITH_AES_256_CBC_SHA”,
“SSL_RSA_WITH_RC4_128_SHA”,
“TLS_DHE_DSS_WITH_AES_256_CBC_SHA”
});
chain.addLast(“sslFilter”, sslFilter);
System.out.println(“Server SSL ON”);
}
}
/**
添加客户端的ssl支持
*/
public static void addCilentSSLSupport(DefaultIoFilterChainBuilder chain) throws
Exception {
if (USE_SSL) {
SSLContext sslc = SMPPSSLContextFactory.getInstance(false);
SSLFilter sslFilter = new SSLFilter(sslc);
sslFilter.setUseClientMode(true);
chain.addLast(“sslFilter”, sslFilter);
System.out.println(“Client SSL ON”);
}
}
/**
添加 logger 过滤器
*/
public static void addLogger(DefaultIoFilterChainBuilder chain) throws
Exception {
if (USE_LOG) {
chain.addLast(“logger”, new LoggingFilter());
System.out.println(“Logging ON”);
}
}
/**
添加压缩 过滤器
*/
public static void addCompress(DefaultIoFilterChainBuilder chain) throws
Exception {
if (USE_COMPRESS) {
chain.addLast(“compress”, new org.apache.mina.filter.CompressionFilter());
System.out.println(“Compress ON”);
}
}
/**
添加编码解码过滤器
*/
public static void addCodec(DefaultIoFilterChainBuilder chain) throws
Exception {
chain.addLast(“codec”,
new ProtocolCodecFilter(new SMPPProtocolCodecFactory()));

}
/**
添加线程池过滤器
*/
public static void addThreadPool(DefaultIoFilterChainBuilder chain) throws
Exception {
if (USE_THREADPOOL) {
chain.addLast(“threadpool”,
new org.apache.mina.filter.executor.ExecutorFilter());
System.out.println(“Threadpool ON”);
}
}

public static void main(String[] args) throws IOException, Exception {
IoAcceptor acceptor = new SocketAcceptor();
IoAcceptorConfig config = new SocketAcceptorConfig();
DefaultIoFilterChainBuilder chain = config.getFilterChain();
//Utils.addServerSSLSupport(chain);
Utils.addThreadPool(chain);
Utils.addCompress(chain);
Utils.addCodec(chain);
Utils.addLogger(chain);
SMPPServerSessionHandler handlers = new SMPPServerSessionHandler();
handlers.getHandles().put(Integer.valueOf(0x00000001),
new com.lizongbo.smpp.server.handlers.
BindReceiverHandler());
handlers.getHandles().put(Integer.valueOf(0x00000002),
new com.lizongbo.smpp.server.handlers.
BindTransmitterHandler());
handlers.getHandles().put(Integer.valueOf(0x00000004),
new com.lizongbo.smpp.server.handlers.
SubmitSMHandler());
handlers.getHandles().put(Integer.valueOf(0x00000006),
new com.lizongbo.smpp.server.handlers.
UnbindHandler());
InetSocketAddress serverAddr = new InetSocketAddress(Utils.PORT);
acceptor.bind(
serverAddr, handlers,
config);

//JMX控制

IoServiceManager serviceManager = new IoServiceManager(acceptor);
serviceManager.startCollectingStats(1000);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName(
“com.lizongbo.smpp.server:type=IoServiceManager”);
mbs.registerMBean(serviceManager, name);

System.out.println(“Listening on port ” + Utils.PORT);
}

[/code]

一条评论 »

  1. […] lizongbo at 618119.com 工作,生活,java,apache,tomcat,Squid,lighttpd,Resin,mina…… « 用Spring,smppapi,apache mina, commons ssl快速实现安全的smpp smsc (五) […]

    Pingback by » 用Spring,smppapi,apache mina, commons ssl快速实现安全的smpp smsc (五) -- lizongbo at 618119.com — 2007年12月14日 @ 14:37

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress