Michael K. Wilson

Ranch Hand
+ Follow
since Apr 23, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Michael K. Wilson

Hello there,

Don't know if this particular forum is the best place to ask this question...

What is the best way to handle error response codes generated from Facebook REST API calls using server side Java?

For example, if in a deployed app, a person calls Friends.get <http://wiki.developers.facebook.com/index.php/Friends.get >.

The following error response codes could be generated (in JSON or XML):

1 An unknown error occurred. Please resubmit the request.
2 The service is not available at this time.
4 The application has reached the maximum number of requests allowed. More requests are allowed once the time window has completed.
5 The request came from a remote address not allowed by this application.
101 The API key submitted is not associated with any known application.
102 The session key was improperly submitted or has reached its timeout. Direct the user to log in again to obtain another key.
103 The submitted call_id was not greater than the previous call_id for this session.
104 Incorrect signature.

Figured that I would write my own custom exceptions which are bubbled < http://today.java.net/pub/a/today/2006/04/06/exception-handling-antipatterns.html >,
but my project lead says that throwing custom exceptions isn't the way to go!?!

Would appreciate it if someone could suggest an alternative approach to handle the Facebook REST API error codes...

Thank you for taking the time to read this.

Happy programming.
14 years ago
Discovered the solution! The generated device token string seemed too long.

My NSData to hex code was printing the wrong token (it should be 64 characters, before it was 155 characters).

Solution:


Now, I am receiving the notifications on my Device!

Happy programming to all!
15 years ago
iOS
Hello there,

Am using the javapns library on Google Code to send an Apple Push Notification through a REST based web service...

Here are the steps that I have completed:

iPhone Developer Program Portal (IDPP)
:

(1) Created the App ID and APNS based SSL Certificate and Keys.

(2) Created and installed the provisioning profile.

(3) Installed the SSL Certificate and Key on the server.

(4) Set up my iPhone app to register for remote notifications.

XCode
:

Was able to obtain my device token when I built and deployed my app onto my device.

As soon as my iPhone app deployed, the dialog came up on my iPhone indicating that my app would like to send push notifications and also asked for permission to allow them.

When I invoked my web service, through my Log4J statements, I was able to see that my REST based web service was indeed invoked but I never received a push notification on my iPhone app!

ApnsManager class:



RESTful Web Service:



Now, when I deploy my app to my app server and open up a rest client and type in:

http: // localhost:8080/myapp/apns/send

The rest client returns this:

HTTP/1.1 200 OK


The following log messages are outputted to my console:



However, I don't receive the push notification on my app (residing on my iPhone)!

Am really stumped at this point...

What could I possibly be doing wrong?

Is it a problem with the way I set up my RESTful web service (sorry I am a newbie to REST)?

Would really appreciate it if someone could assist me with this...

Thank you for taking the time to read this...
15 years ago
iOS
Nishan,

Good news! When I click on the embedded URL, my ConfirmServlet does run...



My local server's console (after I click on the e-mail's confirm embedded URL):


WARN ConfirmServlet:25 - Inside Confirm Servlet
WARN ConfirmServlet:31 - Mail Token received: yfPRA00LiNHhB6QYuXByq4E78dUp8zOLryAb68ZfBnI=


In the servlet which sends the e-mail, I hard coded the user's e-mail address for test purposes...

Will be pulling the e-mail address out of a Hibernate 3 / JPA object in my real code...

Question(s):

(1) How do I set my User class's setConfirmed(true)?

(2) Meaning, how do I send the user object reference to ConfirmServlet?

The user will be instantiated as part of the HibernateSession in the servlet which sends my e-mail...

(3) Should I use URL encoding / decoding?

Now when user click on your url you get that key which is unique. Now just select user which contains that key.... So, first store token into user table and then select user with that token. Now just update confirm field for that user and update user table with new data.



This last part of selecting having ConfirmServlet know which user it was confirmed by is confusing...

In the servlet which sends the e-mail, I hard coded the user's e-mail address for test purposes...

Will be pulling the e-mail address out of a Hibernate 3 / JPA object in my real Send Mail servlet code...

See, I don't understand how the ConfirmServlet would know of my User object reference...

I am using Hibernate / JPA 3 so could you show me some sample code on how to do this?

Happy programming and many, many thanks for writing me back!

-Michael
15 years ago
Hello there,

JavaMail programming is so fun! I first start off mixing the JavaMail code inside a servlet and then refactored it to two separate classes.

Mailer is the independent class which uses JNDI to look up config parameters, sends e-mails, and then closes the connection with the protocol.



MailController is just a simple Java servlet where a Mailer object is instantiated and a String is passed inside the Mailer.sendMsg() method.



Have some OO design issues...

If you can notice, I manually place the body of the e-mail (as a String) from inside the client (in this case, a Java Servlet). Also, I manually have to switch the content type inside the doPost().

Question(s):

(1) How can the Mailer class be set up, so it can send both HTML and plain text messages?

(2) How can the Mailer class be structured to send e-mail to multiple recipients or one user?

(3) Would both of these features / actions require writing two overloaded methods for sendMsg()?

Would appreciate it if someone could help me...

Happy programming,

Michael
15 years ago
I fixed it! It works now!

Solution: Replace the mail.jar file on JBoss with the newest one from Sun and edit the mail configuration file to reflect port 465.

The JavaMail 1.4ea jar is what comes bundled with JBoss 5.1.0.GA inside:

