-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSynchronousCallExample.java
More file actions
78 lines (60 loc) · 2.59 KB
/
SynchronousCallExample.java
File metadata and controls
78 lines (60 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import at.sms.business.sdk.client.impl.DefaultSmsClient;
import at.sms.business.sdk.domain.TextMessage;
import at.sms.business.sdk.exception.ApiException;
import at.sms.business.sdk.exception.AuthorizationFailedException;
import at.sms.business.sdk.exception.HttpConnectionException;
import at.sms.business.sdk.exception.ParameterValidationException;
/**
* This is a simple synchronous call to the sdk.
*
* @author Sebastian Wilhelm
*
*/
public class SynchronousCallExample {
public void test() {
try {
// The server-url, the username and password of the websms-account has to be
// provided to constructor to get it working. If you don't own websms-account
// the registration-url is http://websms.com/anmeldung
DefaultSmsClient smsClient = new DefaultSmsClient("your websms-username", "your password",
"https://api.websms.com/");
// Insert the recipients-number ( international number format ) you want
// to text to.
long[] recipients = new long[] { /* e.g, 43123456789L */ };
// The content of the message.
String messageContent = "Hello World!";
// A Text-Message-Object with the only mandatory parameters has to be created.
TextMessage textMessage = new TextMessage(recipients,messageContent);
// Max sms per message shows that just one sms will be send. This is a
// security parameter, that will specifies an upper limit for to be send sms.
// The tutorial on the website (http://websms.com/entwickler) will give
// further explanation about this topic.
int maxSmsPerMessage = 1;
// If test = true, it's just a test. No real sms will be send.
boolean test = false;
// The actual call of the SmsClient. Returns a statuscode if
// successful, throws an exception if something went wrong.
int statuscode = smsClient.send(textMessage, maxSmsPerMessage, test);
if (statuscode == 2000) {
System.out.println("Message successfully transferred");
}
} catch (ApiException e) {
// This exception delivers a status-code in the message.
e.printStackTrace();
} catch (ParameterValidationException e) {
// A parameter was invalid. No request was made.
e.printStackTrace();
} catch (AuthorizationFailedException e) {
System.err
.println("The username and password has to be changed to your websms-account-credentials in the source-code.");
} catch (HttpConnectionException e) {
// No server was found. Adjust the url provided as
// constructor-argument for the SmsClient.
e.printStackTrace();
}
}
public static void main(String[] args) {
SynchronousCallExample example = new SynchronousCallExample();
example.test();
}
}