Web程序辅导、辅导Java编程语言

- 首页 >> Database
SJSU CS 218 HW RESTful Web Svc on GAE FALL 2021
REMINDER: Each homework is individual. "Every single byte must come from you." Cut&paste from others is not
allowed. Keep your answer and source code to yourself only - never post or share them to any site in any way.
Replace and , or YourName and L3SID, with your own name and last 3 digit of your student ID,
respectively.
Theme: Java-based REST server + NoSQL (Cloud Datastore) on Google App Engine

Description
REST server: create a Java-based RESTful Web Service server on top of Google App Engine (GAE) standard environment
or flexible environment. The server retrieves data from, and persists data to, Google Cloud Datastore according to the
functional matrix specified later. You may build your REST server by using any Java-based technologies/frameworks,
such as using Servlet directly, or Jax-RS or Spring, etc. See Design options later.

REST client: you can use any REST client, such as RESTClient (Firefox), soapUI, Postman (dark theme only), curl, etc.
Do NOT use Postman as the REST client unless you change to dark theme.

Data objects
There are two types of objects (two “kinds” of object in Cloud Datastore):
owner
int id // user-generated unique value across all instances of this type
String name
car
int id // user-generated unique value across all instances of this type
int status
Float price
NOTE: the id property is a user-defined property. Each entity still has its own built-in unique identifier with an auto-
generated value; you are not allowed to define the value of the built-in unique identifier.

Format of HTTP Request and Response
You can choose either XML or JSON. The HTTP request and response must include the proper header “Content-Type”
with value “application/xml” or “application/json”. The exact representation in XML and JSON are as follows:
XML JSON

10
John

{ "id": 10,
"name": "John"
}

1
3
3456.78

{ "id": 1,
"status": 3,
"price": 3456.78
}


{ "ownerList":
[ {"id": 10, "name": "John"},
2



…,
{…} ]
}





{ "carList":
[ {"id": 1, "status": 3, "price": 3456.78},
…,
{…} ]
}

Environment Setup
Connect to https://console.cloud.google.com/, create a project with - as the suffix of the
project ID (not project name), e.g., rest-demo123, which implies after deployment the URL of your web service is
https://rest-demo123.REGION_ID.r.appspot.com, e.g., https://rest-demo123.wl.r.appspot.com
In the project, enable the client side library Google Cloud Datastore API (and others if needed), and set the
billing account to the Google Education Grant you received.

Additional requirements
REST resource (URI) must start with /cs218fa21/rest/.. . For example, the entire URL would be
http://server[:port]/cs218fa21/rest/… The screenshots (explained later) must include the proper resource (URI).
Any HTTP response from your app must include a proper header “Content-Type” with value “application/xml” or
“application/json”, and a header “CS218FA21-WebSvc” whose value is your name and L3SID
CS218FA21-WebSvc: Demo 123
Any screenshot must include these headers.
You are not allowed to define the value of the internal built-in identifier for each entity. Have the system
automatically generate the value.
Google Cloud Datastore: You must use “Firestore in datastore mode”. Not the legacy datastore.
o Import Java package com.google.cloud.datastore, not com.google.appengine.api.datastore.
Keep your web site on until the instructor finishes grading (i.e., post grade for HW) – deduction if site is not up!
Note: You do NOT need an interface like http://thomas-bayer.com/restgate/index.do which has “built-in” REST client.
The homework asks for the core of REST server (i.e., be able to handle GET, PUT, POST, and DELETE). You can choose
any existing REST client to communicate with your REST server.

Questions
Q1.
a. List technologies, software (including version), and platform for dev tools, REST client, and REST server.
b. How did you build your REST server? JDK version? any external jars? Maven or Gradle?
c. Is the format of the data object based on XML or JSON?
d. Indicate the public URL of your web site on appspot.com. No additional setup (e.g., additional HTTP header,
etc.) is allowed.
e. A sample HTTP POST request URI and request body to create a new owner based on the XML format or JSON
format (depending on your answer to c). No additional setup (e.g., additional HTTP header, etc.) is allowed.
f. A sample HTTP PUT request URI and request body to update one property (“partial update”, explained later) of
an existing car based on the XML format or JSON format (depending on your answer to c). No additional setup
(e.g., additional HTTP header, etc.) is allowed.
3

For example,
a.
Dev tools: Eclipse Java EE 2020-6 on Windows 10
REST Client: soapUI 5.6.0 on Windows 10
REST Server: Servlet, JAXB on Windows 10
b. REST Server: use Servlet directly without Spring. One single Servlet for both owner and car.
JDK 11.0.11. No external jars. No Maven nor Gradle.
c. Based on XML
d. https://rest-demo123.wl.r.appspot.com/cs218fa21/rest/
no additional setup (no additional request header) is needed.
(NOTE: URI portion in Functionality matrix must be /cs218fa21/rest/…)
e.
request URI: POST /cs218fa21/rest/owner
request body:

10
John

f.
request URI: PUT /cs218fa21/rest/car/10
request body:

1234.56


