aspose file tools*
The moose likes Web Services and the fly likes java soap client to connect to sugarCRM server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "java soap client to connect to sugarCRM server" Watch "java soap client to connect to sugarCRM server" New topic
Author

java soap client to connect to sugarCRM server

Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Hello,
my Project involve writing a openoffice sugarCRM plugin .so i need to make an interop communication between OO and sugarCRM probably via webservices.

i thought a starting point is to write a java client to connect to sugarrcm server and query the sugarCRM instance for some valuable data.

below is an example of soap params to send to sugarcrm server so to get available sugarCRM modules .what i need is to write a java client to connect to sugarcrm using below params and get back the results.


can someone give me hint (or java code) to write this soap client?
many thanks.

Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
Find the WSDL file (sugarcrm.wsdl) and use it to generate a static client stub with the WSDL-to-Java generator of the SOAP web services toolkit of your choice.

"3. WSDL2Java: Generate the Server-side Wrapper Code and Stubs For Easy Client Access" from Creating Web Services with Apache Axis shows an example of the process with Axis 1.x.

Because SugarCRM chose to use a RPC/encoded messaging SOAP endpoint your choice of toolkit will be limited because RPC/encoded messaging is NOT supported by the newer toolkits like Apache CXF or Axis2. So it wouldn't be surprising if a future version of SugarCRM might change to a different web services interface (document/literal messaging if they stick with SOAP).

Alternately the WSDL will give you enough information to write a SAAJ client � though I wouldn�t recommend that with RPC/encoded.


"Don't succumb to the false authority of a tool or model. There is no substitute for thinking."
Andy Hunt, Pragmatic Thinking & Learning: Refactor Your Wetware p.41
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

thank you for replying .i appreciate your help.

i wrote a soap client to talk to my local sugarcrm server.

i just added soap.jar and mail.jar to my classpath & this simple code :



it seems my client don't work perfectly for all methods of sugar webservice

when running above java program ,i got this exception:


i don't know what i'm doing wrong & would appreciate if you guide me.

i know sugar wdsl file url. if i use WSDL2Java to generate my java stub classes , how can i invoke the web service via these generated classes & how to send requests and receive responses from sugar ?

thanks.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
Please do not write any new code that depends on Apache SOAP (org.apache.soap) - that is even more ancient than Axis 1.x (org.apache.axis).

Originally posted by othman El Moulat:
if i use WSDL2Java to generate my java stub classes , how can i invoke the web service via these generated classes & how to send requests and receive responses from sugar?


That is detailed in the link I gave you; look under "3. WSDL2Java: Generate the Server-side Wrapper Code and Stubs For Easy Client Access" and later in "6. Client: Write a Client That Uses the Generated Stubs to Easily Access the Web Service". (Even that article dates back to 2002!!!)

For http://demo.sugarcrm.com/sugarcrm/soap.php?wsdl WSDL2Java creates the classes necessary for the client. You use the SugarsoapLocator to obtain an instance of the SugarsoapPortType through getSugarsoapPort(). On the SugarsoapPortType instance you can then call methods like get_available_modules(); WSDL2Java creates classes like Module_list and Error_value for you.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

thanks for the helpful reply : i managed to generate the stub clients and here is my Test java class :

i now can get a reference to sugar soap web service & i have a plenty of remote sugar methods available for me to call.
the first method i want to call is login(User_auth user_auth, String application_name);

i kow i have to call :

my questions:
1) what wsdl file i need to use (i used the demo one yuu gave me in your post).is the wsdl file fixed for a given web service or does it depends on my local sugar server ?
2) do i need to provide real 'password' string or use md5('password')? if yes should i use some java md5 library ?
3) what 'application_name' refer to in login method?
4) is it mandatory to login to sugar before calling any soap method ? or just create a session(username,password) and use that session String as param to suguarsoap methods ?


for my test code above ,I'm not getting the list of modules though .I'm sure there exist one module on my sugar2 server. but i can't get any.

thanks for your further assistance.

othman.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

this code :


gives me this result :

can you help on this ?
thanks
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
I have no knowledge of SugarCRM.

Maybe this will help you: SOAP Intro and Practical Examples

Originally posted by othman El Moulat:
1) what wsdl file i need to use (i used the demo one yuu gave me in your post).is the wsdl file fixed for a given web service or does it depends on my local sugar server ?


To be on the safe side I would use the WSDL on your local sugar server. At the very least your local server version may be different from the version of the demo and they could expose a different SOAP API. It is conceivable that the SOAP API could change based on the configuration of the server - however I doubt that this is the case here.


2) do i need to provide real 'password' string or use md5('password')? if yes should i use some java md5 library ?


As you have already found out and as the SOAP intro shows you need to send the MD5 hash.

3) what 'application_name' refer to in login method?

I presume that you can configure the SugarRCM server to support multiple applications at once. I have no idea what the actually means. The application name could serve as an alias for a database that the server can access, or it could refer to one of many applications configured inside of SugarRCM; it may simply identify the accessing application to SugarRCM. The PHP SOAP samples seem to treat it as an optional parameter.

4) is it mandatory to login to sugar before calling any soap method ? or just create a session(username,password) and use that session String as param to suguarsoap methods ?

The samples suggest that you need to login first. However the application name seems to be only needed in some cases. I noted however that you specified "5.0.0RC" in the version slot.

This states: "parameter 3: string:version - this is the version of soap you are expecting"

The values "0.1" and "1" used in the samples don't make any sense there are only SOAP 1.1 and 1.2 in use (and "1.1" is the one you want)

One avenue to pursue is to see if you can get those PHP SOAP samples to work. If you have trouble getting the Java equivalent to work, use TCPMon (Tutorial) to intercept the successful PHP generated requests and compare them to the request generated by the failing Java code. The differences may give you a clue as to what is going wrong.
[ December 14, 2007: Message edited by: Peer Reynders ]
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

thank you much.your reply was very helpful

i managed to get it work now & I'm retrieving the sugarcrm modules .

thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java soap client to connect to sugarCRM server
 
Similar Threads
error after(?) deploying a webservice
raw xml as the payload
what should be the serializer for this ?
reading soap-envelop messages
WSDL: Is use=encoded alowed?