Skip to content

Commit 4bc9a08

Browse files
robbinspgtobespc
authored andcommitted
Return relative URIs (#76)
* Update version to 1.2.0 * Fix returned uri * Consistent return uris * Generate tar.gz package plus checksums
1 parent 5ddea8f commit 4bc9a08

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

REST-API.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ or from the time of a clear request
1414

1515
1. Create a new metrics collections. Metrics are recorded from collection creation time.
1616
- `POST <context_root>/api/v1/collections`
17-
- returned URI `<context_root>/api/v1/collection/3`
17+
- returned URI `collections/3`
1818
2. Retrieve the metrics from the collection at required interval.
19-
- `GET <context_root>/api/v1/collection/3`
19+
- `GET <context_root>/api/v1/collections/3`
2020
- Process the returned JSON format metrics.
2121
- Optionally clear the metrics from the collection.<br>
22-
`PUT <context_root>/api/v1/collection/3`
22+
`PUT <context_root>/api/v1/collections/3`
2323
3. Delete the collection.
24-
- `DELETE <context_root>/api/v1/collection/3`
24+
- `DELETE <context_root>/api/v1/collections/3`
2525

2626

2727

@@ -62,8 +62,8 @@ Returns a list of the current metrics collections URIs.
6262
Example:
6363
```JSON
6464
{
65-
"collectionUris": ["http://localhost:9080/javametrics/api/v1/collections/0",
66-
"http://localhost:9080/javametrics/api/v1/collections/1"]
65+
"collectionUris": ["collections/0",
66+
"collections/1"]
6767
}
6868
```
6969

@@ -99,7 +99,7 @@ A maximum of 10 collections are allowed at any one time. Return code 400 indicat
9999
* **Content:** The uri of the created **collection**.
100100
Example:
101101
```JSON
102-
{"uri":"http://localhost:9080/javametrics/api/v1/collections/1"}
102+
{"uri":"collections/1"}
103103
```
104104

105105
* **Error Responses**

packageRelease.xml

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
<copy file="rest/target/javametrics-rest-${project.version}.war" todir="${rest.dir}" />
2929

3030
<zip destfile="${dist.dir}/javametrics-release-${project.version}.zip" basedir="${javametrics.dir}" includes="**/**" />
31+
<tar destfile="${dist.dir}/javametrics-release-${project.version}.tar.gz" basedir="${javametrics.dir}" includes="**/**" compression="gzip"/>
32+
<checksum file="${dist.dir}/javametrics-release-${project.version}.zip" algorithm="MD5"/>
33+
<checksum file="${dist.dir}/javametrics-release-${project.version}.zip" algorithm="SHA-512"/>
34+
<checksum file="${dist.dir}/javametrics-release-${project.version}.tar.gz" algorithm="MD5"/>
35+
<checksum file="${dist.dir}/javametrics-release-${project.version}.tar.gz" algorithm="SHA-512"/>
3136

3237
</target>
3338

rest/src/main/java/com/ibm/javametrics/rest/api/MetricsEndpoint.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public Response getContexts(@Context UriInfo uriInfo) {
5151
sb.append(',');
5252
}
5353
sb.append('\"');
54-
UriBuilder builder = uriInfo.getAbsolutePathBuilder();
54+
UriBuilder builder = UriBuilder.fromPath(uriInfo.getPath());
5555
builder.path(Integer.toString(contextId));
5656
URI uri = builder.build();
5757
sb.append(uri.toString());
@@ -69,10 +69,10 @@ public Response newContext(@Context UriInfo uriInfo) {
6969
return Response.status(Status.BAD_REQUEST).build();
7070
}
7171
int contextId = mp.addContext();
72-
UriBuilder builder = uriInfo.getAbsolutePathBuilder();
72+
UriBuilder builder = UriBuilder.fromPath(uriInfo.getPath());
7373
builder.path(Integer.toString(contextId));
7474
URI uri = builder.build();
75-
return Response.created(uri).entity("{\"uri\":\"" + builder.build() + "\"}").build();
75+
return Response.status(Status.CREATED).header("Location", uri).entity("{\"uri\":\"" + uri + "\"}").build();
7676
}
7777

7878
@Path("/{metricsId}")

spring/src/main/java/com/ibm/javametrics/spring/rest/JavametricsRestController.java

+8-14
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
******************************************************************************/
1616
package com.ibm.javametrics.spring.rest;
1717

18-
import java.net.URI;
19-
2018
import org.springframework.http.HttpHeaders;
2119
import org.springframework.http.HttpStatus;
2220
import org.springframework.http.ResponseEntity;
@@ -48,19 +46,16 @@ private void init() {
4846
MetricsProcessor mp = MetricsProcessor.getInstance();
4947

5048
@RequestMapping(produces = "application/json", path = "/collections", method = RequestMethod.GET)
51-
public ResponseEntity<?> getCollections(UriComponentsBuilder ucb) {
49+
public ResponseEntity<?> getCollections() {
5250
Integer[] contextIds = mp.getContextIds();
53-
UriComponents uriComponents = ucb.path("/collections/").build();
54-
String uri = uriComponents.toUriString();
5551

5652
StringBuilder sb = new StringBuilder("{\"collectionUris\":[");
5753
boolean comma = false;
5854
for (Integer contextId : contextIds) {
5955
if (comma) {
6056
sb.append(',');
6157
}
62-
sb.append('\"');
63-
sb.append(uri);
58+
sb.append("\"collections/");
6459
sb.append(contextId);
6560
sb.append('\"');
6661
comma = true;
@@ -71,24 +66,23 @@ public ResponseEntity<?> getCollections(UriComponentsBuilder ucb) {
7166
}
7267

7368
@RequestMapping(produces = "application/json", path = "/collections", method = RequestMethod.POST)
74-
public ResponseEntity<?> createCollection(UriComponentsBuilder ucb) {
69+
public ResponseEntity<?> createCollection() {
7570
if (!initialized) {
7671
init();
7772
}
78-
73+
7974
if (mp.getContextIds().length > 9) {
8075
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
8176
}
82-
77+
8378
int contextId = mp.addContext();
8479

85-
UriComponents uriComponents = ucb.path("/collections/{id}").buildAndExpand(contextId);
86-
URI uri = uriComponents.toUri();
80+
UriComponents uriComponents = UriComponentsBuilder.fromPath("collections/{id}").buildAndExpand(contextId);
8781

8882
HttpHeaders headers = new HttpHeaders();
89-
headers.setLocation(uri);
83+
headers.setLocation(uriComponents.toUri());
9084

91-
String json = new String("{\"uri\":\"" + uri + "\"}");
85+
String json = new String("{\"uri\":\"" + uriComponents.getPath() + "\"}");
9286
return new ResponseEntity<>(json, headers, HttpStatus.CREATED);
9387
}
9488

0 commit comments

Comments
 (0)