In this assignment, you will add a server component to my (not your) solution of homework 3, extending the work from the last lab.
Be sure to change the package name to
edu.sjsu.cs175.hw08, also in the manifest.
First make a way of adding a quiz to the server, using a
POST because this the RESTful way of updating the database. Specifically, make a
http://localhost:8080/testbank/rest/quiz/add with form parameter
questions, a string with multiple lines, where questions are separated by blank lines and correct responses start with a
*. Here is the code to send a file with questions to the server. It uses the Apache HTTP components, which you can download from here. To compile and run, use
javac -Xlint:deprecation -cp path/to/httpcomponents-client-4.3.1/lib/\*:. AddQuestions.java java -cp path/to/httpcomponents-client-4.3.1/lib/\*:. AddQuestions < questions.txt
You only need to use that classpath for the
AddQuestions program, which is not an Android program. In Android, simply import the classes.
QuestionService class from the lab, remove the
init method. Really remove it. Also remove the
makeQuestion helper method (unless you use it).
Next make the GET query
http://localhost:8080/testbank/rest/quiz/latest return the quiz with the largest ID number. You won't know what's in the database that is used for testing, so be sure to implement this correctly. You can make a
MAX query in JPQL.
You'll only need one additional GET query,
http://localhost:8080/testbank/rest/quiz/questions/id, where the ID is returned from the preceding query. That was already done as part of the lab. (Complete the lab if you haven't.) Use JAXB to turn the query result into XML. It won't quite be the same XML as in homework 3, so adapt the client.
Also add a
POST query to send the user's reply to the server when the user has made a selection. The server should track how many times each choice was chosen. Add a
count field to the
Choice class and annotate it so that the preceding GET query will show the updates. Use JPQL to locate the
Choice object that needs to be updated, and simply increment the count. You need not do anything else to get the new value in the database—session bean methods are transactional and automatically store any changes. Also, don't show the count in the Android client. The grader will just run the GET query to see that you did it right.
report.txt into the
Choiceobject? What did you have to do to update the count?
Submit your work in two subfolders
testbank of the
http://10.0.2.2:8080/testbank/quiz/...into the client.
countfield to the
Choiceentity, you will run into a problem with the existing database structure, which doesn't have an associated column. The easiest way around that is to edit
drop-create-tables, redeploy, and re-run the
AddQuestionsprogram. Then you can change back to
create-tablesso you don't have to keep reinitializing the database. Alternatively, you can run
ijas described in the lab, and drop the tables.
path/to/glassfish4/glassfish/domains/domain1/logs/server.log. It is a pain to look through the “stack trace from hell”, but that's what you have to do. It's the one aspect of Java EE that still sucks after all these years.
server.log, call something like
Logger.getLogger("edu.sjsu.cs175").info("id=" + id + ", response=" + response);The message will show up in the logs. If it doesn't, run this command:
asadmin set-log-levels edu.sjsu.cs175 INFOand restart GlassFish.
asadmin deploywith the name of the directory containing
WEB-INF. That's why I asked you to call that directory
testbank, so that it's the same as the app name. Then any recompilation automatically triggers reload of the application. Feel free to use that if you find it easier.
curlcommand. Here is how I tested mine:
curl --data "quizId=27&response=All of them" localhost:8080/testbank/rest/quiz/recordAnswer
It took me three four days of fussing with various frustrating aspects of Android and GlassFish, so don't put this off until the day before the due date.
Due date: Wed. Dec 4 18:00