【问题标题】:Problem creating Axis2 Rampart Client创建 Axis2 Rampart 客户端时出现问题
【发布时间】:2011-06-28 08:54:06
【问题描述】:

我正在使用 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 的在线存储库。有人知道这方面的好指南吗?我还是宁愿把所有东西都打包在罐子里。

【问题讨论】:

    标签: web-services axis2 rampart


    【解决方案1】:

    如果您不需要 Axis2 存储库,我一直发现 Axis2 客户端就是这种情况,那么您可以使用以下方法加载没有存储库的 ConfigurationContext(请注意我添加的额外细节代码 cmets)...

    //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-05-23
      • 1970-01-01
      • 1970-01-01
      • 2011-03-17
      • 1970-01-01
      • 2014-04-17
      • 1970-01-01
      • 2013-08-19
      • 2011-09-21
      相关资源
      最近更新 更多