Q2. (60 pts)
Functionality matrix of the REST server: (URI “/…/rest” means “/cs218fa21/rest”)
HTTP method + URI Description HTTP status -
successful
HTTP status –err, in
addition to 400, 500
GET /…/rest/owner/n Retrieve owner with id n.
Resp body: XML or JSON
OK (200) invalid id:
Not found (404)
GET /…/rest/car/m Retrieve car with id m.
Resp body: XML or JSON
OK (200) invalid id:
Not found (404)
POST /…/rest/owner Create a new owner.
Req body: XML or JSON
Resp header: include Location header
Created (201) duplicated id:
Conflict (409)
POST /…/rest/car Create a new car.
Req body: XML or JSON
Resp header: include Location header
Created (201) duplicated id:
Conflict (409)
PUT /…/rest/owner/n Update owner with id n.
Req body: XML or JSON (allow partial
properties, except id, to be updated)
OK (200) invalid id:
Not found (404)
4
PUT /…/rest/car/m Update car with id m.
Req body: XML or JSON (allow partial
properties, except id, to be updated)
OK (200) invalid id:
Not found (404)
DELETE /…/rest/owner/n Delete owner with id n OK (200) invalid id:
Not found (404)
DELETE /…/rest/car/m Delete car with id m OK (200) invalid id:
Not found (404)
GET /…/rest/owner Retrieve all owners.
Resp body: XML or JSON. Format:
…, or
{“ownerList”: [{…}, {…}]}
OK (200) empty result set:
Not found (404)
GET /…/rest/car Retrieve all cars.
Resp body: XML or JSON. Format:
…, or {“carList”: [{…},
{…}]}
OK (200) empty result set:
Not found (404)

For each of the function matrix,
add the status column and specify its implementation status (i.e., completed, partially completed, not
implemented)
If it’s completed
o include before screenshot of Datastore entities on GAE (not local server)
o error case: include screenshot of REST request and response (method, URI, HTTP status code, HTTP
headers)
highlight method, URI, HTTP status code, Content-Type header, and CS218FA21-WebSvc header
in the screenshot
o success case: include screenshot of REST request and response (method, URI, HTTP status code, HTTP
headers)
highlight method, URI, HTTP status code, Content-Type header, CS218FA21-WebSvc header, and
Location header in the screenshot
POST: need to show HTTP response headers which include the Location header
PUT: need to demo partial property update (i.e., HTTP request only includes a single property)
o include after screenshot of Datastore entities on GAE (not local server), if it’s PUT, POST, or DELETE
highlight the newly-inserted object, or modified property in the screenshot
if it’s partially completed, indicate exactly which portion is completed and which is not

Q3. (2 pts)
List known issues if any
Any additional unique design or features you are proud of

Q4. (15 pts)
Use a http load tool of your choice (JMeter, Httpperf, Locust.io, etc.) to generate HTTP traffic (both read and write
requests) against your REST server on GAE so that there will be more than one instance of the REST server running.
Design your load/traffic pattern so that you gradually increase the load and your load should stop after a while.
Ensure you get no more than 4 instances, and very low http 4xx and 5xx errors to simplify your analysis. If you have
5
more than 4 instance or high http 4xx or 5xx errors, it means your load is too heavy. The ideal curve in the
“Instances” graph is a bell curve shape - the number of instances starts from 1, gradually increases (scale out), then
it stays relatively the same, and then (when the load decreases/drops) the gradually reduces back (scale in).

For details, refer to
https://cloud.google.com/appengine/docs/standard
https://cloud.google.com/appengine/docs/standard/java/how-instances-are-managed

a. Name the load tool and its configuration (traffic pattern, total # of requests, # of read, # of writes, length of time, #
of threads or users, requests/sec, URL, etc.).
b. Scale out: correlate your data and identify the time frame GAE starts a new instance of REST server and the
corresponding hits rate (requests/sec, etc.) during this time frame. Include traffic data from both GAE and the load
tool, with screenshots, to support your conclusion.
o Load tool: screenshots of hits rate related graph or data, highlight the time frame.
o GAE: screenshot of the graph “Summary: count/sec” (or Requests by type: requests/sec), highlight the
corresponding time frame.
o GAE: screenshot of the graph “Instances: total instances”, highlight the corresponding time frame.
Screenshot of list of instances and their statistics (QPS, Requests, Start time) for each instance.
c. Network load balance among multiple REST server instances: show the QPS, requests, start time of each GAE
instance. Correlate the total number of requests across all instances on GAE with the total number of requests from
your load tool, and explain any discrepancies if any.
o Load tool: screenshots of the summary/result which includes total requests, timing statistics, errors, etc.
o GAE: screenshot of list of instances and their statistics (QPS, requests, start time) for each instance.

Source code (23 pts)
Submit source files as a separate .zip file. zip the project directory to include .java sources, web.xml, and other config/xml
files. Do not include .class, .jar, .war files.

Submission
Submit the followings as separate files to Canvas
CS218_HW3_ (.pdf, .doc, or .docx): the report consists of answers and screenshots to questions
specified in Question.
o You receive no credit if your report is not .pdf, .doc, or .docx.
o Screenshots must include required information (URI, Content-Type, CS218FA21-WebSvc, and Location
headers, etc.). No credit if you do not follow requirements (naming, URI, etc.).
o If a screenshot is unreadable (e.g., too small or blurry), it will be treated as if you did not turn in that
screenshot.
Any screenshots from non-dark theme of the REST client Postman are not accepted.
o Keep your web site on until the instructor unmutes HW grade – deduction if site not up!
Zip corresponding GAE logs file (GCP console ? Logging ? Logs, click “Down logs” in JSON format)
CS218_HW3_.zip: zip the project directory to include .java sources, and config-related files (e.g.,
web.xml, appengine-web.xml (JDK 8) or app.yaml (JDK 11), pom.xml, build.gradle, etc.). Do not
include .class, .jar, .war files.
Keep your web site on until the instructor finishes grading (i.e., post grade for HW) – deduction if site is not up!
6
The ISA and/or instructor leave feedback to your homework as comments and/or annotated comment. To access
annotated comment, click “view feedback” button. For details, see the following URL:
https://guides.instructure.com/m/4212/l/352349-how-do-i-view-annotation-feedback-comments-from-my-
instructor-directly-in-my-assignment-submission