[ofbiz-plugins] branch trunk updated: Improved: Added Consumes for non-GET methods(OFBIZ-11328)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-plugins] branch trunk updated: Improved: Added Consumes for non-GET methods(OFBIZ-11328)

grv-2
This is an automated email from the ASF dual-hosted git repository.

grv pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-plugins.git


The following commit(s) were added to refs/heads/trunk by this push:
     new d2e34eb  Improved: Added Consumes for non-GET methods(OFBIZ-11328)
d2e34eb is described below

commit d2e34ebe10ab7c437c41053e6b21325dcdbb4160
Author: Girish Vasmatkar <[hidden email]>
AuthorDate: Wed Sep 23 15:55:11 2020 +0530

    Improved: Added Consumes for non-GET methods(OFBIZ-11328)
---
 .../java/org/apache/ofbiz/ws/rs/core/OFBizApiConfig.java    | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/core/OFBizApiConfig.java b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/core/OFBizApiConfig.java
index b9d02cb..126bd09 100644
--- a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/core/OFBizApiConfig.java
+++ b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/core/OFBizApiConfig.java
@@ -26,6 +26,7 @@ import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.ws.rs.HttpMethod;
 import javax.ws.rs.core.MediaType;
 
 import org.apache.ofbiz.base.component.ComponentConfig;
@@ -105,9 +106,14 @@ public class OFBizApiConfig extends ResourceConfig {
                     Resource.Builder resourceBuilder = Resource.builder(modelResource.getPath())
                             .name(modelResource.getName());
                     for (ModelOperation op : modelResource.getOperations()) {
+                        String verb = op.getVerb().toUpperCase();
+                        boolean isOtherThanGet = verb.matches(HttpMethod.POST + "|" + HttpMethod.PUT + "|" + HttpMethod.PATCH);
                         if (UtilValidate.isEmpty(op.getPath())) { // Add the method to the parent resource
-                            ResourceMethod.Builder methodBuilder = resourceBuilder.addMethod(op.getVerb().toUpperCase());
+                            ResourceMethod.Builder methodBuilder = resourceBuilder.addMethod(verb);
                             methodBuilder.produces(MediaType.APPLICATION_JSON);
+                            if (isOtherThanGet) {
+                                methodBuilder.consumes(MediaType.APPLICATION_JSON);
+                            }
                             if (op.isAuth()) {
                                 methodBuilder.nameBindings(Secured.class);
                             }
@@ -115,8 +121,11 @@ public class OFBizApiConfig extends ResourceConfig {
                             methodBuilder.handledBy(new ServiceRequestHandler(serviceName));
                         } else {
                             Resource.Builder childResourceBuilder = resourceBuilder.addChildResource(op.getPath());
-                            ResourceMethod.Builder childResourceMethodBuilder = childResourceBuilder.addMethod(op.getVerb().toUpperCase());
+                            ResourceMethod.Builder childResourceMethodBuilder = childResourceBuilder.addMethod(verb);
                             childResourceMethodBuilder.produces(MediaType.APPLICATION_JSON);
+                            if (isOtherThanGet) {
+                                childResourceMethodBuilder.consumes(MediaType.APPLICATION_JSON);
+                            }
                             if (op.isAuth()) {
                                 childResourceMethodBuilder.nameBindings(Secured.class);
                             }