Review
In the previous section, we have laid down the functional specs and took a preview of the application. In this section, we will write and discuss the Java classes and the project's structure.Table of Contents
Part 1: Introduction and Functional SpecsPart 2: Java classes
Part 3: XML configuration
Part 4: HTML form
Part 5: Running the Application
Project Structure
Our application is a Maven project which means it follows the Maven convention for web applications.Here's a preview of our project's structure:
Domain Layer
The domain layer contains a Message class that represents an email message and n UploadedFile class that represents a file upload.Controller Layer
The controller layer contains a simple controller EmailController that serves a form for composing and sending emails. It has two main methods: send for sending emails and upload for uploading files.Whenever a file is attached and uploaded, it is saved first to a temporary location which can be retrieved later via its filename. When the send method is triggered, it basically pulls out the file from the temporary location based on the filename.
Service Layer
The service layer contains the email service. We have a simple interface EmailService for sending messages.The actual implementation SendGridEmailService relies on RestTemplate to send the email message via HTTP.
How did we manage to produce this code? Basically this is a translation of SendGrid's API using Spring RestTemplate. The specific SendGrid API we're using is the Mail module, which is under the Web API. Please see http://docs.sendgrid.com/documentation/api/web-api/mail/#send for the complete documentation.
To test the Mail module, you can either use your browser or CURL (if you're familiar with it).
Browser-based test:
https://sendgrid.com/api/mail.send.xml?api_user=youremail@domain.com&api_key=secureSecret&to=destination@example.com&toname=Destination&subject=Example%20Subject&text=testingtextbody&from=info@domain.com
CURL-based test:
curl -d 'to=destination@example.com&toname=Destination&subject=Example Subject&text=testingtextbody&from=info@domain.com&api_user=sendgridUsername&api_key=sendgridPassword' https://sendgrid.com/api/mail.send.json
Utility Layer
This layer contains helper classes and interfaces. Here we've extracted the required SendGrid parameters when sending emails via HTTP.Next
We've just completed discussing and writing our Java classes. In the next section, we will declare the required configuration files. Click here to proceed.
Share the joy:
|
Subscribe by reader Subscribe by email Share
I have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteSpring online training Spring online training Spring Hibernate online training Spring Hibernate online training Java online training
spring training in chennai spring hibernate training in chennai
I enjoyed your blog Thanks for sharing such an informative post. We are also providing the best services click on below links to visit our website.
ReplyDeletedigital marketing company in nagercoil
digital marketing services in nagercoil
digital marketing agency in nagercoil
best marketing services in nagercoil
SEO company in nagercoil
SEO services in nagercoil
social media marketing in nagercoil
social media company in nagercoil
PPC services in nagercoil
digital marketing company in velachery
digital marketing company in velachery
digital marketing services in velachery
digital marketing agency in velachery
SEO company in velachery
SEO services in velachery
social media marketing in velachery
social media company in velachery
PPC services in velachery
online advertisement services in velachery
online advertisement services in nagercoil
web design company in nagercoil
web development company in nagercoil
website design company in nagercoil
website development company in nagercoil
web designing company in nagercoil
website designing company in nagercoil
best web design company in nagercoil
web design company in velachery
web development company in velachery
website design company in velachery
website development company in velachery
web designing company in velachery
website designing company in velachery
best web design company in velachery
Thanks for Sharing - ( Groarz branding solutions )
hermes bag outlet
ReplyDeletebape
yeezy outlet
air jordan travis scott
air jordan
supreme new york
jordan outlet
bape official
off white shoes
palm angels