ReviewIn the previous section, we have learned how to sign-up with SendGrid's free plan. In this section, we will start writing the Java classes and discuss the project's structure.
Table of ContentsPart 1: Introduction and Functional Specs
Part 2: SendGrid account setup
Part 3: Java classes
Part 4: XML configuration
Part 5: Running the Application
Project StructureOur application is a Maven project which means our project follows the Maven structure.
Here's a preview of our project's structure:
Domain LayerThe domain layer contains a Message class that represents an email message.
Controller LayerThe controller layer contains a simple controller that serves a form for composing and sending emails. It also contains a send method that accepts a Message object. The controller delegates the sending part to an email service.
Service LayerThe 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 as a POST method.
Utility LayerThis layer contains helper classes and interfaces. Here we've extracted the required SendGrid parameters for sending emails via HTTP. Please refer to Part 2 of this guide if you need to review the SendGrid Web API.
View LayerThe view layer contains a simple html form for composing and sending email messages. One important section here that needs to be discussed is the usage of the postJSON plugin.
jQuery pluginpostJSON is a jQuery plugin that allows sending of JSON objects via POST. This plugin is based a plugin I found at the jQuery plugin repository. Unfortunately, the location doesn't seem to exist anymore. Also, I've made some modifications with the plugin (see the comments).
NextWe've completed writing our Java classes. In the next section, we will start writing the configuration files. Click here to proceed.
Share the joy:
Subscribe by reader Subscribe by email Share