开发者

Problem creating Axis2 Rampart Client

I'm creating a web service using Axis2 which uses Rampart for authentication. In all the samples for Rampart, the client needs to have a client side repository for Axis2. Rampart is started on the client as follows:

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");

The method createConfigurationContextFromFileSystem needs a path to an Axis2 repo on the cli开发者_高级运维ent which has the rampart.mar file. It apparently needs a full absolute path, not a relative path.

However, I'm deploying my client with Java Web Start and I can't put a Axis2 repo on every machine that may need to run the client. It needs to work from any machine from a web browser so everything the client needs to be in the jar. Is there any way I can load the rampart.mar file from the jar of my client app?

Another possibility would be using the ConfigurationContextFactory.createConfigurationContextFromURIs method, but this would require me to create an online repo of axis2+rampart on the server. Anyone know of a good guide for this? I still would prefer to just package everything in the jar.


If you don't have a need for an Axis2 repository, which I've always found to be the case with Axis2 clients, then you can load a ConfigurationContext without a repository using the following (note the extra detail I add in code comments)...

//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;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