Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jdk_21_maven/cs/rest/movies-xml/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
165 changes: 165 additions & 0 deletions jdk_21_maven/cs/rest/movies-xml/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.


This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.

0. Additional Definitions.

As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.

"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.

An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.

A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".

The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.

The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.

1. Exception to Section 3 of the GNU GPL.

You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.

2. Conveying Modified Versions.

If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:

a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or

b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.

3. Object Code Incorporating Material from Library Header Files.

The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:

a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.

b) Accompany the object code with a copy of the GNU GPL and this license
document.

4. Combined Works.

You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:

a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.

b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.

c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.

d) Do one of the following:

0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.

1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.

e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)

5. Combined Libraries.

You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:

a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.

b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.

6. Revised Versions of the GNU Lesser General Public License.

The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.

Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.

If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
142 changes: 142 additions & 0 deletions jdk_21_maven/cs/rest/movies-xml/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# movies-xml

<img width="1724" height="848" alt="image" src="https://github.com/user-attachments/assets/3190d5b4-e3e4-4dee-be2a-22c34e5d48d2" />

A movie catalogue REST API whose request and response bodies are **exclusively
`application/xml`**. There is no JSON path anywhere in the API: a write sent as
`application/json` is answered with `415`, and errors come back as XML too.

The project is a case study for research on REST API fuzzing. What is being measured is
whether a fuzzer can build XML request bodies that honour the `xml` metadata of an
OpenAPI schema — attributes instead of elements, a root element whose name differs from
the class name, and a wrapped list. The database therefore starts **empty**: nothing is
preloaded, so every row either arrives through a well formed XML request or through a
direct SQL insert.

The one accepted shape of a movie document is:

```xml
<movie id="7" year="1999">
<title>The Matrix</title>
<genre>SCIFI</genre>
<rating>8.7</rating>
<director nationality="US">
<name>Lana Wachowski</name>
</director>
<cast>
<actor billing="1"><name>Keanu Reeves</name></actor>
<actor billing="2"><name>Laurence Fishburne</name></actor>
</cast>
</movie>
```

`id` and `year` are attributes, `nationality` is an attribute of the nested `<director>`,
and the cast is a `<cast>` wrapper around `<actor>` elements. Nothing else is accepted:
spelling `id` or `year` as elements, or hanging `<actor>` straight off `<movie>`, is a
`400`. On creation a supplied `id` is ignored and the server assigns its own.

## Build and run

Java 21 and Maven are required.

```bash
mvn clean package
java -jar target/movies-xml-sut.jar
```

The app listens on port 8080 and stores everything in an in-memory H2 database that is
created at startup and dropped at shutdown. The H2 console is disabled.

## Endpoints

Seven, all under `/movies`:

| Method | Path | Responses |
|---|---|---|
| `POST` | `/movies` | 201 + `Location`, 400, 409, 415 |
| `GET` | `/movies` | 200 (`<movies>`), 400 |
| `GET` | `/movies/{id}` | 200, 404 |
| `PUT` | `/movies/{id}` | 200, 400, 404, 409, 415 |
| `PATCH` | `/movies/{id}` | 200, 400, 404, 409, 415 |
| `DELETE` | `/movies/{id}` | 204, 404 |
| `GET` | `/movies/stats` | 200 (`<stats>`) |

Two more answers are not tied to any one endpoint, because they come from the exception
handler rather than from a controller: `405` for a method the path does not support and
`406` for a client that asks for anything other than `application/xml`. Every endpoint can
produce both, and the schema says so on every operation.

The handler also turns anything unexpected into a `500`, and that one is deliberately left
out of the schema. This is a fuzzing target: a `500` is a fault worth reporting, not an
answer a tool should be told to expect. No request is known to produce one.

Anything in the `{id}` position that is not a stored movie is a `404`, including an id that
is not a number at all (`/movies/abc`), one too large for a 64 bit integer, and a blank one
(`/movies/%20`). The `400` on `GET /movies` is for the query parameters, which are part of
the request rather than of the path. The one gap is a URI Tomcat refuses to parse — a null
byte or an encoded traversal, as in `/movies/%00` — which is rejected with an HTML `400`
before the application runs at all.

`GET /movies` takes `genre`, `titleContains`, `minYear`, `maxYear`, `minRating` and
`sort` (`title`, `year` or `rating`); they are optional and combinable.

`PATCH` applies only the fields the document actually carries, and it tells an absent
`<cast>` (the cast is left alone) apart from an empty `<cast></cast>` (the cast is
cleared).

## The OpenAPI schema

The schema is served as JSON at `/v3/api-docs` — it is the schema, not part of the API —
and Swagger UI renders it at `/swagger-ui.html`.

A snapshot of it is committed as [`openapi.json`](openapi.json), so the exact contract
can be read, diffed and reviewed without starting the application. It is what a client
has to go on, including the `xml` metadata: which properties are attributes, which
element names differ from the property names, and that `cast` is a wrapped list.

**`openapi.json` is generated. Never edit it by hand.** Regenerate it whenever the
endpoints, the DTOs or their annotations change: start the application, then run this
from the repository root and commit the result along with the change that caused it.

```powershell
python -c "import json,urllib.request; d=json.load(urllib.request.urlopen('http://localhost:8080/v3/api-docs')); open('openapi.json','w',newline='\n',encoding='utf-8').write(json.dumps(d,indent=2,ensure_ascii=False)+'\n')"
```

It writes two-space indentation and LF endings, so a regeneration that changed nothing
produces an empty diff. Piping `curl` into `python` on Windows PowerShell does not work
here — the pipeline prepends a BOM that `json.load` rejects — which is why the command
downloads the document itself.

## Creating a movie

```bash
curl -i -X POST http://localhost:8080/movies \
-H 'Content-Type: application/xml' \
-d '<movie year="1999"><title>The Matrix</title><genre>SCIFI</genre><rating>8.7</rating><director nationality="US"><name>Lana Wachowski</name></director><cast><actor billing="1"><name>Keanu Reeves</name></actor></cast></movie>'
```

```
HTTP/1.1 201
Location: http://localhost:8080/movies/1
Content-Type: application/xml

<movie id="1" year="1999">...</movie>
```

Errors use a single document shape:

```xml
<error status="404">
<message>movie 999 not found</message>
</error>
```

## Rules worth knowing

- No two movies may share a title and a year (title compared ignoring case and
surrounding whitespace) — `409`.
- `billing` values must be unique inside a cast — `400`.
- A movie rated above 9.0 must list at least one actor — `400`.
- `nationality`, when given, is exactly two upper case letters — `400`.
- Statistics skip genres with no movies, and average only the movies that carry a
rating.
Loading
Loading