File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Variable response throws error but static  response fine? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Variable response throws error but static  response fine?" Watch "Variable response throws error but static  response fine?" New topic
Author

Variable response throws error but static response fine?

Lila Fowler
Ranch Hand

Joined: Jul 31, 2009
Posts: 84
Hi guys,

I am testing a web service and have come across a strange problem,
In a specific method if I return a static result eg: return = "random value here";
it displays the result on the screen without any errors/issues. The moment I set
it to a variable that is returned even if I add a +"" or .toString(); it throws me an error.

Here is my code:



Here is a printout of the server when using a static var:

INFO: Invoking wsimport with http://localhost:8080/SmsService/SmsService?WSDL
INFO: wsimport successful
SEVERE: cell:0835707641
SEVERE: message:testing
SEVERE: confirmdelivery:false
SEVERE: errorlog:false
SEVERE: You still have more then 50 credits
SEVERE: Orig resM7: ID: d44f624a5276e43da51ab85060955c3a
SEVERE: M7:ID: ab98e7c5d8bdf74cd41f96bcab80fdfd

I have attached the screenshots of both the static and dynamic results.

NB*? -- I should add though that when I try to copy and past the the original
printed value from the glassfish server output i get the following resut:

SEVERE: Orig resM7:

I think this may be the reason that I receive a null pointer, but am very confused
as to why it prints out if this is the case, and how I should resolve it.

Any suggestions?
Thanks





[Thumbnail for errorresult.jpg]


[successresult.jpg]


Courage is not the absence of fear but rather the judgment that something is more important then fear. ~ Ambrose Redmond
Guillaume Jourdan
Ranch Hand

Joined: Jul 24, 2012
Posts: 47

Hi Linda,

Lila Fowler wrote:





I think that your http request doesn't return the same result...

System.err.println("Orig resM7:" + response); //original dynamic response return by clickatell

This print doesn't print origresponse but your static variable : response
Lila Fowler
Ranch Hand

Joined: Jul 31, 2009
Posts: 84
Sorry for the error, but I was editing it on Java Ranch just to illustrate the difference better,
and forgot to edit the variable. Sorry about that, I will edit and correct this. Thanks Guillaume Jourdan

But if you look at my result returned, you will notice different variables print out.

SEVERE: Orig resM7: ID: d44f624a5276e43da51ab85060955c3a //dynamic
SEVERE: M7:ID: ab98e7c5d8bdf74cd41f96bcab80fdfd //static

//Correction line 15


My problem is still the same as the above, a result is returned and printed out but
at the end of the method returns nothing.


Thanks for the help
Guillaume Jourdan
Ranch Hand

Joined: Jul 24, 2012
Posts: 47

Hi Lila,

Lila Fowler wrote:
SEVERE: cell:0835707641
SEVERE: message:testing
SEVERE: confirmdelivery:false
SEVERE: errorlog:false
SEVERE: You still have more then 50 credits


I think this is not a free API and you must paid to send a SMS to this cellphone.

Clickatell_SMTP.pdf wrote: To use this API, you need to register at (http://www.clickatell.com/register/?product=1). When you sign up for an SMTP account you will be given a username, password and api_id: keep these at hand. Once you have registered and been activated you will receive 10 free credits with which to test our service. Messages sent with these credits contain a canned (pre-populated) message. You can test the API using these credits, and purchase credits to start sending your own, customised messages


You can find the doc here : : Clickatell_SMTP.pdf
Lila Fowler
Ranch Hand

Joined: Jul 31, 2009
Posts: 84
Thanks Guillaume,

But I am registered with clickatell and have more then 500 credits available.
My messages are sending without a problem and I am picking up the
session id's, which I am printing out as below.

SEVERE: Orig resM7:ID: d7c46b9f048e42411716ed786b427f62

My problem comes in when I try and pass the response back to the original method
that I used to call the compileSmsUrl() it returns a static variable fine but not a dynamic one.

Thanks for the help.
Guillaume Jourdan
Ranch Hand

Joined: Jul 24, 2012
Posts: 47

Just to be sure...

In your real code, you don't have :


But :

String staticurl = "http://api.clickatell.com/http/msg?user=YOUR_USER &password=YOUR_PASSWORD &api_id=11111111&to=";
Lila Fowler
Ranch Hand

Joined: Jul 31, 2009
Posts: 84
The reason for that is because I don't want to post my real username
and real password online thereby letting the any unauthorized person
send sms's that I am paying for.
Guillaume Jourdan
Ranch Hand

Joined: Jul 24, 2012
Posts: 47

Lila Fowler wrote:The reason for that is because I don't want to post my real username
and real password online thereby letting the any unauthorized person
send sms's that I am paying for.


I understand, it's just to be sure ;p
Guillaume Jourdan
Ranch Hand

Joined: Jul 24, 2012
Posts: 47

Lila Fowler wrote:My problem comes in when I try and pass the response back to the original method
that I used to call the compileSmsUrl() it returns a static variable fine but not a dynamic one.






What do you do in executeHttpRequest and writeLogInfo methods?

and why you have :


and not :
Lila Fowler
Ranch Hand

Joined: Jul 31, 2009
Posts: 84
The log method literally generates a log file. // Not applicable in this case as returnErrors is set to false - same as above changed the variable to better illustrate the different vars.

I will post the code used all three methods to better illustrate. I normally try to keep the code minimal so that there isn't tons of reading to do, so sorry bout this.

First method -- picks up the variables the user enters



Second method -- goes in here to compile the url needed by clickatall



In the next method the HttpRequest is actually sent to clickatell and a session id is returned



Any ideas?
Guillaume Jourdan
Ranch Hand

Joined: Jul 24, 2012
Posts: 47

What's your output log of your executeHttpRequest method?

Have you a log who start by : "Response in httpp:" or "Exceptions:" ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Variable response throws error but static response fine?
 
Similar Threads
IllegalStateException when inserting session attribute into a table
Program like ATM where person enters amount in dollars and cents but program uses int for monies
Hibernate Spring
not getting what this servlet is doing+MVC
Solution for repeating function in all servlets.