创建Axis2 Rampart客户端时出现问题

时间:2011-06-28 08:54:06

标签: web-services axis2 rampart

我正在使用Axis2创建一个Web服务,它使用Rampart进行身份验证。在Rampart的所有示例中,客户端需要具有Axis2的客户端存储库。 Rampart在客户端启动如下:

ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("path/to/client/repo", null);

SecureServiceStub stub = new SecureServiceStub(ctx,"https://localhost:8443/axis2/services/SecureService");

ServiceClient sc = stub._getServiceClient();

sc.engageModule("rampart");

方法createConfigurationContextFromFileSystem需要一个到具有rampart.mar文件的客户端上的Axis2 repo的路径。它显然需要一条完整的绝对路径,而不是相对路径。

但是,我正在使用Java Web Start部署我的客户端,并且我无法在每台可能需要运行客户端的计算机上放置Axis2 repo。它需要从Web浏览器中的任何机器工作,因此客户端需要在jar中的所有内容。有什么办法可以从我的客户端应用程序的jar中加载rampart.mar文件吗?

另一种可能性是使用ConfigurationContextFactory.createConfigurationContextFromURIs方法,但这需要我在服务器上创建axis2 + rampart的在线仓库。有人知道这个好指南吗?我仍然希望只是将所有东西打包在罐子里。

1 个答案:

答案 0 :(得分:1)

如果您不需要Axis2存储库(我一直认为这是Axis2客户端的情况),那么您可以使用以下内容加载没有存储库的ConfigurationContext(请注意我添加的额外详细信息)代码评论)...

//Globally sharable as long as care is taken to call ServiceClient.cleanupTransport()
//in 'finally' block after port call - avoids expensive object creation upon every use
//Must cleanup transport when reusing ConfigurationContext.  See...
//http://issues.apache.org/jira/browse/AXIS2-4357
//http://markmail.org/message/ymqw22vx7j57hwdy#query:axis2%20ConfigurationContext%20thread%20safe+page:1+mid:jh54awy6lf2tk524+state:results
private static final ConfigurationContext CONFIG_CTX = createConfigurationContext();
....
....

private static ConfigurationContext createConfigurationContext()
{
    try
    {
        //See: http://wso2.org/library/585, or specifically...
        //"Option 1 : Create ConfigurationContext by using both the parameters as NULL"
        //Module mar files should be placed in the same location as the Axis2
        //jar files.  Actually, mar files don't need to be literally listed
        //in the classpath, but merely placed in the same relative location
        //as the Axis2 jar files.
        //"In this particular case we have neither service hot-deployment
        //nor service hot-update since we do not have a repository."
        //Even though we do not have a repository in this case, we have an
        //option to add modules (module mar files) in to the classpath and
        //engage them whenever we want."
        return ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    }
    catch (final Throwable th)
    {
        //Squash.  Shouldn't occur, but ignorable anyway because ServiceClient
        //accepts a null ConfigurationContext argument without complaint.
        return null;
    }
}