From e5c090e1e9f31728dda1b53a84d22ba53fa2db84 Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Wed, 10 May 2017 15:45:37 -0500 Subject: [PATCH 01/17] Add JAX-RS PATCH annotation --- CHANGELOG.md | 5 +- CONTRIBUTORS.md | 2 + checkstyle-suppressions.xml | 1 + .../com/cerner/beadledom/jaxrs/PATCH.java | 14 ++++ .../beadledom/jaxrs/provider/FakeModel.java | 30 ++++++++ .../jaxrs/provider/FakeResource.java | 24 ++++++ .../cerner/beadledom/jaxrs/PATCHSpec.scala | 77 +++++++++++++++++++ 7 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java create mode 100644 jaxrs/src/test/java/com/cerner/beadledom/jaxrs/provider/FakeResource.java create mode 100644 jaxrs/src/test/scala/com/cerner/beadledom/jaxrs/PATCHSpec.scala diff --git a/CHANGELOG.md b/CHANGELOG.md index d66c15b4..f0a88588 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,12 @@ ### Enhancements * Disable the stagemonitor web widget in the service generated by the archetype, as the default configuration. +* Added toString implementation to DelegatingGenericResponse and BuiltGenericResponse. +* Added a PATCH annotation. ### Defects Corrected * Cleaned up dependencies and fixed few minor issues with generated code in archetype. -### Enhancements -* Added toString implementation to DelegatingGenericResponse and BuiltGenericResponse. - ## 2.4 - 16 Feb 2017 ### Additions diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 150959be..0d7fb97a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -12,6 +12,7 @@ * Jason Gassel [@jpeg][jason-gassel] * Andy Nelson [@anelson425][andy-nelson] * Bryan Baugher [@bbaugher][bryan-baugher] +* Eric Christensen [@EricChristensen][eric-christensen] [john-leacox]: https://github.com/johnlcox [jacob-williams]: https://github.com/brokensandals @@ -25,3 +26,4 @@ [jason-gassel]: https://github.com/jpeg [andy-nelson]: https://github.com/anelson425 [bryan-baugher]: https://github.com/bbaugher +[eric-christensen]: https://github.com/EricChristensen diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml index 5fbbe529..e5d93af7 100644 --- a/checkstyle-suppressions.xml +++ b/checkstyle-suppressions.xml @@ -4,4 +4,5 @@ + diff --git a/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java b/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java new file mode 100644 index 00000000..6c0e9ef4 --- /dev/null +++ b/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java @@ -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 { +} diff --git a/jaxrs/src/test/java/com/cerner/beadledom/jaxrs/provider/FakeModel.java b/jaxrs/src/test/java/com/cerner/beadledom/jaxrs/provider/FakeModel.java index 28e0028b..00840989 100644 --- a/jaxrs/src/test/java/com/cerner/beadledom/jaxrs/provider/FakeModel.java +++ b/jaxrs/src/test/java/com/cerner/beadledom/jaxrs/provider/FakeModel.java @@ -28,6 +28,10 @@ public class FakeModel { @JsonProperty("inner_models") public List innerModels; + public FakeModel() { + + } + public FakeModel( String id, String name, int times, List tags, List 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 tags) { + this.tags = tags; + return this; + } + + public FakeModel setInnerModels( + List innerModels) { + this.innerModels = innerModels; + return this; + } + @JsonProperty("id") public String getId() { return id; diff --git a/jaxrs/src/test/java/com/cerner/beadledom/jaxrs/provider/FakeResource.java b/jaxrs/src/test/java/com/cerner/beadledom/jaxrs/provider/FakeResource.java new file mode 100644 index 00000000..a543c733 --- /dev/null +++ b/jaxrs/src/test/java/com/cerner/beadledom/jaxrs/provider/FakeResource.java @@ -0,0 +1,24 @@ +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(); + } + +} diff --git a/jaxrs/src/test/scala/com/cerner/beadledom/jaxrs/PATCHSpec.scala b/jaxrs/src/test/scala/com/cerner/beadledom/jaxrs/PATCHSpec.scala new file mode 100644 index 00000000..75e7e4ab --- /dev/null +++ b/jaxrs/src/test/scala/com/cerner/beadledom/jaxrs/PATCHSpec.scala @@ -0,0 +1,77 @@ +package com.cerner.beadledom.jaxrs + +import com.cerner.beadledom.jaxrs.provider.{FakeModel, FakeResource} + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider + +import org.jboss.resteasy.core.Dispatcher +import org.jboss.resteasy.mock.{MockDispatcherFactory, MockHttpRequest, MockHttpResponse} +import org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory +import org.scalatest._ +import org.scalatest.mock.MockitoSugar + +import java.io._ + +import scala.collection.JavaConverters._ +import javax.ws.rs.core.MediaType + +/** + * Spec tests for {@link PATCH}. + * + * @author Eric Christensen + */ +class PATCHSpec extends FunSpec with BeforeAndAfterAll with ShouldMatchers with MockitoSugar { + + val dispatcher: Dispatcher = MockDispatcherFactory.createDispatcher() + val noDefaults: POJOResourceFactory = new POJOResourceFactory(classOf[FakeResource]) + dispatcher.getRegistry.addResourceFactory(noDefaults) + dispatcher.getProviderFactory.registerProvider(classOf[JacksonJsonProvider]) + + describe("PATCH") { + it("calls PATCH resource without error") { + + val model = new FakeModel() + .setId("id") + .setName("name") + .setTimes(10) + .setTags(List.empty[String].asJava) + .setInnerModels(List.empty[FakeModel.FakeInnerModel].asJava) + + val mapper = new ObjectMapper + val request: MockHttpRequest = MockHttpRequest.create("PATCH", "/fakeResource/Patch") + request.contentType(MediaType.APPLICATION_JSON) + request.content(new ByteArrayInputStream(mapper.writeValueAsBytes(model))) + + val response: MockHttpResponse = new MockHttpResponse() + dispatcher.invoke(request, response) + + response.getStatus shouldBe 200 + } + + it("should change the request model fields") { + + val model = new FakeModel() + .setId("id") + .setName("name") + .setTimes(10) + .setTags(List.empty[String].asJava) + .setInnerModels(List.empty[FakeModel.FakeInnerModel].asJava) + + val mapper = new ObjectMapper + val request: MockHttpRequest = MockHttpRequest.create("PATCH", "/fakeResource/Patch") + request.contentType(MediaType.APPLICATION_JSON) + request.content(new ByteArrayInputStream(mapper.writeValueAsBytes(model))) + + val response: MockHttpResponse = new MockHttpResponse() + dispatcher.invoke(request, response) + + response.getStatus shouldBe 200 + + val newModel: FakeModel = mapper.readValue(response.getContentAsString, classOf[FakeModel]) + newModel.name shouldBe "newName" + newModel.id shouldBe "newId" + newModel.times shouldBe 10 + } + } +} From d582c3a78cc5f6ca53ed2ee53d7c9507bdb69565 Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Mon, 15 May 2017 16:52:25 -0500 Subject: [PATCH 02/17] Use PATCH on a stood up service --- .../example-api/pom.xml | 4 ++++ .../beadledom/client/example/ResourceOne.java | 6 +++++ .../beadledom/client/example/ResourceTwo.java | 6 +++++ .../client/example/model/JsonOne.java | 23 ++++++++++++++++++- .../client/example/model/JsonTwo.java | 23 ++++++++++++++++++- .../client/example/ResourceOneImpl.java | 8 +++++++ .../client/example/ResourceTwoImpl.java | 8 +++++++ .../beadledom/client/ClientServiceSpec.scala | 5 +++- 8 files changed, 80 insertions(+), 3 deletions(-) diff --git a/client/beadledom-client-example/example-api/pom.xml b/client/beadledom-client-example/example-api/pom.xml index 242e02f7..2926686c 100644 --- a/client/beadledom-client-example/example-api/pom.xml +++ b/client/beadledom-client-example/example-api/pom.xml @@ -25,5 +25,9 @@ javax.ws.rs javax.ws.rs-api + + com.cerner.beadledom + beadledom-jaxrs + diff --git a/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/ResourceOne.java b/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/ResourceOne.java index b6016d20..1d6f3556 100644 --- a/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/ResourceOne.java +++ b/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/ResourceOne.java @@ -1,6 +1,7 @@ package com.cerner.beadledom.client.example; import com.cerner.beadledom.client.example.model.JsonOne; +import com.cerner.beadledom.jaxrs.PATCH; import javax.ws.rs.Consumes; import javax.ws.rs.GET; @@ -23,4 +24,9 @@ public interface ResourceOne { @Produces("application/json") @Consumes("application/json") JsonOne echo(JsonOne json); + + @PATCH + @Produces("application/json") + @Consumes("application/json") + JsonOne patch(JsonOne json); } diff --git a/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/ResourceTwo.java b/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/ResourceTwo.java index b0bdb5d1..3edfe506 100644 --- a/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/ResourceTwo.java +++ b/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/ResourceTwo.java @@ -1,6 +1,7 @@ package com.cerner.beadledom.client.example; import com.cerner.beadledom.client.example.model.JsonTwo; +import com.cerner.beadledom.jaxrs.PATCH; import javax.ws.rs.Consumes; import javax.ws.rs.GET; @@ -23,4 +24,9 @@ public interface ResourceTwo { @Produces("application/json") @Consumes("application/json") JsonTwo echo(JsonTwo json); + + @PATCH + @Produces("application/json") + @Consumes("application/json") + JsonTwo patch(JsonTwo json); } diff --git a/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/model/JsonOne.java b/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/model/JsonOne.java index 45104904..35d8115d 100644 --- a/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/model/JsonOne.java +++ b/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/model/JsonOne.java @@ -2,6 +2,8 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.google.auto.value.AutoValue; /** @@ -10,8 +12,13 @@ * @author John Leacox */ @AutoValue +@JsonDeserialize(builder = AutoValue_JsonOne.Builder.class) public abstract class JsonOne { + public static Builder builder() { + return new AutoValue_JsonOne.Builder(); + } + /** * Creates a new instance of JsonOne. */ @@ -19,7 +26,10 @@ public abstract class JsonOne { public static JsonOne create( @JsonProperty("one") String one, @JsonProperty("hello") String hello) { - return new AutoValue_JsonOne(one, hello); + return builder() + .setOne(one) + .setHello(hello) + .build(); } @JsonProperty("one") @@ -27,4 +37,15 @@ public static JsonOne create( @JsonProperty("hello") public abstract String getHello(); + + @AutoValue.Builder + @JsonPOJOBuilder(withPrefix = "set") + public abstract static class Builder { + + public abstract Builder setOne(String one); + + public abstract Builder setHello(String hello); + + public abstract JsonOne build(); + } } diff --git a/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/model/JsonTwo.java b/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/model/JsonTwo.java index 113f073d..6c15da55 100644 --- a/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/model/JsonTwo.java +++ b/client/beadledom-client-example/example-api/src/main/java/com/cerner/beadledom/client/example/model/JsonTwo.java @@ -2,6 +2,8 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.google.auto.value.AutoValue; /** @@ -10,8 +12,13 @@ * @author John Leacox */ @AutoValue +@JsonDeserialize(builder = AutoValue_JsonTwo.Builder.class) public abstract class JsonTwo { + public static Builder builder() { + return new AutoValue_JsonTwo.Builder(); + } + /** * Creates a new instance of JsonOne. */ @@ -19,7 +26,10 @@ public abstract class JsonTwo { public static JsonTwo create( @JsonProperty("two") String two, @JsonProperty("hello") String hello) { - return new AutoValue_JsonTwo(two, hello); + return builder() + .setTwo(two) + .setHello(hello) + .build(); } @JsonProperty("two") @@ -27,4 +37,15 @@ public static JsonTwo create( @JsonProperty("hello") public abstract String getHello(); + + @AutoValue.Builder + @JsonPOJOBuilder(withPrefix = "set") + public abstract static class Builder { + + public abstract Builder setTwo(String two); + + public abstract Builder setHello(String hello); + + public abstract JsonTwo build(); + } } diff --git a/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceOneImpl.java b/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceOneImpl.java index 958c3eb2..41736309 100644 --- a/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceOneImpl.java +++ b/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceOneImpl.java @@ -17,4 +17,12 @@ public JsonOne get() { public JsonOne echo(JsonOne json) { return json; } + + @Override + public JsonOne patch(JsonOne json) { + return json.builder() + .setHello("Hola") + .setOne("New Json") + .build(); + } } diff --git a/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceTwoImpl.java b/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceTwoImpl.java index d5a8ef28..7d13803a 100644 --- a/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceTwoImpl.java +++ b/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceTwoImpl.java @@ -17,4 +17,12 @@ public JsonTwo get() { public JsonTwo echo(JsonTwo json) { return json; } + + @Override + public JsonTwo patch(JsonTwo json) { + return json.builder() + .setHello("Hola") + .setTwo("New Json") + .build(); + } } diff --git a/client/beadledom-client-test/src/test/scala/com/cerner/beadledom/client/ClientServiceSpec.scala b/client/beadledom-client-test/src/test/scala/com/cerner/beadledom/client/ClientServiceSpec.scala index dce7d318..cf6ec0fe 100644 --- a/client/beadledom-client-test/src/test/scala/com/cerner/beadledom/client/ClientServiceSpec.scala +++ b/client/beadledom-client-test/src/test/scala/com/cerner/beadledom/client/ClientServiceSpec.scala @@ -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") 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)) From f093e1030266a20114f220ba4ec3f0f4d4c366a4 Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Tue, 16 May 2017 09:45:33 -0500 Subject: [PATCH 03/17] Move dependency to alphabetical spot --- client/beadledom-client-example/example-api/pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/beadledom-client-example/example-api/pom.xml b/client/beadledom-client-example/example-api/pom.xml index 2926686c..e5f5bbcb 100644 --- a/client/beadledom-client-example/example-api/pom.xml +++ b/client/beadledom-client-example/example-api/pom.xml @@ -12,6 +12,10 @@ Beadledom Resteasy Client Example API + + com.cerner.beadledom + beadledom-jaxrs + com.fasterxml.jackson.core jackson-annotations @@ -25,9 +29,5 @@ javax.ws.rs javax.ws.rs-api - - com.cerner.beadledom - beadledom-jaxrs - From 203e4a63a379f0056b09e5a9e3c8ec527a44d6fa Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Tue, 16 May 2017 15:26:23 -0500 Subject: [PATCH 04/17] little change to see config changes --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0a88588..a78ee202 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ ### Enhancements * Disable the stagemonitor web widget in the service generated by the archetype, as the default configuration. * Added toString implementation to DelegatingGenericResponse and BuiltGenericResponse. -* Added a PATCH annotation. +* Added a PATCH annotation because JAX-rs does not have one. ### Defects Corrected * Cleaned up dependencies and fixed few minor issues with generated code in archetype. From 48dafb39c647b45e9fee3f4e749bf787ab9b2711 Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Tue, 16 May 2017 15:49:39 -0500 Subject: [PATCH 05/17] extra newline --- .../java/com/cerner/beadledom/jaxrs/provider/FakeResource.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jaxrs/src/test/java/com/cerner/beadledom/jaxrs/provider/FakeResource.java b/jaxrs/src/test/java/com/cerner/beadledom/jaxrs/provider/FakeResource.java index a543c733..526c308c 100644 --- a/jaxrs/src/test/java/com/cerner/beadledom/jaxrs/provider/FakeResource.java +++ b/jaxrs/src/test/java/com/cerner/beadledom/jaxrs/provider/FakeResource.java @@ -20,5 +20,4 @@ public Response fakePatch(FakeModel model) { model.setName("newName"); return Response.ok(model).build(); } - } From a1fac9f9a46f0a4ffe59c34ce5ec9c528c42ebb5 Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Tue, 16 May 2017 16:13:54 -0500 Subject: [PATCH 06/17] add to jaxrs.rst --- docs/source/manual/jaxrs.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/source/manual/jaxrs.rst b/docs/source/manual/jaxrs.rst index 5d218e89..b4cb13c1 100644 --- a/docs/source/manual/jaxrs.rst +++ b/docs/source/manual/jaxrs.rst @@ -85,3 +85,10 @@ or return customCorrelationIdName; } } + +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. From 00de0c59a75dd6128591cc0e796da777e275d774 Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Tue, 16 May 2017 16:49:18 -0500 Subject: [PATCH 07/17] add example and link to rfc for patch description --- docs/source/manual/jaxrs.rst | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/docs/source/manual/jaxrs.rst b/docs/source/manual/jaxrs.rst index b4cb13c1..91e0111c 100644 --- a/docs/source/manual/jaxrs.rst +++ b/docs/source/manual/jaxrs.rst @@ -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 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 + Download -------- @@ -85,10 +109,3 @@ or return customCorrelationIdName; } } - -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. From 7ea7deceee70bc1fae4b6a007fed31208164a0fd Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Tue, 16 May 2017 16:50:54 -0500 Subject: [PATCH 08/17] remove extra underscore --- docs/source/manual/jaxrs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/manual/jaxrs.rst b/docs/source/manual/jaxrs.rst index 91e0111c..da343119 100644 --- a/docs/source/manual/jaxrs.rst +++ b/docs/source/manual/jaxrs.rst @@ -32,7 +32,7 @@ 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 RFC_ +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 From 20ef4a8c5243b6d30b349104083e5a05c5c54c38 Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Tue, 16 May 2017 16:52:16 -0500 Subject: [PATCH 09/17] remove the other underscore? --- docs/source/manual/jaxrs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/manual/jaxrs.rst b/docs/source/manual/jaxrs.rst index da343119..172ad141 100644 --- a/docs/source/manual/jaxrs.rst +++ b/docs/source/manual/jaxrs.rst @@ -48,7 +48,7 @@ interface. @ApiParam(value = "changes to make to the object with the specified id") PatchObject patchObject); ->> _RFC: https://tools.ietf.org/html/rfc5789 +>> RFC: https://tools.ietf.org/html/rfc5789 Download -------- From 32acdeb808b1216a63e8b8a5c5a2c4fcd3670506 Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Tue, 16 May 2017 16:54:44 -0500 Subject: [PATCH 10/17] add period instead of << --- docs/source/manual/jaxrs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/manual/jaxrs.rst b/docs/source/manual/jaxrs.rst index 172ad141..46224347 100644 --- a/docs/source/manual/jaxrs.rst +++ b/docs/source/manual/jaxrs.rst @@ -48,7 +48,7 @@ interface. @ApiParam(value = "changes to make to the object with the specified id") PatchObject patchObject); ->> RFC: https://tools.ietf.org/html/rfc5789 +.. _RFC: https://tools.ietf.org/html/rfc5789 Download -------- From f8347b058f0fe313c978098ecb60f15d5c2c73bc Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Tue, 16 May 2017 16:56:18 -0500 Subject: [PATCH 11/17] add _ back --- docs/source/manual/jaxrs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/manual/jaxrs.rst b/docs/source/manual/jaxrs.rst index 46224347..1f66bc4f 100644 --- a/docs/source/manual/jaxrs.rst +++ b/docs/source/manual/jaxrs.rst @@ -32,7 +32,7 @@ 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. +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 From 7931147398b85634dec536301172c529873eb276 Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Wed, 17 May 2017 09:00:05 -0500 Subject: [PATCH 12/17] Sundeeps comments --- .../client/example/ResourceOneImpl.java | 2 +- .../client/example/ResourceTwoImpl.java | 2 +- .../beadledom/client/ClientServiceSpec.scala | 4 +-- docs/source/manual/jaxrs.rst | 28 ++++++++----------- .../com/cerner/beadledom/jaxrs/PATCH.java | 5 ++++ .../cerner/beadledom/jaxrs/PATCHSpec.scala | 22 +-------------- 6 files changed, 22 insertions(+), 41 deletions(-) diff --git a/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceOneImpl.java b/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceOneImpl.java index 41736309..365cd6d8 100644 --- a/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceOneImpl.java +++ b/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceOneImpl.java @@ -21,7 +21,7 @@ public JsonOne echo(JsonOne json) { @Override public JsonOne patch(JsonOne json) { return json.builder() - .setHello("Hola") + .setHello("Hola1") .setOne("New Json") .build(); } diff --git a/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceTwoImpl.java b/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceTwoImpl.java index 7d13803a..786db19f 100644 --- a/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceTwoImpl.java +++ b/client/beadledom-client-example/example-service/src/main/java/com/cerner/beadledom/client/example/ResourceTwoImpl.java @@ -21,7 +21,7 @@ public JsonTwo echo(JsonTwo json) { @Override public JsonTwo patch(JsonTwo json) { return json.builder() - .setHello("Hola") + .setHello("Hola2") .setTwo("New Json") .build(); } diff --git a/client/beadledom-client-test/src/test/scala/com/cerner/beadledom/client/ClientServiceSpec.scala b/client/beadledom-client-test/src/test/scala/com/cerner/beadledom/client/ClientServiceSpec.scala index cf6ec0fe..a121bce2 100644 --- a/client/beadledom-client-test/src/test/scala/com/cerner/beadledom/client/ClientServiceSpec.scala +++ b/client/beadledom-client-test/src/test/scala/com/cerner/beadledom/client/ClientServiceSpec.scala @@ -34,12 +34,12 @@ 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 jsonNewOne = JsonOne.create("New Json", "Hola1") val jsonOne = JsonOne.create("LocalOne", "Hi") resourceOne.echo(jsonOne) mustBe jsonOne resourceOne.patch(jsonOne) mustBe jsonNewOne - val jsonNewTwo = JsonTwo.create("New Json", "Hola") + val jsonNewTwo = JsonTwo.create("New Json", "Hola2") val jsonTwo = JsonTwo.create("LocalTwo", "Howdy") resourceTwo.echo(jsonTwo) mustBe jsonTwo resourceTwo.patch(jsonTwo) mustBe jsonNewTwo diff --git a/docs/source/manual/jaxrs.rst b/docs/source/manual/jaxrs.rst index 1f66bc4f..803d1e12 100644 --- a/docs/source/manual/jaxrs.rst +++ b/docs/source/manual/jaxrs.rst @@ -26,30 +26,26 @@ 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 +PATCH -------------- -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_. +`PATCH `_ is a HTTP verb (similar to GET, POST, DELETE, PUT) to push partial changes to the REST resource. JAX-RS by default doesn't support PATCH hence Beadledom adds the support for PATCH explicitly. -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. +For more details on the PATCH method visit the PATCH RFC_. + +To use the PATCH method and annotation for your resource, simply annotate your JAX-RS resource method with the PATCH annotation as shown below .. 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); + @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 - Download -------- diff --git a/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java b/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java index 6c0e9ef4..9bf4b39e 100644 --- a/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java +++ b/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java @@ -7,6 +7,11 @@ import javax.ws.rs.HttpMethod; +/** + * Indicates that the annotated method responds to HTTP PATCH requests. + * + * @author John Leacox + */ @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @HttpMethod("PATCH") diff --git a/jaxrs/src/test/scala/com/cerner/beadledom/jaxrs/PATCHSpec.scala b/jaxrs/src/test/scala/com/cerner/beadledom/jaxrs/PATCHSpec.scala index 75e7e4ab..73ab0def 100644 --- a/jaxrs/src/test/scala/com/cerner/beadledom/jaxrs/PATCHSpec.scala +++ b/jaxrs/src/test/scala/com/cerner/beadledom/jaxrs/PATCHSpec.scala @@ -29,27 +29,7 @@ class PATCHSpec extends FunSpec with BeforeAndAfterAll with ShouldMatchers with dispatcher.getProviderFactory.registerProvider(classOf[JacksonJsonProvider]) describe("PATCH") { - it("calls PATCH resource without error") { - - val model = new FakeModel() - .setId("id") - .setName("name") - .setTimes(10) - .setTags(List.empty[String].asJava) - .setInnerModels(List.empty[FakeModel.FakeInnerModel].asJava) - - val mapper = new ObjectMapper - val request: MockHttpRequest = MockHttpRequest.create("PATCH", "/fakeResource/Patch") - request.contentType(MediaType.APPLICATION_JSON) - request.content(new ByteArrayInputStream(mapper.writeValueAsBytes(model))) - - val response: MockHttpResponse = new MockHttpResponse() - dispatcher.invoke(request, response) - - response.getStatus shouldBe 200 - } - - it("should change the request model fields") { + it("the resource is patched correctly") { val model = new FakeModel() .setId("id") From 84431c4e2bc9c8bed230d16e5d3f05f8a8d23c40 Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Wed, 17 May 2017 09:03:26 -0500 Subject: [PATCH 13/17] remove mysterious url --- docs/source/manual/jaxrs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/manual/jaxrs.rst b/docs/source/manual/jaxrs.rst index 803d1e12..50851fc4 100644 --- a/docs/source/manual/jaxrs.rst +++ b/docs/source/manual/jaxrs.rst @@ -29,7 +29,7 @@ To include the correlation id in the catalina.out file using log4j, update the l PATCH -------------- -`PATCH `_ is a HTTP verb (similar to GET, POST, DELETE, PUT) to push partial changes to the REST resource. JAX-RS by default doesn't support PATCH hence Beadledom adds the support for PATCH explicitly. +`PATCH is a HTTP verb (similar to GET, POST, DELETE, PUT) to push partial changes to the REST resource. JAX-RS by default doesn't support PATCH hence Beadledom adds the support for PATCH explicitly. For more details on the PATCH method visit the PATCH RFC_. From d564ac3fb4f2eceb01d3cea3705aad1b80bdedcd Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Wed, 17 May 2017 09:14:29 -0500 Subject: [PATCH 14/17] link wiki --- docs/source/manual/jaxrs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/manual/jaxrs.rst b/docs/source/manual/jaxrs.rst index 50851fc4..76317aa0 100644 --- a/docs/source/manual/jaxrs.rst +++ b/docs/source/manual/jaxrs.rst @@ -29,7 +29,7 @@ To include the correlation id in the catalina.out file using log4j, update the l PATCH -------------- -`PATCH is a HTTP verb (similar to GET, POST, DELETE, PUT) to push partial changes to the REST resource. JAX-RS by default doesn't support PATCH hence Beadledom adds the support for PATCH explicitly. +`PATCH `_ is a HTTP verb (similar to GET, POST, DELETE, PUT) to push partial changes to the REST resource. JAX-RS by default doesn't support PATCH hence Beadledom adds the support for PATCH explicitly. For more details on the PATCH method visit the PATCH RFC_. From bb8be5203c6721fe2b3ef5d03c017bef69441e43 Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Wed, 17 May 2017 10:05:24 -0500 Subject: [PATCH 15/17] add proper name and brians version of rst --- docs/source/manual/jaxrs.rst | 17 ++++++++++++----- .../java/com/cerner/beadledom/jaxrs/PATCH.java | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/source/manual/jaxrs.rst b/docs/source/manual/jaxrs.rst index 76317aa0..f5ac10aa 100644 --- a/docs/source/manual/jaxrs.rst +++ b/docs/source/manual/jaxrs.rst @@ -29,11 +29,18 @@ To include the correlation id in the catalina.out file using log4j, update the l PATCH -------------- -`PATCH `_ is a HTTP verb (similar to GET, POST, DELETE, PUT) to push partial changes to the REST resource. JAX-RS by default doesn't support PATCH hence Beadledom adds the support for PATCH explicitly. - -For more details on the PATCH method visit the PATCH RFC_. - -To use the PATCH method and annotation for your resource, simply annotate your JAX-RS resource method with the PATCH annotation as shown below +`JAX-RS 2.0 (see section 3.3 for Resource Methods) `_ does not require implementations to support the +``PATCH`` HTTP method. This is likely due to the fact that ``PATCH`` was introduced in a later `rfc `_ that added +the new HTTP method to the already existing HTTP/1.1 specification. + +``@PATCH`` was added to `beadledom-jaxrs `_ to allow services to support partial updates without the need of +overloading ``@POST``. The annotation has no opinion on how the service decides to implement the +resource performing the ``PATCH`` operation. Implementing services have the freedom to support `JSON +Patch `_ and/or `JSON Merge Patch `_. + +As long as a service has ``beadledom-jaxrs`` as a dependency ``@PATCH`` can be used just like any of the +HTTP method annotations defined by JAX-RS. Below is a small example of ``@PATCH`` being used in an +interface for a resource. .. code-block:: java diff --git a/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java b/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java index 9bf4b39e..0a1fea2c 100644 --- a/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java +++ b/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java @@ -10,7 +10,7 @@ /** * Indicates that the annotated method responds to HTTP PATCH requests. * - * @author John Leacox + * @author Eric Christensen */ @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) From f388ee2f8c06434cc427eafd2717d1f38ba67d1d Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Wed, 17 May 2017 10:11:43 -0500 Subject: [PATCH 16/17] link to wiki on new rst --- docs/source/manual/jaxrs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/manual/jaxrs.rst b/docs/source/manual/jaxrs.rst index f5ac10aa..e3e3a08a 100644 --- a/docs/source/manual/jaxrs.rst +++ b/docs/source/manual/jaxrs.rst @@ -30,7 +30,7 @@ PATCH -------------- `JAX-RS 2.0 (see section 3.3 for Resource Methods) `_ does not require implementations to support the -``PATCH`` HTTP method. This is likely due to the fact that ``PATCH`` was introduced in a later `rfc `_ that added +`PATCH `_ HTTP method. This is likely due to the fact that ``PATCH`` was introduced in a later `rfc `_ that added the new HTTP method to the already existing HTTP/1.1 specification. ``@PATCH`` was added to `beadledom-jaxrs `_ to allow services to support partial updates without the need of From ffcd9d078905a7bdd6933cff11a5de34ab44e762 Mon Sep 17 00:00:00 2001 From: EricChristensen Date: Wed, 17 May 2017 10:26:15 -0500 Subject: [PATCH 17/17] add since 2.5 in patch javadoc --- jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java | 1 + 1 file changed, 1 insertion(+) diff --git a/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java b/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java index 0a1fea2c..c7323ee6 100644 --- a/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java +++ b/jaxrs/src/main/java/com/cerner/beadledom/jaxrs/PATCH.java @@ -11,6 +11,7 @@ * Indicates that the annotated method responds to HTTP PATCH requests. * * @author Eric Christensen + * @since 2.5 */ @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME)