Exception in thread "main" com.twilio.exception.ApiException: api.twilio.com - twilio-api

public static final String ACCOUNT_SID = "ACxxx";
public static final String AUTH_TOKEN = "6xx";
public static void main(String[] args) {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Message message =
Message.creator(new PhoneNumber("+1518xx"), new PhoneNumber("+18xxx"),
"SMS POC").create();
System.out.println(message.getSid());
}
Exception
Exception in thread "main" com.twilio.exception.ApiException: api.twilio.com
at com.twilio.http.NetworkHttpClient.makeRequest(NetworkHttpClient.java:88)
at com.twilio.http.HttpClient.reliableRequest(HttpClient.java:38)
at com.twilio.http.HttpClient.reliableRequest(HttpClient.java:22)
at com.twilio.http.TwilioRestClient.request(TwilioRestClient.java:42)
at com.twilio.rest.api.v2010.account.MessageCreator.create(MessageCreator.java:307)
at com.twilio.rest.api.v2010.account.MessageCreator.create(MessageCreator.java:25)
at com.twilio.base.Creator.create(Creator.java:45)
at com.twilio.notifications.config.TestMain.main(TestMain.java:18)

I ran into this issue as well when trying out the quick start example. I verified that I had the correct verified phone numbers, the text did not have an empty message and the code specified the to and from numbers properly.
I found the issue to be proxy related. Once fixed this in my local setup, it worked like a charm. It also worked without any issues in the server.
Hope this helps,
Alice

Related

JerseyTest with ApacheCXF client does not return a reasonPhrase

I have a simple JerseyTest, that looks like this:
final Response getResponse = this.target(endpoint).get();
assertStatusEquals(Status.NOT_FOUND, getResponse);
assertEquals("Cannot find something", getResponse.getStatusInfo().getReasonPhrase());
This worked fine when using the standard JerseyClient. However, I switched to ApacheCXF because I want to use the PATCH method.
...
//We want to support PATCH, which is sucky in Java's HttpUrlConnection.
//That is why we need a different HttpClient implementation (This is ApaceCXF)
//We need to register the JacksonJaxbJsonProvider
private final Client cxfHttpClient = new ClientBuilderImpl().build()
.register(JacksonJaxbJsonProvider.class);
//Set it before each test
#Override
public void setUp() throws Exception {
super.setUp();
this.setClient(this.cxfHttpClient);
}
Now this simple test breaks becuase the .getReasonPhrase() returns null. I haven't changed the server, so I expect the message to be there.
Is seems to be a bug: CXF-8633,
Which is on its way to be fixed: https://github.com/apache/cxf/commit/d23ed9dc87481d9a6cabdb2b6a6e086da6fcce24

JMS Unable to resolve QueueConnectionFactory

volks!
I have a problem. I want to read some messages from Weblogic 12c. This code is currently working with another server, which wasn't configured by me. So the problem may be in configuration of server.
The problem is when I use code:
public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
public final static String JMS_FACTORY="QCF";
public final static String QUEUE="dizzyworldQueue";
public final static String USER_NAME="weblogic";
public final static String USER_PASSWORD="Welcome1";
public final static String URL="t3://localhost:8001";
private static InitialContext getInitialContext(String url) throws NamingException
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_PRINCIPAL, USER_NAME);
env.put(Context.SECURITY_CREDENTIALS, USER_PASSWORD);
return new InitialContext(env);
}
qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
qcon = qconFactory.createQueueConnection(); // here it falls
The error is:
Exception in thread "main" javax.naming.NameNotFoundException: Unable to resolve 'QCF'. Resolved '' [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'QCF'. Resolved '']; remaining name 'QCF'
I have Queue and QueueConnection factory on my server. What can be the rison?
The message says that there is no connection factory bound in your naming service (JNDI) with the name "QCF".
So you have to configure your application server to offer the queue connection factory through JNDI.
If that is already the case, you have to change that name in your client code to match the name in JNDI.
You have to add the connection factory and the queue in the admin console.
Look for Services - JMS modules. Possibly add a JMS module, and add a connection factory and queue.
Have a look at this tutorial, it shows the steps to configure it.

JBoss7.1 final 2 counts of IllegalAnnotationExceptions

