Repository: camel Updated Branches: refs/heads/master 50e8ed779 -> 2fb649050
Rest DSL. camel-swagger work in progress. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2fb64905 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2fb64905 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2fb64905 Branch: refs/heads/master Commit: 2fb649050408e88558e9f9f2dc889418ab5e4fdb Parents: 50e8ed7 Author: Claus Ibsen <davscl...@apache.org> Authored: Sun Aug 10 12:21:44 2014 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Aug 10 12:21:44 2014 +0200 ---------------------------------------------------------------------- .../camel/model/rest/RestBindingDefinition.java | 38 ++++++-------------- .../apache/camel/model/rest/RestDefinition.java | 16 +++------ .../apache/camel/model/rest/VerbDefinition.java | 22 ------------ .../component/swagger/RestSwaggerReader.scala | 3 +- .../src/main/resources/camel-config-xml.xml | 2 +- 5 files changed, 17 insertions(+), 64 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/2fb64905/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java index 7099c90..5655ca5 100644 --- a/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java @@ -29,7 +29,6 @@ import org.apache.camel.Processor; import org.apache.camel.model.NoOutputDefinition; import org.apache.camel.processor.binding.RestBindingProcessor; import org.apache.camel.spi.DataFormat; -import org.apache.camel.spi.RestConfiguration; import org.apache.camel.spi.RouteContext; import org.apache.camel.util.IntrospectionSupport; @@ -52,12 +51,6 @@ public class RestBindingDefinition extends NoOutputDefinition { @XmlAttribute private String outType; - @XmlAttribute - private Boolean list; - - @XmlAttribute - private Boolean outList; - @Override public String toString() { return "RestBinding"; @@ -100,22 +93,24 @@ public class RestBindingDefinition extends NoOutputDefinition { if (json != null) { Class<?> clazz = null; if (type != null) { - clazz = context.getClassResolver().resolveMandatoryClass(type); + String typeName = type.endsWith("[]") ? type.substring(0, type.length() - 2) : type; + clazz = context.getClassResolver().resolveMandatoryClass(typeName); } if (clazz != null) { IntrospectionSupport.setProperty(context.getTypeConverter(), json, "unmarshalType", clazz); - IntrospectionSupport.setProperty(context.getTypeConverter(), json, "useList", list != null ? list : false); + IntrospectionSupport.setProperty(context.getTypeConverter(), json, "useList", type.endsWith("[]")); } setAdditionalConfiguration(context, json); context.addService(json); Class<?> outClazz = null; if (outType != null) { - outClazz = context.getClassResolver().resolveMandatoryClass(outType); + String typeName = outType.endsWith("[]") ? outType.substring(0, outType.length() - 2) : outType; + outClazz = context.getClassResolver().resolveMandatoryClass(typeName); } if (outClazz != null) { IntrospectionSupport.setProperty(context.getTypeConverter(), outJson, "unmarshalType", outClazz); - IntrospectionSupport.setProperty(context.getTypeConverter(), outJson, "useList", outList != null ? outList : false); + IntrospectionSupport.setProperty(context.getTypeConverter(), outJson, "useList", outType.endsWith("[]")); } setAdditionalConfiguration(context, outJson); context.addService(outJson); @@ -136,7 +131,8 @@ public class RestBindingDefinition extends NoOutputDefinition { if (jaxb != null) { Class<?> clazz = null; if (type != null) { - clazz = context.getClassResolver().resolveMandatoryClass(type); + String typeName = type.endsWith("[]") ? type.substring(0, type.length() - 2) : type; + clazz = context.getClassResolver().resolveMandatoryClass(typeName); } if (clazz != null) { JAXBContext jc = JAXBContext.newInstance(clazz); @@ -150,7 +146,8 @@ public class RestBindingDefinition extends NoOutputDefinition { Class<?> outClazz = null; if (outType != null) { - outClazz = context.getClassResolver().resolveMandatoryClass(outType); + String typeName = outType.endsWith("[]") ? outType.substring(0, outType.length() - 2) : outType; + outClazz = context.getClassResolver().resolveMandatoryClass(typeName); } if (outClazz != null) { JAXBContext jc = JAXBContext.newInstance(outClazz); @@ -217,19 +214,4 @@ public class RestBindingDefinition extends NoOutputDefinition { this.outType = outType; } - public Boolean getList() { - return list; - } - - public void setList(Boolean list) { - this.list = list; - } - - public Boolean getOutList() { - return outList; - } - - public void setOutList(Boolean outList) { - this.outList = outList; - } } http://git-wip-us.apache.org/repos/asf/camel/blob/2fb64905/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 cf322a9..558b38f 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 @@ -194,8 +194,8 @@ public class RestDefinition { } VerbDefinition verb = getVerbs().get(getVerbs().size() - 1); - verb.setType(classType.getCanonicalName()); - verb.setList(true); + // list should end with [] to indicate array + verb.setType(classType.getCanonicalName() + "[]"); return this; } @@ -217,8 +217,8 @@ public class RestDefinition { } VerbDefinition verb = getVerbs().get(getVerbs().size() - 1); - verb.setOutType(classType.getCanonicalName()); - verb.setOutList(true); + // list should end with [] to indicate array + verb.setOutType(classType.getCanonicalName() + "[]"); return this; } @@ -318,8 +318,6 @@ public class RestDefinition { RestBindingDefinition binding = new RestBindingDefinition(); binding.setType(verb.getType()); binding.setOutType(verb.getOutType()); - binding.setList(verb.getList()); - binding.setOutList(verb.getOutList()); // verb takes precedence over configuration on rest if (verb.getConsumes() != null) { binding.setConsumes(verb.getConsumes()); @@ -357,16 +355,10 @@ public class RestDefinition { // append optional type binding information String inType = binding.getType(); - if (binding.getList() != null && binding.getList()) { - inType = "List<" + inType + ">"; - } if (inType != null) { options.put("inType", inType); } String outType = binding.getOutType(); - if (binding.getOutList() != null && binding.getOutList()) { - outType = "List<" + outType + ">"; - } if (outType != null) { options.put("outType", outType); } http://git-wip-us.apache.org/repos/asf/camel/blob/2fb64905/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java index 48aa066..fe4dd33 100644 --- a/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java @@ -53,12 +53,6 @@ public class VerbDefinition { @XmlAttribute private String outType; - @XmlAttribute - private Boolean list; - - @XmlAttribute - private Boolean outList; - // used by XML DSL to either select a <to> or <route> // so we need to use the common type OptionalIdentifiedDefinition @XmlElements({ @@ -131,22 +125,6 @@ public class VerbDefinition { this.outType = outType; } - public Boolean getList() { - return list; - } - - public void setList(Boolean list) { - this.list = list; - } - - public Boolean getOutList() { - return outList; - } - - public void setOutList(Boolean outList) { - this.outList = outList; - } - public RestDefinition getRest() { return rest; } http://git-wip-us.apache.org/repos/asf/camel/blob/2fb64905/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala ---------------------------------------------------------------------- diff --git a/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala b/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala index f9fe70f..7522595 100644 --- a/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala +++ b/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala @@ -50,7 +50,7 @@ class RestSwaggerReader { // TODO: add parameters to operations // - {id} is a path type, and required - // - type/typeList/outType/outTypeList is body type and required + // - type/outType is body type and required def read(rest: RestDefinition, config: SwaggerConfig): Option[ApiListing] = { @@ -99,6 +99,7 @@ class RestSwaggerReader { var nickName = createNickname(verb.asVerb(), buildUrl(resourcePath, path)) var responseType = verb.getOutType match { + case e: String if e.endsWith("[]") => "List[" + e.substring(0, e.length - 2) + "]" case e: String => e case _ => "java.lang.Void" } http://git-wip-us.apache.org/repos/asf/camel/blob/2fb64905/examples/camel-example-servlet-rest-tomcat/src/main/resources/camel-config-xml.xml ---------------------------------------------------------------------- diff --git a/examples/camel-example-servlet-rest-tomcat/src/main/resources/camel-config-xml.xml b/examples/camel-example-servlet-rest-tomcat/src/main/resources/camel-config-xml.xml index 3138843..b6185c6 100755 --- a/examples/camel-example-servlet-rest-tomcat/src/main/resources/camel-config-xml.xml +++ b/examples/camel-example-servlet-rest-tomcat/src/main/resources/camel-config-xml.xml @@ -53,7 +53,7 @@ </put> <!-- this is a rest GET to find all users --> - <get uri="/findAll" outList="true" outType="org.apache.camel.example.rest.User"> + <get uri="/findAll" outType="org.apache.camel.example.rest.User[]"> <to uri="bean:userService?method=listUsers"/> </get>