JBoss EJB3.0 RC6 -PFD
http://www.jboss.org/jbossejb3/docs/reference/build/reference/en/html/index.html
10 传输
这张解释了客户端怎样和EJB3容器之间通讯, 怎样设置替换的传输方式。传输方式基于JBoss Remoting, 更深层次的例子请参见其文档。
10.1 缺省传输
基于socket的调用层,端口3878. 参见deploy/ejb3.deployer/META-INF/jboss-service.xml。实用设置:
<mbean code="org.jboss.remoting.transport.Connector"
xmbean-dd="org/jboss/remoting/transport/Connector.xml"
name="jboss.remoting:type=Connector,name=DefaultEjb3Connector,handler=ejb3">
<depends>jboss.aop:service=AspectDeployer</depends>
<attribute name="InvokerLocator">socket://0.0.0.0:3873</attribute>
<attribute name="Configuration">
<handlers>
<handler subsystem="AOP">org.jboss.aspects.remoting.AOPRemotingInvocationHandler</handler>
</handlers>
</attribute>
</mbean>
InvokerLocator决定了协议、IP和端口。0.0.0.0表示所有网卡。
Configuration属性指定到了EJB容器的入口: AOPRemotingInvocationHandler.
10.2 加密传输
有时候 你可能希望SSL来加密传输(太需要了)。先生成个keystore吧
10.2.1 生成keystore和 truststore
先 来个公钥私钥对:
cd $JBOSS_HOME/server/default/conf/
keytool -genkey -alias ejb3-ssl -keypass opensource -keystore localhost.keystore
别名ejb3-ssl, 密码opensource, 文件名localhost.keystore
导出证书:
keytool -export -alias ejb3-ssl -file mycert.cer -keystore localhost.keystore
给客户端导入:
keytool -import -alias ejb3-ssl -file mycert.cer -keystore localhost.truststore
10.2.2 设置SSL传输
最简单的方法是定义一个新的Remoting connector:
<mbean code="org.jboss.remoting.transport.Connector"
xmbean-dd="org/jboss/remoting/transport/Connector.xml"
name="jboss.remoting:type=Connector,transport=socket3843,handler=ejb3">
<depends>jboss.aop:service=AspectDeployer</depends>
<attribute name="InvokerLocator">sslsocket://0.0.0.0:3843</attribute>
<attribute name="Configuration">
<handlers>
<handler subsystem="AOP">org.jboss.aspects.remoting.AOPRemotingInvocationHandler</handler>
</handlers>
</attribute>
</mbean>
keystore和密码系统Properties传入jboss:
run -Djavax.net.ssl.keyStore=../server/default/conf/localhost.keystore -Djavax.net.ssl.keyStorePassword=opensource
10.2.3 配置EJB实用SSL
缺省连接时socket://0.0.0.0:3873. 使用@org.jboss.annotation.ejb.RemoteBinding来指定SSL:
@RemoteBinding(clientBindUrl="sslsocket://0.0.0.0:3843", jndiBinding="StatefulSSL"),
@Remote(BusinessInterface.class)
public class StatefulBean implements BusinessInterface
{
...
}
还能指定不同的通讯方式:
@RemoteBindings({
@RemoteBinding(clientBindUrl="sslsocket://0.0.0.0:3843", jndiBinding="StatefulSSL"),
@RemoteBinding(jndiBinding="StatefulNormal")
})
@Remote(BusinessInterface.class)
public class StatefulBean implements BusinessInterface
{
...
}
10.2.4 设定客户端实用truststore
如果你的证书不是授信机构签名的, 你需要用System Properties来制定store和密码:
java -Djavax.net.ssl.trustStore=${resources}/test/ssl/localhost.truststore -Djavax.net.ssl.trustStorePassword=opensource com.acme.RunClient