I'm trying to migrate app from jboss 5.1 to 7.1 and i have error like this Error message which i'm not sure why i get this. if anyone have any idea please help me.
Update: 1
#Stateless
#Remote(PackageService.class)
#Interceptors(CrossContextSpringBeanAutowiringInterceptor.class)
#WebContext(contextRoot="/appname_web_services", urlPattern="/MaintenanceService", authMethod="", secureWSDLAccess=false)
#WebService(
name="MaintenanceService",
targetNamespace = "http://appname.com/web/services",
serviceName = "MaintenanceService")
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
#HandlerChain(file = "WebServiceHandlerChains.xml")
#TransactionTimeout(10800)
public class MaintenanceServiceBean implements MaintenanceService {
private static final Logger logger = Logger.getLogger( MaintenanceServiceBean.class );
#Resource(mappedName="/ConnectionFactory")
ConnectionFactory connectionFactory;
#Resource(mappedName="topic/manager_system_topic")
javax.jms.Destination systemTopic;
#Autowired
MaintenanceService MigrationService;
#WebMethod
public List<Long> getSoftDeletedPackageIds(Long performedBy) throws Exception {
return MigrationService.getSoftDeletedPackageIds(null);
}
this is the class where i believe it fails.
You are using an interface in your JAXB mappings for which you have not provided enough information to the runtime for it too be able to bind an actual implementation. Without more code included in your question it's hard to recommend a specific solution, but typically you would annotate the included interface with #XmlAnyElement.
You can read through this useful tutorial to determine the best solution for your possible case.

SWTbot tests not behaving as expected

So I'm testing an eclipse plugin with SWTbot and I'm not getting the result I'm expect - when I cut the test down it turns out that the problem isn't with the bot it's with some code that I've copied accross from another part of the program (where it was fully functional)
The following code...
#RunWith(SWTBotJunit4ClassRunner.class)
public class Tests {
private static SWTWorkbenchBot bot;
#BeforeClass
public static void beforeClass() throws Exception {
bot = new SWTWorkbenchBot();
bot.viewByTitle("Welcome").close();
}
#Test
public void maybeThisWillWork(){
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
System.out.println("A");
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
System.out.println("B");
}
#AfterClass
public static void sleep() {
System.out.println("In the sleep function");
bot.sleep(10000);
}
}
Gives me the output -
A
In the sleep function
Rather than the expected
A
B
In the sleep function
Any ideas?
you may need to run your test as JUnit plugin test. Have you tried that?
So it turns out that the answer is thus (also a nice advantage of stackoverflow is that I actually solved this somewhere else, remembered I'd had a similar problem and then had to come back to stackoverflow to remind myself of the details)
SWTBot isn't running in the UI thread proper hence the null pointer errors, what I had to do was use effectively:
Display display = bot.getDisplay();
display.syncExec(objectThatdoesthethingiwanttogetdoneintheUIthread);
System.out.println(objectThatdoesthethingiwanttogetdoneintheUIthread.results);
...and that got things working...

StatusCodeException Vs. RuntimeException in GWT

In my GWT app. I overrode RemoteServiceServlet to check if the session is valid right before the service method is being called. I am trying to throw a RuntimeException("expired session") from the server and I would like the client to catch this exception from the asynccallback onFailure...
In the client I would like to:
Asynccallback:
#Override
public void onFailure(Throwable caught) {
final String message = caught.getMessage();
if (!isNullOrEmptyString(message) && message.contains("expired session")) {
com.google.gwt.user.client.Window.Location.reload();
}
}
However, in the client, the caught object is still a StatusCodeException and the message is still the default "...Exception in the server...". how can I override the exception at least the default message to compare if it was a session expired message I sent from the server?
thanks
Hi Gursel,
Here's my code:
-> Custom RemoteServiceServlet. I'm trying to "intercept" every method before it's invoked. I check the session and throw a RuntimeException if it's already expired. So basically, it is not the declared method that throws the exception but the custom RemoteServiceServlet. It still goes to the "onFailure" in the client async but the Throwable object is still of type "StatusCodeException" without the EXPIRED_SESSION_MSG message. Don;t know how to make this work. Thanks!
public class XRemoteServiceServlet extends RemoteServiceServlet {
private final static String EXPIRED_SESSION_MSG = "ERROR: Application has expired session.";
#Override
protected void onAfterRequestDeserialized(RPCRequest rpcRequest) {
HttpServletRequest httpServletRequest = this.getThreadLocalRequest();
HttpSession session = httpServletRequest.getSession(false);
if (session != null) {
final String sessionIdFromRequestHeader = getSessionIdFromHeader();
if (!isNullOrEmptyString(sessionIdFromRequestHeader)) {
final String sessionId = session.getId();
if (!sessionId.equals(sessionIdFromRequestHeader)) {
throw new RuntimeException(EXPIRED_SESSION_MSG);
}
}
All RuntimeExceptions thrown by Server side of gwt application has been wrapped as StatusCodeException if you did not declare them at your remote method declaration.
EDIT :
After, Thomas Broyer comment, I have learned that all exceptions (checked or unchecked) that are declared at remote method declaration are propagated to gwt client. Therefore all you have to do is just declare your remote method such as :
public void myRemoteMethod() throws RuntimeException;
The post looks too old, still here is the solution I have come up with. Override processCall(String payload) of RemoveServiceServlet, if the session is invalid execute the blow code else call super.processCall(payload).
//Pass the exception to Client
RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(), this);
onAfterRequestDeserialized(rpcRequest);
return RPC.encodeResponseForFailure(rpcRequest.getMethod(), new CustomException("Invalid Session!"),rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());
All the GWT services are servlets so GWT serializes the custom exception and sends to client as string, we follow the same :)