Difference between revisions of "Java Sending SMS via SOAP"

From SMS Wiki
Jump to: navigation, search
(New page: The process of sending an SMS using Java is fairly straightforward. The easiest setup is to use Eclipse with the XFire plugin. XFire is an opensource Java SOAP interface http://xfire.code...)
 
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The process of sending an SMS using Java is fairly straightforward.
+
The process of sending an SMS using Java is shown using Eclipse with the XFire plugin. XFire is an opensource Java SOAP interface [http://xfire.codehaus.org/ (download XFire)]
  
The easiest setup is to use Eclipse with the XFire plugin. XFire is an opensource Java SOAP interface http://xfire.codehaus.org/
+
* Once you have the plugin installed, add the XFire nature to your project by right clicking on the project and selecting "Add XFire Nature"
  
Once you have the plugin installed, add the XFire nature to your project by right clicking on the project and selecting "Add XFire Nature"
+
* Then, right click on the project and specify "New > Other...". At the bottom of the list should be an option labeled "Code generation from WSDL Document". Select this option and enter the following into the dialog presented:
  
Then, again, right click on the project and specify "New > Other...". At the bottom of the list should be an option labeled "Code generation from WSDL Document". Select this option and enter the following into the dialog presented:
+
WSDL: http://api.upsidewireless.com/soap/Authentication.asmx?WSDL
 
+
WSDL: http://api.upsidewireless.com/soap/Authentication.asmx?WSDL
+
 
Output Directory: <Your source directory>
 
Output Directory: <Your source directory>
Package: <Leave Blank> (By leaving this field blank, the default package of the service will be used)
 
  
Click Finish and it will build the necessary source files. Repeat the process for: http://api.upsidewireless.com/soap/SMS.asmx?WSDL
+
Package: <Leave Blank> (By leaving this field blank, the default package of the service will be used)
  
Now that you have both sets of XFire client code generated (one for authentication and the other for sending SMS), now it is time to make a call. The essence of making the call is the following 3 lines of code (it can be reduce down to a single line of code, but that would make debugging difficult):
+
Click Finish and it will build the necessary source files. Repeat the process for: http://api.upsidewireless.com/soap/SMS.asmx?WSDL
 +
 
 +
* Now that you have both sets of XFire client code generated (one for authentication and the other for sending SMS), now it is time to make a call. The essence of making the call is the following 3 lines of code (it can be reduce down to a single line of code, but that would make debugging difficult):
 +
 
 +
<source lang="java">
  
 
SMSClient client = new SMSClient();
 
SMSClient client = new SMSClient();
 +
 
SMSSoap soap = client.getSMSSoap();
 
SMSSoap soap = client.getSMSSoap();
 +
 
soap.send_Plain(token, signature, "+15557779999", "Hello", SmsEncoding.SEVEN);
 
soap.send_Plain(token, signature, "+15557779999", "Hello", SmsEncoding.SEVEN);
 +
 +
</source>
 +
 +
 +
Here is the one liner:
 +
<source lang="java">
 +
new SMSClient().getSMSSoap().send_Plain(token, signature, "+15557779999", "Hello", SmsEncoding.SEVEN);
 +
</source>
 +
 +
If you are sending URL in the text of your message please note that special characters like "-", "+", "/" and others MUST be replaced with their safe equivalents (for example %2f).
 +
 +
A complete "Main" style application would look like:
 +
 +
<source lang="java">
 +
import org.codehaus.xfire.XFireRuntimeException;
 +
 +
import com.upsidewireless.webservice.authentication.AuthenticationClient;
 +
 +
import com.upsidewireless.webservice.authentication.AuthenticationParameters;
 +
 +
import com.upsidewireless.webservice.authentication.AuthenticationSoap;
 +
 +
import com.upsidewireless.webservice.sms.SMSClient;
 +
 +
import com.upsidewireless.webservice.sms.SMSSoap;
 +
 +
import com.upsidewireless.webservice.sms.SmsEncoding;
 +
 +
 +
/**
 +
* Start of your code
 +
*
 +
*/
 +
public class SendSms {
 +
 +
/**
 +
* @param args
 +
*/
 +
 +
public static void main(String[] args) {
 +
 +
/***********************************************************************
 +
 +
* Execute the retrieval of the token and signature only once.
 +
 +
* Preferably from the web interface and store them as Constants
 +
**********************************************************************/
 +
 +
AuthenticationClient authclient = new AuthenticationClient();
 +
 +
AuthenticationSoap authsoap = authclient.getAuthenticationSoap();
 +
 +
AuthenticationParameters authparams = authsoap.getParameters("YourUserName", "YourPassword");
 +
 +
String token = authparams.getToken();
 +
 +
String signature = authparams.getSignature();
 +
 +
/***********************************************************************
 +
 +
* We now have the credentials, now build a SOAP client and make the call.
 +
**********************************************************************/
 +
 +
SMSClient client = new SMSClient();
 +
 +
SMSSoap soap = client.getSMSSoap();
 +
 +
soap.send_Plain(token, signature, "+15557779999", "Hello", SmsEncoding.SEVEN);
 +
 +
}
 +
 +
}
 +
 +
</source>
 +
 +
----
 +
[[APIs | back]]

Latest revision as of 12:05, 6 December 2011

The process of sending an SMS using Java is shown using Eclipse with the XFire plugin. XFire is an opensource Java SOAP interface (download XFire)

  • Once you have the plugin installed, add the XFire nature to your project by right clicking on the project and selecting "Add XFire Nature"
  • Then, right click on the project and specify "New > Other...". At the bottom of the list should be an option labeled "Code generation from WSDL Document". Select this option and enter the following into the dialog presented:
WSDL: http://api.upsidewireless.com/soap/Authentication.asmx?WSDL

Output Directory: <Your source directory>

Package: <Leave Blank> (By leaving this field blank, the default package of the service will be used)
Click Finish and it will build the necessary source files. Repeat the process for: http://api.upsidewireless.com/soap/SMS.asmx?WSDL
  • Now that you have both sets of XFire client code generated (one for authentication and the other for sending SMS), now it is time to make a call. The essence of making the call is the following 3 lines of code (it can be reduce down to a single line of code, but that would make debugging difficult):
SMSClient client = new SMSClient();
 
SMSSoap soap = client.getSMSSoap();
 
soap.send_Plain(token, signature, "+15557779999", "Hello", SmsEncoding.SEVEN);


Here is the one liner:

new SMSClient().getSMSSoap().send_Plain(token, signature, "+15557779999", "Hello", SmsEncoding.SEVEN);

If you are sending URL in the text of your message please note that special characters like "-", "+", "/" and others MUST be replaced with their safe equivalents (for example %2f).

A complete "Main" style application would look like:

import org.codehaus.xfire.XFireRuntimeException;
 
import com.upsidewireless.webservice.authentication.AuthenticationClient;
 
import com.upsidewireless.webservice.authentication.AuthenticationParameters;
 
import com.upsidewireless.webservice.authentication.AuthenticationSoap;
 
import com.upsidewireless.webservice.sms.SMSClient;
 
import com.upsidewireless.webservice.sms.SMSSoap;
 
import com.upsidewireless.webservice.sms.SmsEncoding;
 
 
/**
 * Start of your code
 * 
 */
public class SendSms {
 
	/**
	 * @param args
	 */
 
	public static void main(String[] args) {
 
/***********************************************************************
 
		 * Execute the retrieval of the token and signature only once.
 
		 * Preferably from the web interface and store them as Constants
		 **********************************************************************/
 
		AuthenticationClient authclient = new AuthenticationClient();
 
		AuthenticationSoap authsoap = authclient.getAuthenticationSoap();
 
		AuthenticationParameters authparams = authsoap.getParameters("YourUserName", "YourPassword");
 
		String token = authparams.getToken();
 
		String signature = authparams.getSignature();
 
		/***********************************************************************
 
* We now have the credentials, now build a SOAP client and make the call.
		 **********************************************************************/
 
		SMSClient client = new SMSClient();
 
		SMSSoap soap = client.getSMSSoap();
 
		soap.send_Plain(token, signature, "+15557779999", "Hello", SmsEncoding.SEVEN);
 
	}
 
}

back