I'm in the process of setting up a web service client using Axis2 with XML beans. My code is exiting my calculateTest function without throwing an exception. If you look at my code below, the code exits at the line "AuthHeader authHeader = authHeaderDocument.addNewAuthHeader();"
public class ClientTest {
private static final int IDLE_CONNECTION_TIME = 0;
private ServiceStub serviceStub;
private MultiThreadedHttpConnectionManager connectionManager;
public ServiceStub getServiceStub() {
return serviceStub;
}
public void setServiceStub(ServiceStub serviceStub) {
this.serviceStub = serviceStub;
}
public static void main(String[] args) {
try {
System.out.println("STARTING");
ClientTest a = new ClientTest();
a.initServiceClient("https://XXXXXXX.asmx?WSDL");
a.calculateTest();
System.out.println("FINISHED");
} catch (Exception e) {
e.printStackTrace();
}
}
public void initServiceClient(String targetEndpoint) throws Exception {
try {
org.apache.axis2.context.ConfigurationContext myConfigContext = org.apache.axis2.context.ConfigurationContextFactory.createDefaultConfigurationContext();
this.connectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setStaleCheckingEnabled(true);
params.setDefaultMaxConnectionsPerHost(100);
this.connectionManager.setParams(params);
HttpClient httpClient = new HttpClient(this.connectionManager);
myConfigContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
myConfigContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE);
if(targetEndpoint != null){
serviceStub = new DACALCServiceStub(myConfigContext,targetEndpoint);
}else{
serviceStub = new DACALCServiceStub(myConfigContext);
}
ServiceClient sc = serviceStub._getServiceClient();
Options options = sc.getOptions();
options.setProperty(HTTPConstants.SO_TIMEOUT, 30000);
options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, 30000);
options.setProperty(HTTPConstants.AUTO_RELEASE_CONNECTION, true);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public String calculateTest() throws Exception {
System.out.println("Inside calculateTest");
String output = null;
try {
System.out.println("1.");
String authenticationUsername = "XXXX";
String authenticationPassword = "XXXX";
String errorMsg = "";
System.out.println("1a.");
AuthHeaderDocument authHeaderDocument = AuthHeaderDocument.Factory.newInstance();
System.out.println("1a1.");
AuthHeader authHeader = authHeaderDocument.addNewAuthHeader();
System.out.println("1a2.");
authHeader.setUserName(authenticationUsername);
System.out.println("1a3.");
authHeader.setPassword(authenticationPassword);
System.out.println("1a4.");
authHeader.setErrorMessage(errorMsg);
System.out.println("1b.");
} catch (Exception ex) {
ex.printStackTrace();
} finally {
serviceStub._getServiceClient().cleanupTransport();
this.connectionManager.closeIdleConnections(IDLE_CONNECTION_TIME);
return output;
}
}
}
The output I'm seeing is:
STARTING
Inside calculateTest
1.
1a.
FINISHED
No exceptions are thrown. Why would the code be silently failing on this line?
I removed the try/catch in calculateTest and an exception was thrown (strange how it wasn't being caught by the generic Exception handler). It turns out that I wasn't including some required files in my resources directory. Once I added that, everything worked.