|
| Step 1: Setup your development environment | |
|
We will be using
| |
| | |
| Step 2: Authentication: ( https://www.ebsuite.com/cxf/SessionAuthenticatorAPI?wsdl ) | |
| 2A> Generating Java Classes from WSDL | |
|
C:> WSDL2Java https://www.ebsuite.com/cxf/SessionAuthenticatorAPI?wsdl This should generate several web service classes in your file system. | |
Using WSDL2Java to generate Stub Classes
| |
Result Folder
| |
| 2B> Using these classes to authenticate:
Code Sample 1: SimpleTest1 (com.ebsuite.common.tutorial)
| |
package com.ebsuite.common.tutorial;
import java.io.*;
import java.util.*;
import com.ebsuite.login.SessionAuthenticatorAPIServiceSoapBindingStub;
public class SimpleTest1 {
public static void doTest() throws Exception
{
java.net.URL _endpoint = new java.net.URL( "https://www.ebsuite.com/cxf/SessionAuthenticatorAPI" );
SessionAuthenticatorAPIServiceSoapBindingStub _stub =
new SessionAuthenticatorAPIServiceSoapBindingStub(_endpoint, new org.apache.axis.client.Service() );
System.out.println( "[" + _stub.simpleAuthenticate( "******", "*************************" ) + "]" );
}
public static void main ( String[] params )
{
try { doTest(); } catch (Exception e) { e.printStackTrace(); }
}
}
| |
| Compile, Run, and Result If success, the result should start with "[SESSIONID:" . Otherwise it should display the error message.
| |
Alternatively, we can use loginAuthenticate(company_name,user_name,password) to authenticate.
package com.ebsuite.common.tutorial;
import java.io.*;
import java.util.*;
import com.ebsuite.login.SessionAuthenticatorAPIServiceSoapBindingStub;
public class SimpleTest1 {
public static void doTest() throws Exception
{
java.net.URL _endpoint = new java.net.URL( "https://www.ebsuite.com/cxf/SessionAuthenticatorAPI" );
SessionAuthenticatorAPIServiceSoapBindingStub _stub =
new SessionAuthenticatorAPIServiceSoapBindingStub(_endpoint, new org.apache.axis.client.Service() );
System.out.println( "[" + _stub.loginAuthenticate( "*****", "*****", "*****" ) + "]" );
}
public static void main ( String[] params )
{
try { doTest(); } catch (Exception e) { e.printStackTrace(); }
}
}
| |
| | |
| Step 3: Post Authentication: Processing Opportunity Records. ( https://www.ebsuite.com/cxf/OppAPI?wsdl ) | |
| 3A> Generating Java Classes from WSDL | |
|
C:> WSDL2Java https://www.ebsuite.com/cxf/OppAPI?wsdl This should generate several web service classes in your file system. | |
Using WSDL2Java to generate Stub Classes
| |
Result Folder
| |
| 3B> Using these classes to process Opportunity Records:
Code Sample 2: OppTest2 (com.ebsuite.common.tutorial), search opportunities
| |
package com.ebsuite.common.tutorial;
import java.io.*;
import java.util.*;
import com.ebsuite.login.SessionAuthenticatorAPIServiceSoapBindingStub;
import com.ebsuite.sales.api.OppAPIServiceSoapBindingStub;
import com.ebsuite.sales.api.OpportunityList;
import com.ebsuite.sales.api.Opportunity;
public class OppTest2 {
public static void doTest() throws Exception
{
java.net.URL _endpoint = new java.net.URL( "https://www.ebsuite.com/cxf/SessionAuthenticatorAPI" );
SessionAuthenticatorAPIServiceSoapBindingStub _stub =
new SessionAuthenticatorAPIServiceSoapBindingStub(_endpoint, new org.apache.axis.client.Service() );
String authResult = _stub.loginAuthenticate( "****", "****", "****" );
System.out.println( "[" + authResult + "]" );
if ( authResult.startsWith("SESSIONID:") )
{
String sessId = authResult.substring( 10 );
OppAPIServiceSoapBindingStub oppApiStub = new OppAPIServiceSoapBindingStub(
new java.net.URL( "https://www.ebsuite.com/cxf/OppAPI" ), new org.apache.axis.client.Service() );
OpportunityList oppList = oppApiStub.searchOpportunities( sessId, "William" );
Opportunity[] opps = oppList.getList();
for (int i=0; i < opps.length; i++)
{
System.out.println( " ( " + opps[i].getOppNumber() + " ) " + opps[i].getOppName() );
}
}
}
public static void main ( String[] params )
{
try { doTest(); } catch (Exception e) { e.printStackTrace(); }
}
}
| |
| Compile, Run, and Result In this example, there are 5 records returned for search result "William"
| |
| 3C> More Sample Code: Save one Opportunity Data:
Code Sample 3: OppTest3 (com.ebsuite.common.tutorial)
| |
package com.ebsuite.common.tutorial;
import java.io.*;
import java.util.*;
import com.ebsuite.login.SessionAuthenticatorAPIServiceSoapBindingStub;
import com.ebsuite.sales.api.OppAPIServiceSoapBindingStub;
import com.ebsuite.sales.api.Opportunity;
import com.ebsuite.sales.api.BaseCustomFieldData;
public class OppTest3 {
public static void doTest() throws Exception
{
java.net.URL _endpoint = new java.net.URL( "https://www.ebsuite.com/cxf/SessionAuthenticatorAPI" );
SessionAuthenticatorAPIServiceSoapBindingStub _stub =
new SessionAuthenticatorAPIServiceSoapBindingStub(_endpoint, new org.apache.axis.client.Service() );
String authResult = _stub.loginAuthenticate( "***", "****", "***" );
System.out.println( "[" + authResult + "]" );
if ( authResult.startsWith("SESSIONID:") )
{
String sessId = authResult.substring( 10 );
OppAPIServiceSoapBindingStub oppApiStub = new OppAPIServiceSoapBindingStub(
new java.net.URL( "https://www.ebsuite.com/cxf/OppAPI" ), new org.apache.axis.client.Service() );
System.out.println( " Now attempting to create a new Opportunity." );
Opportunity o = new Opportunity();
o.setOppId( -1 ); // indicating new record
o.setOppName( "Web Service API Test " ); // this should generate a unique name
o.setCustomerId( 258621 ); // Please use a real, valid customer id.
BaseCustomFieldData[] cfdatas = new BaseCustomFieldData[1];
cfdatas[0] = new BaseCustomFieldData();
cfdatas[0].setCfDataId( -1 ); // indicating new record
cfdatas[0].setFieldDefinitionId(-1);
cfdatas[0].setFieldDefinition( "Rental City" );
cfdatas[0].setCfDataValue( "San Francisco" );
cfdatas[0].setOlLastUpdateDate( Calendar.getInstance() ); // touch the date stamp, so the server know to process this record
o.setCustomFields( cfdatas );
Opportunity result = oppApiStub.saveOpportunityRecord( sessId, o );
System.out.println( "\n\n --- saveOppRecord() --- " );
if ( result != null && result.getOppId() > 0 )
{
System.out.println( " Record saved successfully. New record ID ="+ result.getOppId() );
System.out.println( " Calling retrieve detail again. " );
Opportunity refresh = oppApiStub.getOpportunityDetail( sessId, result.getOppId() );
System.out.println( refresh.getOppName() );
}
else
{
System.out.println( " Transaction Failed. " );
if ( result != null )
System.out.println( " Msg = "+ result.getErrorMsg() );
}
}
}
public static void main ( String[] params )
{
try { doTest(); } catch (Exception e) { e.printStackTrace(); }
}
}
| |
| Compile, Run, and Result Check your Opportunity online. You should see the new data online.
|