twilio / twilio-java Goto Github PK
View Code? Open in Web Editor NEWA Java library for communicating with the Twilio REST API and generating TwiML.
License: MIT License
A Java library for communicating with the Twilio REST API and generating TwiML.
License: MIT License
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
AccountList accountList = client.getAccounts();
for (Account account : accountList) {
System.out.println(account.getFriendlyName() + " " + account.getSid());
}
When iterating through the account list resource with the snippet above, Account.getSid() returns the requestAccountSid instead of account.getProperty("sid").
class: IncomingPhoneNumber
method: getVoiceApplicaitonSid()
... wrong! getVoiceApplicationSid()
Not sure if it occurs elsewhere, just thought I'd point it out.
Currently, if you accidentally pass in a null for the sid in the constructor of a Resource, e.g. Call and try to do call.getSid() for example, it will fail with a StackOverflow exception due to a null property indicating the need to load the property. And the load in its turn is referencing getResourceLocation which calls getSid which calls getProperty which call load() which calls getResourceLocation etc...
would be nice to have, although i am working on adding these to the API documentation.
I'm trying to reply to incoming SMS messages, and I'm using the SMS verb.
The constructor for SMS passes the body directly to the body field in the Verb base class. The toXML() on the base Verb class looks like this:
public String toXML(){
String xml = "<" + this.tag;
for (String key : attributes.keySet()) {
xml += " " + key + "=\"" + attributes.get(key) + "\"";
}
xml += ">";
if(this.body != null)
xml += this.body;
for (Verb child : children){
xml += child.toXML();
}
return xml += "</" + this.tag + ">";
}
This doesn't escape the body element at all. Here is a simple test case:
TwiMLResponse twiml = new TwiMLResponse();
Sms sms = new Sms("I enjoy peanut butter & jelly");
twiml.append(sms);
System.out.println(twiml.toXML());
That produces the following output:
<Response><Sms>I enjoy peanut butter & jelly</Sms></Response>
I expected:
<Response><Sms>I enjoy peanut butter & jelly</Sms></Response>
It's not escaping the string passed it. I think the principal of least surprise would suggest that the string be automatically be escaped. At the least an alternate constructor could be provided which would automatically escape the content.
The example only exposes getAvailablePhoneNumbers()
Support for the (secondary verb) is not present.
It is missing from TwiMLResponse.java
Reference :
http://www.twilio.com/docs/api/twiml/pause
It'll be awesome if you can put this library in a maven repository.
Thanks.
Probably my fault, but when I try to update a phone number, I get an "Authenticate" error. I can get the call to work in APIGEE. I'm trying to update a number's URLs, and said number belongs to a subaccount. I authenticate the client with the master account, then ask for numbers for the subaccount. I even tried to add the AccountSid parameter manually (which is the subaccount's sid?). Do you see what I'm doing wrong? Thanks!
/* Top level account is needed for this */
TwilioRestClient client = new TwilioRestClient(
Credentials.TWILIO_MASTER_ACCOUNT_SID, Credentials.TWILIO_MASTER_AUTH_TOKEN);
Account TwilioSubAccount = client.getAccount(Credentials.TWILIO_SUBACCOUNT_SID);
IncomingPhoneNumberList list = TwilioSubAccount.getIncomingPhoneNumbers();
String sid = null;
for (IncomingPhoneNumber phoneNumber : list) {
if (phoneNumber.getPhoneNumber().equals(number)) {
Logger.info("Found matching number for subaccount, it's SID is: "
+ phoneNumber.getSid());
Logger.info("Number we found: " + phoneNumber.getPhoneNumber());
Logger.info("Number voice url (current): "
+ phoneNumber.getVoiceUrl());
sid = phoneNumber.getSid();
}
}
IncomingPhoneNumber phoneNumber = new IncomingPhoneNumber(client,
Credentials.TWILIO_SUBACCOUNT_SID);
Map<String, String> params = new HashMap<String, String>();
params.put("AccountSid", Credentials.TWILIO_SUBACCOUNT_SID);
params.put("VoiceUrl", "my new url");
params.put("VoiceMethod", "GET");
params.put("StatusCallback", "my new url");
params.put("StatusCallbackMethod", "GET");
try {
phoneNumber.update(params);
Logger.info("Updated phone number successfully");
} catch (TwilioRestException e1) {
Logger.info("Error updating phone number");
e1.printStackTrace();
return false;
}
return true;
AppEngineClientConnection.java relies on the default URLFetchService timeout, which is 5 seconds as documented here:
https://developers.google.com/appengine/docs/java/urlfetch/#Java_Making_requests
This is too short since the API server-side timeout is ~30 seconds (client should be longer).
The CallList.create method is hard coded to use Post. Unfortunately, this won't work if the TwiML files are on S3 for example.
It would be great if the method could be set in the paramters map.
It would be enormously helpful if this project were available from the Maven Central Repository. This is the only dependency of my product that is not available from a public maven repo. This is a minor nuisance for developers, and Twilio would be well served to address this issue.
Guide to uploading artifacts to the Central Repository - http://maven.apache.org/guides/mini/guide-central-repository-upload.html
With gratitude,
Ryan
I do not see delete methods for removing subaccounts, maybe something like setStatus(boolean)
, based on the REST API docs. Is this is there, or do I have to build a request?
This will prevent the unauthenticated request that is made prior to the authenticated request
Instructions under 'Preemptive authentication in HttpClient' here:
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html#d4e1023
Is it possible to get support for Java5 with this library?
see the docs here: http://books.sonatype.com/nexus-book/reference/staging.html
While testing the send SMS - java api, I tried sms.getPrice(). This throws IllegalArgumentException: Property price does not exist
We shouldn't run into problems like this:
http://stackoverflow.com/questions/19826219/sslpeerunverifiedexception-in-basic-twilio-java-app
The Numbers class:
https://github.com/twilio/twilio-java/blob/master/src/main/java/com/twilio/sdk/verbs/Number.java
which we normally refer to as a noun:
http://www.twilio.com/docs/api/twiml/number
is described as a verb and extends the Verb class. While this seems to work functionally, semantically it is inconsistent with our docs.
Conference is the same and there doesn't appear to be a verb (or noun) for Client within the Dial verb.
When you ask for the category on a usage record, it performs a lookup using the UsageCategory enum. Here are the relevant lines:
public UsageCategory getCategory() {
return UsageCategory.valueOf(getProperty("Category").replace('-', '_'));
}
The problem is this throws an IllegalArgumentException when it encounters a category that isn't in the enum. Right now (2013-10-08) the API is returning a category named "calls_sip" which isn't in the enum in the current version of the code (enum last updated in commit d9cf649).
Here is the exact stack trace:
java.lang.IllegalArgumentException: No enum const class com.twilio.sdk.resource.instance.UsageCategory.calls_sip
at java.lang.Enum.valueOf(Enum.java:196)
at com.twilio.sdk.resource.instance.UsageCategory.valueOf(UsageCategory.java:10)
at com.twilio.sdk.resource.instance.UsageRecord.getCategory(UsageRecord.java:70)
(called from my code)
This means that whenever a new stats category is added, the existing Java code can suddenly start to error out where it worked before. I'd suggest putting a try/catch around the valueOf and returning null if it's not in the enum. At least it could be documented (say with Javadoc) that this may occur.
Exception swallowing makes it difficult to troubleshoot any API errors in the App Engine environment.
Could wrap the exception instead, e.g.
throw new IOException("Error flushing content in Google App Engine fetch", ex);
Recording lacks a method to retrieve its TranscriptionList, as described here:
http://www.twilio.com/docs/api/rest/recording#instance-subresources
InstanceResource.getProperty(String name) throws an IllegalArgumentException, when it should return an error code/status code instead. For instance, if the SMS message is too long, an exception is never thrown.
Add the following around line 71 of InstanceResource.java to fix the problem:
if (prop instanceof Integer) {
return String.valueOf(prop);
}
Usage Record interface needs to support LastMonth, Monthly, Yearly etc.
It looks like Android OS does not include deprecated methods/constructors from Apache HttpClient 4.
As a result a runtime exception is encountered when the Twilio Java helper library is used, similar to this:
E/AndroidRuntime(618): java.lang.NoSuchMethodError: org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.
E/AndroidRuntime(618): at com.twilio.sdk.TwilioRestClient.(TwilioRestClient.java:137)
E/AndroidRuntime(618): at com.twilio.sdk.TwilioRestClient.(TwilioRestClient.java:108)
If we can remove references to deprecated methods/constructors it should improve the experience of using Twilio Java helper library in Android OS.
Trying to send an SMS internationally resulted in the following error when attempting to retrieve the price:
getObject is protected and there is no way to access it.
Caused by: java.lang.IllegalArgumentException: Property price is an object. Use getObject() instead.
at com.twilio.sdk.resource.InstanceResource.getProperty(InstanceResource.java:70)
at com.twilio.sdk.resource.instance.Sms.getPrice(Sms.java:172)
at com.xoom.sms.twilio.transform.TwilioSmsResourceTransformer.getPrice(TwilioSmsResourceTransformer.java:32)
at com.xoom.sms.twilio.transform.TwilioSmsResourceTransformer.transform(TwilioSmsResourceTransformer.java:25)
at com.xoom.sms.service.send.SmsTemplateProcessingSendingService.send(SmsTemplateProcessingSendingService.java:42)
at com.xoom.sms.service.notification.XferSmsNotificationServiceImpl.sendSms(XferSmsNotificationServiceImpl.java:59)
at com.xoom.sms.service.notification.XferSmsNotificationServiceImpl.notify(XferSmsNotificationServiceImpl.java:50)
The Http connection timeout is set to one second leading to spurious connection exceptions towards the Twilio API nodes.
It appears that the precompiled binary for Twilio contains library code to support tests, such as the EasyMock classes. As you are using EasyMock 2.4, this makes it impossible to use EasyMock 3.0 or later with the Twilio jars. Presumably the production Twilio jar should not include tests, so removing the EasyMock classes from the binary would:
(1) Decrease the size of the binary.
(2) Make it easier to use a newer version of EasyMock alongside Twilio.
EasyMock 3.0 and later has important class extensions.
from the quickstart on the homepage
We should subclass the TwilioRestClient with a TwilioAppEngineRestClient or something that uses the java.net.URL class instead of org.apache.HttpClient, which is not supported on App Engine.
TwilioUtils can not be instantiated because its set to default.
There are places in code like this:
where checked exceptions are wrapped in generic RuntimeException.
If instead these were wrapped in e.g. a TwilioRestRuntimeException this would allow code calling the API to catching these exceptions instead of having to catch RuntimeException.
How to remove the reference to ThreadSafeClientConnManager since Android OS does not include deprecated methods/constructors from Apache HttpClient 4. and how to build prebuilt version of the library. I dont know how to use maven.
Because if i am using twilio sms in android iam getting following error.
E/AndroidRuntime(618): java.lang.NoSuchMethodError: org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.
E/AndroidRuntime(618): at com.twilio.sdk.TwilioRestClient.(TwilioRestClient.java:137)
E/AndroidRuntime(618): at com.twilio.sdk.TwilioRestClient.(TwilioRestClient.java:108)
I get the below error i have added the required jar file but still get the below errror
Caused by:
java.lang.NoClassDefFoundError: com/twilio/sdk/TwilioRestException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2483)
at java.lang.Class.getConstructor0(Class.java:2793)
at java.lang.Class.newInstance(Class.java:345)
at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:428)
at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:368)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:351)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:97)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:485)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.ClassNotFoundException: com.twilio.sdk.TwilioRestException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:215)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 42 more
Caused by:
java.lang.ClassNotFoundException: com.twilio.sdk.TwilioRestException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:215)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2483)
at java.lang.Class.getConstructor0(Class.java:2793)
at java.lang.Class.newInstance(Class.java:345)
at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:428)
at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:368)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:351)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:97)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:485)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
I cannot build local jars with 3.3.9, master or twilio-java-sdk-3.3.10.
git co twilio-java-sdk-3.3.10
mvn install
... skipping output...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.twilio.sdk.resource.instance.MemberTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.32 sec
Running com.twilio.sdk.resource.instance.QueueTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.032 sec
Running com.twilio.sdk.resource.instance.UsageRecordTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.381 sec <<< FAILURE!
Running com.twilio.sdk.resource.instance.UsageTriggerTest
Tests run: 4, Failures: 0, Errors: 4, Skipped: 0, Time elapsed: 0.091 sec <<< FAILURE!
Running com.twilio.sdk.TwilioRestClientTest
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.81 sec
Results :
Tests in error:
testListingUsageRecords(com.twilio.sdk.resource.instance.UsageRecordTest): com.twilio.sdk.TwilioRestClient.setHttpclient(Lorg/apache/http/client/HttpClient;)V
testListingUsageTrigger(com.twilio.sdk.resource.instance.UsageTriggerTest): com.twilio.sdk.TwilioRestClient.setHttpclient(Lorg/apache/http/client/HttpClient;)V
testCreateUsageTrigger(com.twilio.sdk.resource.instance.UsageTriggerTest): com.twilio.sdk.TwilioRestClient.setHttpclient(Lorg/apache/http/client/HttpClient;)V
testDeleteUsageTrigger(com.twilio.sdk.resource.instance.UsageTriggerTest): com.twilio.sdk.TwilioRestClient.setHttpclient(Lorg/apache/http/client/HttpClient;)V
testDeleteErrorUsageTrigger(com.twilio.sdk.resource.instance.UsageTriggerTest): com.twilio.sdk.TwilioRestClient.setHttpclient(Lorg/apache/http/client/HttpClient;)V
Tests run: 18, Failures: 0, Errors: 5, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.119s
[INFO] Finished at: Fri Dec 21 01:14:50 PST 2012
[INFO] Final Memory: 14M/81M
groupid should be groupId (with capital "I")
artifactid should be artifactId (with capital "I")
Copied the code example verbatim, and get an error while trying to list accounts in JUnit:
Code:
AccountList accountList = client.getAccounts();
Stack:
java.lang.NoSuchMethodError: org.codehaus.jackson.type.JavaType.getHandler()Ljava/lang/Object;
at org.codehaus.jackson.map.deser.BasicDeserializerFactory.createMapDeserializer(BasicDeserializerFactory.java:202)
at org.codehaus.jackson.map.deser.StdDeserializerProvider._createDeserializer(StdDeserializerProvider.java:253)
at org.codehaus.jackson.map.deser.StdDeserializerProvider._createAndCacheValueDeserializer(StdDeserializerProvider.java:198)
at org.codehaus.jackson.map.deser.StdDeserializerProvider.findValueDeserializer(StdDeserializerProvider.java:100)
at org.codehaus.jackson.map.ObjectMapper._findRootDeserializer(ObjectMapper.java:1347)
at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:1280)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:883)
at com.twilio.sdk.parser.JsonResponseParser.parseJson(JsonResponseParser.java:34)
at com.twilio.sdk.parser.JsonResponseParser.parse(JsonResponseParser.java:20)
at com.twilio.sdk.TwilioRestResponse.toMap(TwilioRestResponse.java:245)
at com.twilio.sdk.resource.list.AccountList.create(AccountList.java:60)
at integrations.TwilioAPI.createSubAccount(TwilioAPI.java:108)
Hi, I saw that the latest version in pom.xml is 3.3.10-SNAPSHOT. Can you add a git tag for this 3.3.10 release?
Thanks,
Kevin
Can we update the library to support Java 5 or build a separate Java 5 version?
The Java 5 dependencies are as follows:
jackson-mapper-asl-1.9.12.jar
jackson-core-asl-1.9.12.jar
httpclient-4.2.5.jar
httpclient-cache-4.2.5.jar
httpcore-4.2.4.jar
httpmime-4.2.5.jar
commons-codec-1.6.jar
commons-lang-2.3.jar
commons-lang3-3.1.jar
Not sure why both commons-lang jars are required, but project doesn't compile if one is taken out.
The Java client library class com.twilio.sdk.resource.instance.Sms has 3 get date methods, none of which are null safe. The code as it is currently written is:
public Date getDateCreated() {
SimpleDateFormat format = new SimpleDateFormat(
"EEE, dd MMM yyyy HH:mm:ss Z");
try {
return format.parse(this.getProperty("date_created"));
} catch (ParseException e) {
return null;
}
}
If the "date_created" property is null, SimpleDateFormat.parse() will throw a NullPointerException, not a ParseException.
I suggest doing a null check first on the result of the this.getProperty("date_created") call and return null if it is null:
public Date getDateCreated() {
String dateCreated = this.getProperty("date_created");
if (dateCreated == null) {
return null;
}
try {
SimpleDateFormat format = new SimpleDateFormat(
"EEE, dd MMM yyyy HH:mm:ss Z");
return format.parse(dateCreated);
} catch (ParseException e) {
return null;
}
}
You will need to make this fix to all three methods that return dates, getDateCreated(), getDateUpdated(), and getDateSent().
Which also leads me to suggest extracting the common code out to a single method that takes the property name as an argument so that you don't have so much code duplication.
Should the required JSON library actually be the json-simple-1.1.jar? See TwilioCapability.java below:
import org.json.simple.JSONValue;
/**
* This class represents a token that will grant someone access to resources
* within Twilio.
*/
public class TwilioCapability {
ivy.xml could use this...
<dependency org="com.googlecode.json-simple" name="json-simple" rev="1.1" />
Thanks!
httpclient 4.1.2 has a bug in SSL certificate checking. the bug is somewhat confusingly documented here:
https://issues.apache.org/jira/browse/HTTPCLIENT-1118
and it causes exceptions that look like this:
javax.net.ssl.SSLException: hostname in certificate didn't match: <www.google.com/173.194.75.105> != <www.google.com>
From what I can tell, the bug only manifests for callers of a deprecated API and does not affect the twilio sdk. However, many other libraries use httpclient, including some that still call the deprecated API. This means that introducing the twilio sdk to a project may cause other libraries in the project to break.
I was able to work around the issue by forcing my project to use 4.2.1 (4.1.3 has the same bug as 4.1.2). So changing the SDK dependency to 4.2.1+ or 4.1.1- are both possible solutions (I'm not sure about the implications of going back to 4.1.1 for twilio).
When I do:
TwilioRestClient client = new TwilioRestClient(accountSid, authToken); Call call = client.getAccount().getCall(callSid); System.out.println(call.getStatus());
I get:
Exception in thread "main" java.lang.RuntimeException: com.twilio.sdk.TwilioRestException: Authenticate at com.twilio.sdk.resource.InstanceResource.getProperty(InstanceResource.java:56) at com.twilio.sdk.resource.instance.Call.getStatus(Call.java:158) at Test.main(Test.java:13) Caused by: com.twilio.sdk.TwilioRestException: Authenticate at com.twilio.sdk.TwilioRestException.parseResponse(TwilioRestException.java:74) at com.twilio.sdk.TwilioRestClient.safeRequest(TwilioRestClient.java:484) at com.twilio.sdk.resource.Resource.load(Resource.java:50) at com.twilio.sdk.resource.InstanceResource.getProperty(InstanceResource.java:53) ... 2 more
The RequestAccountSid is not set when getStatus() is called, resulting in path:
/2010-04-01/Accounts/null/Calls/xxxxxxx.json"
Fix:
Change com.twilio.sdk.resource.instance.Account.getCall(String) to look like this:
public Call getCall(String sid) { Call call = new Call(this.getClient(), sid); call.setRequestAccountSid(getRequestAccountSid()); return call; }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.