1

我正在使用 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 需要客户端上的 Axis2 存储库的路径,该存储库具有 armart.mar 文件。它显然需要一个完整的绝对路径,而不是相对路径。

但是,我正在使用 Java Web Start 部署我的客户端,我无法在可能需要运行客户端的每台机器上都放置一个 Axis2 存储库。它需要通过网络浏览器在任何机器上工作,因此客户端需要的所有内容都在 jar 中。有什么方法可以从我的客户端应用程序的 jar 中加载rampart.mar 文件?

另一种可能性是使用 ConfigurationContextFactory.createConfigurationContextFromURIs 方法,但这需要我在服务器上创建一个 axis2+rampart 的在线存储库。有人知道这方面的好指南吗?我还是更喜欢把所有东西都打包在罐子里。

4

1 回答 1

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;
    }
}
于 2011-07-06T19:22:16.667 回答