Skip to content

Instantly share code, notes, and snippets.

@amusarra
Created October 31, 2012 08:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amusarra/3985944 to your computer and use it in GitHub Desktop.
Save amusarra/3985944 to your computer and use it in GitHub Desktop.
SugarCRM Community Edition 6.4 (v4 API) SOAP Client - Maven Test
amusarra-macbookpro:SugarCRMCE64v4APISOAPLibrary amusarra$ mvn test
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building SugarCRM Community Edition 6.4 (v4 API) SOAP Client 1.0.6-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ sugarcrmce-64-v4-soap-api ---
[INFO]
[INFO] --- cxf-codegen-plugin:2.5.2:wsdl2java (generate-sources) @ sugarcrmce-64-v4-soap-api ---
[INFO]
[INFO] --- build-helper-maven-plugin:1.7:add-source (add-source) @ sugarcrmce-64-v4-soap-api ---
[INFO] Source directory: /Users/amusarra/git/SugarCRMCE64v4APISOAPLibrary/target/generated/cxf added.
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ sugarcrmce-64-v4-soap-api ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ sugarcrmce-64-v4-soap-api ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ sugarcrmce-64-v4-soap-api ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ sugarcrmce-64-v4-soap-api ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ sugarcrmce-64-v4-soap-api ---
[INFO] Surefire report directory: /Users/amusarra/git/SugarCRMCE64v4APISOAPLibrary/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running it.shirus.labs.sugarcrm.client.soap.SimpleClientTest
#--------------------------------------------------------------#
# Invoking Server Info...
#--------------------------------------------------------------#
# Version: 6.5.0
# Flavor: CE
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Invoking login...
#--------------------------------------------------------------#
# Login Successfully for admin
# Your session Id: 5enefpkuuudk0ikl6ve42l6vq3
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Invoking Get Account Entry List...
# Total Count: 51
# Result Count: 3
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Account Entry ID: 4c120439-0fbc-f707-49cb-50200648cda1
# Account Field Name: id
# Account Field Value: 4c120439-0fbc-f707-49cb-50200648cda1
# Account Field Name: name
# Account Field Value: Hammer Group Inc
# Account Field Name: billing_address_city
# Account Field Value: Santa Monica
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Account Entry ID: 354bdaa4-28de-303c-bcd8-502006750df0
# Account Field Name: id
# Account Field Value: 354bdaa4-28de-303c-bcd8-502006750df0
# Account Field Name: name
# Account Field Value: Waverly Trading House
# Account Field Name: billing_address_city
# Account Field Value: Denver
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Account Entry ID: 647c2423-d235-cf76-e7f7-502006306b14
# Account Field Name: id
# Account Field Value: 647c2423-d235-cf76-e7f7-502006306b14
# Account Field Name: name
# Account Field Value: Southern Realty
# Account Field Name: billing_address_city
# Account Field Value: Salt Lake City
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Invoking Get Module List...
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Home
# Module Label:Home
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Accounts
# Module Label:Accounts
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Contacts
# Module Label:Contacts
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Opportunities
# Module Label:Opportunities
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Leads
# Module Label:Leads
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Calendar
# Module Label:Calendar
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Documents
# Module Label:Documents
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Emails
# Module Label:Emails
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Campaigns
# Module Label:Campaigns
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Calls
# Module Label:Calls
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Meetings
# Module Label:Meetings
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Tasks
# Module Label:Tasks
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Notes
# Module Label:Notes
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Cases
# Module Label:Cases
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Prospects
# Module Label:Targets
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:ProspectLists
# Module Label:Target Lists
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:KReports
# Module Label:K Reporter
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Administration
# Module Label:Administration
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Currencies
# Module Label:Currencies
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:CustomFields
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Connectors
# Module Label:Connectors
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Dropdown
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Dynamic
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:DynamicFields
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:DynamicLayout
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:EditCustomFields
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Help
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Import
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:MySettings
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:FieldsMetaData
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:UpgradeWizard
# Module Label:Upgrade Wizard
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Trackers
# Module Label:Trackers
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Employees
# Module Label:Employees
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Releases
# Module Label:Releases
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Sync
# Module Label:Sync
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Users
# Module Label:Users
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Versions
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:LabelEditor
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Roles
# Module Label:Roles
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:EmailMarketing
# Module Label:Email Marketing
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:OptimisticLock
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:TeamMemberships
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:TeamSets
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:TeamSetModule
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Audit
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:MailMerge
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:MergeRecords
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:EmailAddresses
# Module Label:Email Address
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:EmailText
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Schedulers
# Module Label:Schedulers
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Schedulers_jobs
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:EmailTemplates
# Module Label:Email Templates
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:CampaignTrackers
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:CampaignLog
# Module Label:Campaign Log
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:EmailMan
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Groups
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:InboundEmail
# Module Label:Inbound Email
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:ACLActions
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:ACLRoles
# Module Label:Roles
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:DocumentRevisions
# Module Label:Document Revisions
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:ProjectTask
# Module Label:Project Tasks
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:ACL
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Configurator
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:UserPreferences
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:SavedSearch
# Module Label:Saved Searches
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Studio
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:SugarFeed
# Module Label:Sugar Feed
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:EAPM
# Module Label:
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:OAuthKeys
# Module Label:OAuth Consumer Keys
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:OAuthTokens
# Module Label:OAuth Tokens
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Bugs
# Module Label:Bug Tracker
#--------------------------------------------------------------#
#--------------------------------------------------------------#
# Module Key:Project
# Module Label:Projects
#--------------------------------------------------------------#
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 13.284 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.492s
[INFO] Finished at: Wed Oct 31 09:49:47 CET 2012
[INFO] Final Memory: 7M/265M
[INFO] ------------------------------------------------------------------------
amusarra-macbookpro:SugarCRMCE64v4APISOAPLibrary amusarra$
/**
*
*/
package it.shirus.labs.sugarcrm.client.soap;
import static org.junit.Assert.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Properties;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.sugarcrm.sugarcrm.EntryList;
import com.sugarcrm.sugarcrm.EntryValue;
import com.sugarcrm.sugarcrm.GetEntryListResultVersion2;
import com.sugarcrm.sugarcrm.LinkNamesToFieldsArray;
import com.sugarcrm.sugarcrm.ModuleList;
import com.sugarcrm.sugarcrm.ModuleListEntry;
import com.sugarcrm.sugarcrm.NameValue;
import com.sugarcrm.sugarcrm.NameValueList;
import com.sugarcrm.sugarcrm.SelectFields;
import com.sugarcrm.sugarcrm.Sugarsoap;
import com.sugarcrm.sugarcrm.SugarsoapPortType;
import com.sugarcrm.sugarcrm.UserAuth;
/**
* @author amusarra
*
*/
public class SimpleClientTest {
private static final QName SERVICE_NAME = new QName(
"http://www.sugarcrm.com/sugarcrm", "sugarsoap");
private static final String APPLICATION_NAME = Class.class.getName();
private URL wsdlURL;
private String sessionID = null;
private Properties p = new Properties();
@Before
public void setUp() throws FileNotFoundException, IOException {
p.load((new ClassPathResource("SimpleClientTest.properties"))
.getInputStream());
}
@Test
public void simpleSugarCRMProcess() throws NoSuchAlgorithmException {
try {
wsdlURL = new URL(p.getProperty("sugarcrm.WSDL"));
} catch (MalformedURLException e) {
fail("WSDL Url failed: " + e.getMessage());
}
Sugarsoap ss = new Sugarsoap(wsdlURL, SERVICE_NAME);
SugarsoapPortType port = ss.getSugarsoapPort();
System.out
.println("#--------------------------------------------------------------#");
System.out.println("# Invoking Server Info...");
System.out
.println("#--------------------------------------------------------------#");
System.out.println("# Version: " + port.getServerInfo().getVersion());
System.out.println("# Flavor: " + port.getServerInfo().getFlavor());
assertEquals("Version", "6.5.0", port.getServerInfo().getVersion());
assertEquals("Flavor", "CE", port.getServerInfo().getFlavor());
System.out
.println("#--------------------------------------------------------------#");
/**
* Try to login on SugarCRM
*
* 1) Prepare a MD5 hash password 2) Prepare a User Auth object 3)
* Execute login
*/
{
System.out.println();
System.out
.println("#--------------------------------------------------------------#");
System.out.println("# Invoking login...");
System.out
.println("#--------------------------------------------------------------#");
// 1. Prepare a MD5 hash password
MessageDigest messageDiget = MessageDigest.getInstance("MD5");
messageDiget.update(p.getProperty("sugarcrm.password").getBytes());
// 2. Prepare a User Auth object
com.sugarcrm.sugarcrm.UserAuth _login_userAuth = new UserAuth();
_login_userAuth.setUserName(p.getProperty("sugarcrm.username"));
_login_userAuth.setPassword((new BigInteger(1, messageDiget
.digest())).toString(16));
java.lang.String _login_applicationName = APPLICATION_NAME;
com.sugarcrm.sugarcrm.NameValueList _login_nameValueList = new NameValueList();
try {
// 3. Execute login
com.sugarcrm.sugarcrm.EntryValue _login__return = port.login(
_login_userAuth, _login_applicationName,
_login_nameValueList);
System.out.println("# Login Successfully for "
+ p.getProperty("sugarcrm.username"));
System.out
.println("# Your session Id: " + _login__return.getId());
sessionID = _login__return.getId();
System.out
.println("#--------------------------------------------------------------#");
} catch (Exception e) {
fail("Login failed. Message: " + e.getMessage());
}
}
/**
* Try get entry list operation
*/
{
System.out.println();
System.out
.println("#--------------------------------------------------------------#");
System.out.println("# Invoking Get Account Entry List...");
try {
SelectFields selectFields = new SelectFields();
LinkNamesToFieldsArray linkNamesToFieldsArray = new LinkNamesToFieldsArray();
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
Element fieldId = doc.createElement("item");
fieldId.setTextContent("id");
Element fieldName = doc.createElement("item");
fieldName.setTextContent("name");
Element fieldBillingCity = doc.createElement("item");
fieldBillingCity.setTextContent("billing_address_city");
selectFields.setArrayType("xsd:string[]");
selectFields.getAny().add((Element) fieldId);
selectFields.getAny().add((Element) fieldName);
selectFields.getAny().add((Element) fieldBillingCity);
linkNamesToFieldsArray
.setArrayType("ns1:link_name_to_fields_array[]");
GetEntryListResultVersion2 resultList = port.getEntryList(
sessionID, "Accounts", "", "", 5, selectFields,
linkNamesToFieldsArray, 3, 0, false);
System.out.println("# Total Count: "
+ resultList.getTotalCount());
System.out.println("# Result Count: "
+ resultList.getResultCount());
System.out
.println("#--------------------------------------------------------------#");
EntryList entryList = resultList.getEntryList();
List<EntryValue> entryValue = entryList.getItem();
for (EntryValue entry : entryValue) {
System.out
.println("#--------------------------------------------------------------#");
NameValueList nameValueList = entry.getNameValueList();
List<NameValue> nameValueItem = nameValueList.getItem();
System.out.println("# Account Entry ID: " + entry.getId());
for (NameValue nameValue : nameValueItem) {
System.out.println("# Account Field Name: "
+ nameValue.getName());
System.out.println("# Account Field Value: "
+ nameValue.getValue());
}
System.out
.println("#--------------------------------------------------------------#");
}
} catch (Exception e) {
fail("Get Entry failed: " + e.getMessage());
}
}
/**
* Try get modules
*/
{
System.out.println();
System.out
.println("#--------------------------------------------------------------#");
System.out.println("# Invoking Get Module List...");
System.out
.println("#--------------------------------------------------------------#");
try {
ModuleList moduleList = port.getAvailableModules(sessionID, "");
List<ModuleListEntry> module = moduleList.getModules()
.getItem();
for (ModuleListEntry moduleListEntry : module) {
System.out
.println("#--------------------------------------------------------------#");
System.out.println("# Module Key:"
+ moduleListEntry.getModuleKey());
System.out.println("# Module Label:"
+ moduleListEntry.getModuleLabel());
System.out
.println("#--------------------------------------------------------------#");
}
} catch (Exception e) {
fail("Get Modules failed: " + e.getMessage());
}
}
}
}
sugarcrm.username=admin
sugarcrm.password=admin
sugarcrm.WSDL=http://sugarcrmpgsql-shiruslabs.rhcloud.com/service/v4/soap.php?wsdl&style=rpc&use=literal
@parideLetizia
Copy link

Salve Antonio,
ho un grosso problema nell'usare i web services esposti da Sugar. In particolare, uso Java e le classi generate con CXF sono state costruite a partire da un wsdl il cui style = document e lo use = literal.
Purtroppo quando cerco di contattare Sugar attraverso il metodo get_entry_list, seguendo il tuo esempio ottengo il seguente errore:
Unknown error in SOAP call: service died unexpectedly

Purtroppo non riesco a capirne il motivo. Seguo il tuo tutorial passo passo ma non riesco a contattare Sugar.
Sapresti darmi una mano?

Ti ringrazio infinitamente

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment