You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by gr...@apache.org on 2020/09/23 10:25:39 UTC

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

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 <gi...@hotwaxsystems.com>
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);
                             }