You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/07/01 11:01:01 UTC

[1/2] camel git commit: rest-dsl parameter name is mandatory - avoid potential NPE

Repository: camel
Updated Branches:
  refs/heads/master 65594b370 -> f276180b7


rest-dsl parameter name is mandatory - avoid potential NPE


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/65c9d9a1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/65c9d9a1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/65c9d9a1

Branch: refs/heads/master
Commit: 65c9d9a1b2bb78f21132080cc68d011bf9586510
Parents: 65594b3
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 1 10:32:28 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 1 10:39:17 2015 +0200

----------------------------------------------------------------------
 .../src/main/java/org/apache/camel/model/rest/RestDefinition.java | 2 ++
 .../org/apache/camel/model/rest/RestOperationParamDefinition.java | 3 +++
 2 files changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/65c9d9a1/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
index acbcf56..3331408 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
@@ -577,6 +577,8 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
                     //  merge if exists
                     boolean found = false;
                     for (RestOperationParamDefinition param : verb.getParams()) {
+                        // name is mandatory
+                        ObjectHelper.notEmpty(param.getName(), "parameter name");
                         if (param.getName().equalsIgnoreCase(key)) {
                             param.type(RestParamType.path);
                             found = true;

http://git-wip-us.apache.org/repos/asf/camel/blob/65c9d9a1/camel-core/src/main/java/org/apache/camel/model/rest/RestOperationParamDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestOperationParamDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestOperationParamDefinition.java
index ea379d6..82dcffd 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestOperationParamDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestOperationParamDefinition.java
@@ -28,6 +28,7 @@ import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlTransient;
 
 import org.apache.camel.spi.Metadata;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * To specify the rest operation parameters using Swagger.
@@ -275,6 +276,8 @@ public class RestOperationParamDefinition {
      * Ends the configuration of this parameter
      */
     public RestDefinition endParam() {
+        // name is mandatory
+        ObjectHelper.notEmpty(name, "name");
         verb.getParams().add(this);
         return verb.getRest();
     }


[2/2] camel git commit: CAMEL-8897: camel-example-servlet-rest-tomcat should include rest-dsl query params docs

Posted by da...@apache.org.
CAMEL-8897: camel-example-servlet-rest-tomcat should include rest-dsl query params docs


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f276180b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f276180b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f276180b

Branch: refs/heads/master
Commit: f276180b75977aed3b672ae29e1195a137c015ea
Parents: 65c9d9a
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 1 11:07:06 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 1 11:07:06 2015 +0200

----------------------------------------------------------------------
 .../apache/camel/model/rest/RestDefinition.java | 20 +++++++++++++++++---
 .../org/apache/camel/example/rest/User.java     |  6 ++++++
 .../camel/example/rest/UserRouteBuilder.java    |  5 +++++
 .../src/main/webapp/home.html                   |  7 ++++---
 4 files changed, 32 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f276180b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
index 3331408..6804ae9 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
@@ -596,11 +596,16 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
                 if (bodyType.endsWith("[]")) {
                     bodyType = "List[" + bodyType.substring(0, bodyType.length() - 2) + "]";
                 }
-                param(verb).name(RestParamType.body.name()).type(RestParamType.body).dataType(bodyType).endParam();
+                RestOperationParamDefinition param = findParam(verb, RestParamType.body.name());
+                if (param == null) {
+                    // must be body type and set the model class as data type
+                    param(verb).name(RestParamType.body.name()).type(RestParamType.body).dataType(bodyType).endParam();
+                } else {
+                    // must be body type and set the model class as data type
+                    param.type(RestParamType.body).dataType(bodyType);
+                }
             }
 
-
-
             // the route should be from this rest endpoint
             route.fromRest(from);
             route.setRestDefinition(this);
@@ -622,4 +627,13 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
         }
     }
 
