0
votes

Alright I have a wsdl with web methods that I create stubs via axis2java with the following command:

wsdl2java -uri https://path/to/service?wsdl -p com.my.java.package

It generates all the required stubs but I am having a hard time actually using them. I have two URLs both HTTPS however one of them has message encryption with rampart. I have been able to get the more difficult message encrypted URL to work fine.

I initialize my encrypted stub like follows:

ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("repository", null);

NetWS_0Stub stub = new NetWS_0Stub(ctx, aEndPoint);
ServiceClient client = stub._getServiceClient();

Options options = new Options();
options.setTo(new EndpointReference(aEndPoint));
options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,  this.loadPolicy("repository/policy/HTTPS_Policy.xml"));
client.setOptions(options);
client.engageModule("rampart");

return stub;

For my non-encrypted (HTTPS ONLY) I have tried the above method of stub initializing as well as the following:

ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("repository", null);

NetWS_0Stub stub = new NetWS_0Stub(ctx, aEndPoint);
ServiceClient client = stub._getServiceClient();

Options options = new Options();
options.setTo(new EndpointReference(aEndPoint));
client.setOptions(options);

The plain HTTPS stub does not work. At best I get a soap header missing exception. I can however use these web methods via SOAPui. So I know the URL/WSDL/web methods are working great. I am more familiar with wsimport and not axis2.... axis2 seems much more difficult to do such a simple thing.

How am I supposed to setup the stub for calling a non-message encrypted web service? Why is axis2 such a pain to work with? Is it just a problem with me not understanding something. If SOAPui can immediately generate web requests/responses then I feel the axis2 tool should be able to do the same especially since the web methods were creating and accessed via axis2 in glassfish. I have not setup SOAPui with any keystore/truststore it just works when I give it the wsdl.

If anyone needs particular code samples let me know I am unsure what information would even help someone help me out.

1

1 Answers

0
votes

I found a solution and will share for any other unfortunate individuals who are working with axis2.

ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("repository", null);

NetWS_0Stub stub = new NetWS_0Stub(ctx, aEndPoint);
ServiceClient client = stub._getServiceClient();

Options options = new Options();
options.setTo(new EndpointReference(aEndPoint));
//Added chunking property:
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
client.setOptions(options);
//Engaged rampart module:
client.engageModule("rampart");

return stub;

Above is the magic combination that worked for me. Adding the rampart module back in it gave me a chunking exception and after adding that property regarding chunking it worked. I am not sure if this particular web service I was connecting to has special settings requiring the above config but it was very frustrating getting the perfect combination.