$JBOSS_HOME/common/lib

Replaced it with 1.4.2 and then changed some of the xml config parameters around.

Debug output:



$JBOSS_HOME/server/default/deploy/mail-service.xml:



Please close this topic...

Happy programming,

Mike
15 years ago
Hello there,

Am using JBoss 5.1.0GA and JDK 1.5.0_19 on OS X Leopard.

Created a working SendMailServlet.

Have now decided to refactor it into two separate classes (extract out JavaMail code to a separate class and create a ServletController).

Am also trying to use JNDI to access the connection properties in the mail-service.xml configuration file residing in JBoss.

The Mailer class contains the reusable functionality needed to send an e-mail:



The MailController class serves as a standard Java Servlet which invokes the Mailer.class's sendMsg() method:



Have the mail configuration set under $JBOSS_HOME/server/default/deploy/mail-service.xml:



web.xml (Deployment Descriptor):



This is what is outputted when I start JBOSS and click point my browser to:

https://localhost:8443/myapp/sendmail



Why am I getting this java.net.ConnectException: Connection refused exception?

Happy programming,

Mike
15 years ago
Where do I put that inside the Confirm Servlet or even the SendMail servlet?

Can you please display some sample code? How does the ConfirmServlet or MailServlet know where to get the user object reference from SendMailServlet and set its confirmed to true?

Thank you for all of your help!

-Mike
15 years ago
Nishan,

Okay, I changed that (by adding myapp inside the URL)...

Now, when I click on the link, it does redirect to:

https://localhost:8443/myapp/confirm?token=5YwRpWRyIGv8KW4IMCBf9PUcMj8TEt3DUv++ONHV1mI=

But nothing happens in the database...

-Mike
15 years ago
Nishan,

Thank you for your advice but how come I am unable to view my Confirm servlet when I clicked on the embedded URL?



I'll try again... Also, how do I process the token or user inside my ConfirmServlet's doGet() method?

Right now its not able to view the servlet and thus I can't proceed...

Why am I getting the 404 error?

Happy programming,

Mike
15 years ago
Nishan,

Thank you very much for the help... Am not using JDBC / SQL, I am using Hibernate / JPA, so here's what I've come up with:



web.xml (deployment descriptor):



My Confirm and User classes are Annotated JPAs (with the Confirm holding a Foreign Key with User - OneToOne Mapping):

User:



Confirm:


My ConfirmServlet:



Now, when I run the server and send the e-mail and click on the embedded confirmation URL with the token, this is
what happens:



Questions:

- How come it doesn't run the ConfirmServlet's doGet() method or how come ConfirmServlet isn't recognized?

- How do I make the ConfirmServlet know who the user is? As you can see I am instantiating the User instance manually...

- I need to have it so it can also handle from multiple receipients...

Happy programming,

Mike
15 years ago
Dear Nishan,

Thank you very much for all of your help...

Questions:

1. Why do I need RegiServlet? Why can't I set just the user.setConfirmed(false); inside my SendMailServlet?

2. What does the code look like in the doPost() or doGet() methods of the ConfirmServlet?

That's what I am confused about...

3. How can I send the confirm parameter (located in the URI) to my ConfirmServlet?

4. Will I need to set session attribute to user in SendMailServlet or RegiServlet and then get the session attribute from the ConfirmServlet?

Would really help if you could assist me with how the ConfirmServlet grabs the token parameter (once the user clicks on the e-mail) and processes it inside doGet() or doPost()?

Thank you for all of your help - its most appreciated!

-Mike
15 years ago
Thank you so much Nishan!

How would I map the Confirm servlet with:

http://locahost:8080/myapp/confirm?token= ?

You mean set up the web.xml (deployment descriptor) like this:



So, far, this is what I have for the ConfirmServlet:



How do I include processing inside the ConfirmServlet for the confirm parameter?

Is there a way to do this by using a WebService (REST) or should I stick with servlet?

Thank you so much for your help,

Mike
15 years ago
Nishan,

Thanks for the help! I have a TokenGenerator in place...

So, you are saying generate the Token inside the SendMailServlet (and save to database) and then append it like this:



I know how to get and set the token to the database. What am I seeking is the mechanism in the ConfirmServlet.

How would the code point to the ConfirmServlet (and how would I make it so the ConfirmServlet would launch when this URL was clicked)?

Should I use a ServletFilter instead of Servlet?

And would this be done as an Http doGet() response / request?

Any code samples would be very helpful...

-Mike
15 years ago
Am in the process of writing a server side Java program (servlet) which would send an e-mail to a user with a confirmation URL (located in the body of the e-mail).

Have already created the servlet (which can send an e-mail) using the JavaMail API... Am wondering how I would design / implement the actual unique URL (where upon an end user's click, it launches a browser and states "Confirmed." in a web page)? The confirmed would have to match either the end user's e-mail address (for verification purposes) or an encrypted token correct?

Would appreciate it if someone could point me in the right direction...

So far this is what my SendMailServlet looks like:



If you notice in the e-mail's content, I have it set like this:



(1) So, basically, should I run a TokenGenerator for the code and then create a ConfirmServlet which would perform a doGet() method with confirm code's parameters?

(2) Would I need to generate a token which would match with the User created in a database or would I use HttpSessions or Cookies appended to the URL?

(3) Is this better to use inside a ServletFilter rather than a Servlet?

Happy programming,

Mike
15 years ago