• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 798
  • Last Modified:

Apache Axis2 Java client to access Bronto SOAP WSDL

I've downloaded Apache Axis2, using the following link:
http://archive.apache.org/dist/ws/axis2/1_4_1/axis2-1.4.1-bin.zip

Then I used the following command to generate java classes:
wsdl2java.sh -uri https://api.bronto.com/v4?wsdl
total generated src:
BrontoSoapApiImplServiceStub.java
BrontoSoapApiImplServiceCallbackHandler.java
ApiExceptionException0.java

I was able to login with help using the following.
BrontoSoapApiImplServiceStub stub;

// Get the stub...

LoginE loginE = new LoginE();
Login login = new Login();

login.setApiToken("your token here");
loginE.setLogin(login);

// Call the web service; login
stub.login(loginE);

Open in new window


Now I try to addContacts, and needs SessionHeaderE, but I can't seem to link login to the sessionId, the following code is not right. I'm imaging after login, I should be able to get some session info. But I can't seem to find.
SessionHeader sessionHeader = new SessionHeader();
sessionHeader.setSessionId(param)  // I don't know how to get sessionId from login info
SessionHeaderE sessionHeaderE = new SessionHeaderE();
sessionHeaderE.setSessionHeader(sessionHeader);

Open in new window


By the way, this is my first time working with Axis. Not sure what's the best way to approach the problem.
0
xiaoyunwu
Asked:
xiaoyunwu
  • 2
  • 2
1 Solution
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
You are correct in that what the login call returns is the session information, you just have to dig a little to find the id. But you should just be able to follow the types that Axis has created, from LoginResponseE -> LoginResponse -> _return. Change the login call to this...

String sessionId = stub.login(loginE).getLoginResponse().get_return();

Open in new window

Then you can use the sessionId for subsequent calls.
0
 
xiaoyunwuAuthor Commented:
Hi mccarl,

This is so helpful. I used your method and it worked perfectly. I was able to addContacts to Bronto now.

One question: BrontoSoapApiImplServiceStub.java is so long and there're more than 200,000 lines in it. How did you know loginResponse.get_return() return the sessionId? Is it because it returned String?

When you say: "follow the types that Axis has created", is that mean get_return() returns String and sessionId is a String, and we think login should have sessionId information, so you guessed get_return() will return sessionId? I wanted to know how I can get all these myself in the future.

Thanks a lot for your help!!!
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Ok, 2 main points to this...

1) In response to your questions above... Well, firstly, I started with the API documentation which I found here, http://community.bronto.com/api/v4, and if you look at the 'Overview' section and in that the 'How to login' section, the text states the the login function returns the sessionId. So now I know where to start. (BTW, I think the code samples it gives is for a different version of Axis, see below). Then the use of a good IDE helps a lot. I use Eclipse, and basically, I just found the login() method by using the find function. This shows that it returns an object of type 'LoginResponseE' (and know the good part) and you can just control-click on LoginResponseE and Eclipse takes you straight to the definition of that type. In that type you see that it is just a holder for a 'LoginResponse' type which you receive via the getLoginResponse() method, so again, control-click that type to take you to it's definition, and it is just a holder for a String which you receive via get_return() method call. And since lines up with the text of the documentation, I assumed it was your sessionId.

2) As I mentioned above, the code samples look a lot cleaner than you have needed to do. I looked into this further and it turns out that Apache Axis (as opposed to Axis2) handles all this a much different way. If you are able to use the older Axis, you might find that it can make your life easier, and give you the ability to follow the code samples more closely. I found an axis-1_4 here, http://www.apache.org/dyn/closer.cgi/ws/axis/1_4, and to run WSDL2Java you have to invoke it differently, like this...
C:\Program Files (x86)\Java\axis-1_4>java -cp lib\axis.jar;lib\commons-discovery-0.2.jar;lib\commons-logging-1.0.4.jar;lib\jaxrpc.jar;lib\saaj.jar;lib\wsdl4j-1.5.1.jar org.apache.axis.wsdl.WSDL2Java https://api.bronto.com/v4?wsdl

Open in new window

0
 
xiaoyunwuAuthor Commented:
mccarl, Thank you so much for detailed information. I really learned a lot!
0

Featured Post

When ransomware hits your clients, what do you do?

MSPs: Endpoint security isn’t enough to prevent ransomware.
As the impact and severity of crypto ransomware attacks has grown, Webroot fought back, not just by building a next-gen endpoint solution capable of preventing ransomware attacks but also by being a thought leader.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now