-
Notifications
You must be signed in to change notification settings - Fork 30
Add JAX-RS PATCH annotation #36
Changes from 11 commits
e5c090e
d582c3a
f093e10
203e4a6
48dafb3
a1fac9f
00de0c5
7ea7dec
20ef4a8
32acdeb
f8347b0
7931147
84431c4
d564ac3
bb8be52
f388ee2
ffcd9d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,11 +34,15 @@ class ClientServiceSpec(contextRoot: String, servicePort: Int) | |
val resourceOne = injector.getInstance(classOf[ResourceOne]) | ||
val resourceTwo = injector.getInstance(classOf[ResourceTwo]) | ||
|
||
val jsonNewOne = JsonOne.create("New Json", "Hola") | ||
val jsonOne = JsonOne.create("LocalOne", "Hi") | ||
resourceOne.echo(jsonOne) mustBe jsonOne | ||
resourceOne.patch(jsonOne) mustBe jsonNewOne | ||
|
||
val jsonNewTwo = JsonTwo.create("New Json", "Hola") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you please differentiate |
||
val jsonTwo = JsonTwo.create("LocalTwo", "Howdy") | ||
resourceTwo.echo(jsonTwo) mustBe jsonTwo | ||
resourceTwo.patch(jsonTwo) mustBe jsonNewTwo | ||
} | ||
|
||
it("each client gets its own unique object mapper") { | ||
|
@@ -53,7 +57,6 @@ class ClientServiceSpec(contextRoot: String, servicePort: Int) | |
mapperTwo.isEnabled(SerializationFeature.INDENT_OUTPUT) must be(true) | ||
} | ||
|
||
|
||
it("provides default object mapper") { | ||
val injector = getInjector(List(new ResourceOneModule, new ResourceTwoModule)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,30 @@ To include the correlation id in the catalina.out file using log4j, update the l | |
.. |usageLink| replace:: More on this later | ||
.. _usageLink: `Usage`_ | ||
|
||
PATCH annotation | ||
-------------- | ||
|
||
As of Version 2.5 we have added a PATCH annotation. JAX-RS does not have a PATCH annotation for | ||
supporting HTTP patch method like it does for others like GET or POST. The PATCH annotation was | ||
added to Beadledom so that consumers of Beadledom can use the patch HTTP method. For more details on | ||
the PATCH method visit the PATCH RFC_. | ||
|
||
To use the PATCH method and annotation for your resource, simply add the PATCH annotation above your | ||
resource like you would with a GET or POST method. Here is an example of a PATCH method of an | ||
interface. | ||
|
||
.. code-block:: java | ||
|
||
@PATCH | ||
@Path("path/to/patch") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response patch( | ||
@PathParam("id") final Long id, | ||
@ApiParam(value = "changes to make to the object with the specified id") | ||
PatchObject patchObject); | ||
|
||
.. _RFC: https://tools.ietf.org/html/rfc5789 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about this?
|
||
Download | ||
-------- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.cerner.beadledom.jaxrs; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.ws.rs.HttpMethod; | ||
|
||
@Target({ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@HttpMethod("PATCH") | ||
public @interface PATCH { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you please add some javadoc to this. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,10 @@ public class FakeModel { | |
@JsonProperty("inner_models") | ||
public List<FakeInnerModel> innerModels; | ||
|
||
public FakeModel() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you add a default constructor? the only place I see you using it is here where you use the constructor that already exist. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default constructer and the setters were added to make the creating of the FakeModel more like the builder pattern. It is used in the Spec at the recommendation of Brian. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We didn't break of the existing tests using this model did we? I can't imagine so but you never know. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope all tests pass even after model change |
||
|
||
} | ||
|
||
public FakeModel( | ||
String id, String name, int times, List<String> tags, List<FakeInnerModel> innerModels) { | ||
this.id = id; | ||
|
@@ -37,6 +41,32 @@ public FakeModel( | |
this.innerModels = innerModels; | ||
} | ||
|
||
public FakeModel setId(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public FakeModel setName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public FakeModel setTimes(int times) { | ||
this.times = times; | ||
return this; | ||
} | ||
|
||
public FakeModel setTags(List<String> tags) { | ||
this.tags = tags; | ||
return this; | ||
} | ||
|
||
public FakeModel setInnerModels( | ||
List<FakeInnerModel> innerModels) { | ||
this.innerModels = innerModels; | ||
return this; | ||
} | ||
|
||
@JsonProperty("id") | ||
public String getId() { | ||
return id; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.cerner.beadledom.jaxrs.provider; | ||
|
||
import com.cerner.beadledom.jaxrs.PATCH; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Path("/fakeResource") | ||
public class FakeResource { | ||
|
||
@PATCH | ||
@Path("/Patch") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
public Response fakePatch(FakeModel model) { | ||
model.setId("newId"); | ||
model.setName("newName"); | ||
return Response.ok(model).build(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just want to confirm this is necessary because checkstyle is expecting the classname to be
Patch
?If JAX-RS hadn't already set the standard for these annotations we would name it that way, but
PATCH
is correct in following the standard of the other JAX-RS annotations.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep that is the reason.