+    private RestOperationParamDefinition findParam(VerbDefinition verb, String name) {
+        for (RestOperationParamDefinition param : verb.getParams()) {
+            if (name.equals(param.getName())) {
+                return param;
+            }
+        }
+        return null;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/f276180b/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/User.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/User.java b/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/User.java
index 25b1721..ee63727 100644
--- a/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/User.java
+++ b/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/User.java
@@ -16,6 +16,10 @@
  */
 package org.apache.camel.example.rest;
 
+import com.wordnik.swagger.annotations.ApiModel;
+import com.wordnik.swagger.annotations.ApiModelProperty;
+
+@ApiModel(description = "Represents an user of the system")
 public class User {
 
     private int id;
@@ -29,6 +33,7 @@ public class User {
         this.name = name;
     }
 
+    @ApiModelProperty(value = "The id of the user", required = true)
     public int getId() {
         return id;
     }
@@ -37,6 +42,7 @@ public class User {
         this.id = id;
     }
 
+    @ApiModelProperty(value = "The name of the user", required = true)
     public String getName() {
         return name;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/f276180b/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/UserRouteBuilder.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/UserRouteBuilder.java b/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/UserRouteBuilder.java
index 0f6fbd5..04f22d7 100644
--- a/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/UserRouteBuilder.java
+++ b/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/UserRouteBuilder.java
@@ -18,6 +18,9 @@ package org.apache.camel.example.rest;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.model.rest.RestBindingMode;
+import org.apache.camel.model.rest.RestParamType;
+
+import static org.apache.camel.model.rest.RestParamType.*;
 
 /**
  * Define REST services using the Camel REST DSL
@@ -46,9 +49,11 @@ public class UserRouteBuilder extends RouteBuilder {
             .consumes("application/json").produces("application/json")
 
             .get("/{id}").description("Find user by id").outType(User.class)
+                .param().name("id").type(query).description("The id of the user to get").dataType("int").endParam()
                 .to("bean:userService?method=getUser(${header.id})")
 
             .put().description("Updates or create a user").type(User.class)
+                .param().name("body").type(body).description("The user to update or create").endParam()
                 .to("bean:userService?method=updateUser")
 
             .get("/findAll").description("Find all users").outTypeList(User.class)

http://git-wip-us.apache.org/repos/asf/camel/blob/f276180b/examples/camel-example-servlet-rest-tomcat/src/main/webapp/home.html
----------------------------------------------------------------------
diff --git a/examples/camel-example-servlet-rest-tomcat/src/main/webapp/home.html b/examples/camel-example-servlet-rest-tomcat/src/main/webapp/home.html
index 03cb404..b9c4e2a 100644
--- a/examples/camel-example-servlet-rest-tomcat/src/main/webapp/home.html
+++ b/examples/camel-example-servlet-rest-tomcat/src/main/webapp/home.html
@@ -74,12 +74,13 @@
         <p/>
         This example offers an API browser using Swagger which is accessible from the following link
         <ul>
-            <li><a href="api-docs">api-docs</a> - overview of the apis from the REST services</li>
-            <li><a href="api-docs/user">api-docs/user</a> - api of the user REST service</li>
+            <li><a href="api-docs">api-docs</a> - list all CamelContexts in the JVM that may have REST services</li>
+            <li><a href="api-docs/myCamel">api-docs/myCamel</a> - myCamel - overview of the apis from the REST services</li>
+            <li><a href="api-docs/myCamel/user">api-docs/myCamel/user</a> - myCamel - api of the user REST service</li>
         </ul>
 
         <p/>
-        To use the swagger ui, follow this link. Replace the URL value with this one to access the REST local resources http://localhost:8080/camel-example-servlet-rest-tomcat/api-docs
+        To use the swagger ui, follow this link. Replace the URL value with this one to access the REST local resources http://localhost:8080/camel-example-servlet-rest-tomcat/api-docs/myCamel
         <ul>
             <li><a href="index.html">swagger</a> - swagger ui page</li>
         </ul>