Reference no: EM131848713
Assignment - Using the code in the folder and continue this exercise.
Deploying Jackson with Maven
Step 1: Install Maven
1. Open Netbeans
2. Tools -> Plugins
a. If Maven is under Installed, make sure it is "Activated"
b. Else, find Maven in Available Plugins and click Install
Step 2: Convert your Netbeans project into a Maven Netbeans project
1. Create a new Maven Project (File->New Project->Maven->Java Application)
2. Copy your packages from your old project to the new project
Step 3: Add Jackson as a dependency to your Maven Netbeans project
1. Right click the Dependencies Folder
2. Search for Jackson (you may have to wait awhile as Maven loads its repos for the first time)
3. Choose jackson-annotations, jackson-core, and jackson-databind
4. Right click on your project and click build with dependencies
Step 4: Look up how to actually use Jackson!
1. Jackson's home-page
2. Main documentation page
3. Core JavaDoc page
4. If that doesn't have what you need, looking around on that github page or github.io is a good way to approach learning how to use a new project!
Exercise:
Exercise Part A: Copy the following content into a new file inside a new folder named "public" inside your NetBeans project. Name the file "index.html".
Now, add a new view to your project that loads any file with a given name from inside the "public" directory. Add a static method that checks if some file exists inside that directory. In your controller (which decides which view to serve), you already know how to serve "/ address" and "/list" URL locations. Right now, any other location results in a 404 error. Change this so that it checks, using the new view class, if a file could be served with the name given in the location. For example, if the location "/favicon.ico" is requested, we should check if we have a file "public/favicon.ico", and if so, we should create a view that serves this file. Write the view so it loads the file and serves it.
OK, Let's serve an image.
Now, let's try to do this with a "PNG" or "JPEG" image. Download an image - any image - from the web, store it in your public folder, and try to retrieve it. This may not work perfectly, or not in all browsers. Remember that the HTTP protocol demands we declare the type of data that is being sent: Content-type: text/html. Look up what to declare for PNG and change your code accordingly.
Also, remember that the way you load a text file is different from a binary file (images are binary files). You don't load those line by line. Look up how to load a binary file in Java and store it in a string. That may make your code better.
Exercise Part B: Part B will be a very simple extension / replacement of what you've already done. Ensure your webserver program has the following (some are carry-overs from previous exercises):
1. A method serializeAsJSON that, using the Jackson library, takes an AddressModel as an argument and returns an object from the Jackson library that encodes a JSON
2. A static method deserializeJSON that takes an object encoding a JSON and returns an AddressModel
3. A method serializeAsJSON that takes an AddressListModel as an argument and returns an object from the Jackson library
4. A static method deserializeJSON that takes an object from the Jackson library and returns an AddressListModel
5. A method saveJSONToFile that takes the object from the Jackson library used to encode the AddressListModel and a File object and then writes to a file for persistency
6. A method called readJSONFromFile that takes the File object and returns an AddressListModel
7. A view AddressListDataView that takes and displays the raw data of your own serialized output (i.e., the same thing that's in the text file)
8. A view AddressListJSONView that takes and displays the JSON data produced by Jackson (i.e., what you'll be writing to that text file)
9. A view AddressListTableView that takes an AddressModel and formats it into a table.
Attachment:- Assignment Files.rar