This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch rest-to in repository https://gitbox.apache.org/repos/asf/camel.git
commit 42854530b22e0432f03f69abd48c52d1426b5bd5 Author: Claus Ibsen <[email protected]> AuthorDate: Tue Feb 22 09:48:08 2022 +0100 CAMEL-17675: camel-core - Rest DSL remove support for using inlined routes. --- .../org/apache/camel/model/rest/delete.json | 2 +- .../resources/org/apache/camel/model/rest/get.json | 2 +- .../org/apache/camel/model/rest/head.json | 2 +- .../org/apache/camel/model/rest/patch.json | 2 +- .../org/apache/camel/model/rest/post.json | 2 +- .../resources/org/apache/camel/model/rest/put.json | 2 +- .../apache/camel/model/ProcessorDefinition.java | 17 ---- .../apache/camel/model/rest/RestDefinition.java | 55 ++--------- .../apache/camel/model/rest/VerbDefinition.java | 102 +++------------------ .../component/rest/FromRestAdviceWithTest.java | 6 +- .../rest/FromRestGetEmbeddedRouteTest.java | 87 ------------------ .../component/rest/FromRestGetEndPathTest.java | 6 +- .../rest/FromRestGetHttpErrorCodeTest.java | 5 +- .../component/rest/FromRestGetInterceptTest.java | 5 +- .../component/rest/FromRestGetOnExceptionTest.java | 5 +- .../component/rest/FromRestGetPolicyTest.java | 5 +- .../rest/FromRestGetRouteOnExceptionTest.java | 4 +- .../apache/camel/model/XmlRestParseToDTest.java | 47 ---------- .../org/apache/camel/model/simpleRestToD.xml | 28 ------ .../ManagedFromRestGetEmbeddedRouteTest.java | 96 ------------------- .../camel/management/ManagedRestRegistryTest.java | 10 +- .../java/org/apache/camel/xml/in/ModelParser.java | 4 +- .../src/test/resources/simpleRestToD.xml | 28 ------ 23 files changed, 61 insertions(+), 461 deletions(-) diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/delete.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/delete.json index bafa802..17f46bb 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/delete.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/delete.json @@ -23,7 +23,7 @@ "deprecated": { "kind": "attribute", "displayName": "Deprecated", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Marks this rest operation as deprecated in OpenApi documentation." }, "type": { "kind": "attribute", "displayName": "Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, - "toOrRoute": { "kind": "element", "displayName": "To Or Route", "required": true, "type": "object", "javaType": "org.apache.camel.model.OptionalIdentifiedDefinition<java.lang.Object>", "oneOf": [ "route", "to", "toD" ], "deprecated": false, "autowired": false, "secret": false, "description": "To route from this REST service to a Camel endpoint, or an inlined route" }, + "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "description": { "kind": "element", "displayName": "Description", "required": false, "type": "object", "javaType": "org.apache.camel.model.DescriptionDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the description of this node" } } diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/get.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/get.json index c7c3199..e9b79ff 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/get.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/get.json @@ -23,7 +23,7 @@ "deprecated": { "kind": "attribute", "displayName": "Deprecated", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Marks this rest operation as deprecated in OpenApi documentation." }, "type": { "kind": "attribute", "displayName": "Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, - "toOrRoute": { "kind": "element", "displayName": "To Or Route", "required": true, "type": "object", "javaType": "org.apache.camel.model.OptionalIdentifiedDefinition<java.lang.Object>", "oneOf": [ "route", "to", "toD" ], "deprecated": false, "autowired": false, "secret": false, "description": "To route from this REST service to a Camel endpoint, or an inlined route" }, + "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "description": { "kind": "element", "displayName": "Description", "required": false, "type": "object", "javaType": "org.apache.camel.model.DescriptionDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the description of this node" } } diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/head.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/head.json index f90765c..e8653ad 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/head.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/head.json @@ -23,7 +23,7 @@ "deprecated": { "kind": "attribute", "displayName": "Deprecated", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Marks this rest operation as deprecated in OpenApi documentation." }, "type": { "kind": "attribute", "displayName": "Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, - "toOrRoute": { "kind": "element", "displayName": "To Or Route", "required": true, "type": "object", "javaType": "org.apache.camel.model.OptionalIdentifiedDefinition<java.lang.Object>", "oneOf": [ "route", "to", "toD" ], "deprecated": false, "autowired": false, "secret": false, "description": "To route from this REST service to a Camel endpoint, or an inlined route" }, + "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "description": { "kind": "element", "displayName": "Description", "required": false, "type": "object", "javaType": "org.apache.camel.model.DescriptionDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the description of this node" } } diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/patch.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/patch.json index 0f5d175..b78fea7 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/patch.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/patch.json @@ -23,7 +23,7 @@ "deprecated": { "kind": "attribute", "displayName": "Deprecated", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Marks this rest operation as deprecated in OpenApi documentation." }, "type": { "kind": "attribute", "displayName": "Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, - "toOrRoute": { "kind": "element", "displayName": "To Or Route", "required": true, "type": "object", "javaType": "org.apache.camel.model.OptionalIdentifiedDefinition<java.lang.Object>", "oneOf": [ "route", "to", "toD" ], "deprecated": false, "autowired": false, "secret": false, "description": "To route from this REST service to a Camel endpoint, or an inlined route" }, + "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "description": { "kind": "element", "displayName": "Description", "required": false, "type": "object", "javaType": "org.apache.camel.model.DescriptionDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the description of this node" } } diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/post.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/post.json index 666c6b6..4079a15 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/post.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/post.json @@ -23,7 +23,7 @@ "deprecated": { "kind": "attribute", "displayName": "Deprecated", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Marks this rest operation as deprecated in OpenApi documentation." }, "type": { "kind": "attribute", "displayName": "Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, - "toOrRoute": { "kind": "element", "displayName": "To Or Route", "required": true, "type": "object", "javaType": "org.apache.camel.model.OptionalIdentifiedDefinition<java.lang.Object>", "oneOf": [ "route", "to", "toD" ], "deprecated": false, "autowired": false, "secret": false, "description": "To route from this REST service to a Camel endpoint, or an inlined route" }, + "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "description": { "kind": "element", "displayName": "Description", "required": false, "type": "object", "javaType": "org.apache.camel.model.DescriptionDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the description of this node" } } diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/put.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/put.json index 8bf87a2..e2831e7 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/put.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/put.json @@ -23,7 +23,7 @@ "deprecated": { "kind": "attribute", "displayName": "Deprecated", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Marks this rest operation as deprecated in OpenApi documentation." }, "type": { "kind": "attribute", "displayName": "Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from input to POJO for the incoming data This option will override what may be configured on a parent level. The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, "outType": { "kind": "attribute", "displayName": "Out Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name to use for binding from POJO to output for the outgoing data This option will override what may be configured on a parent level The name of the class of the input data. Append a to the end of the name if you want the input to be an array type." }, - "toOrRoute": { "kind": "element", "displayName": "To Or Route", "required": true, "type": "object", "javaType": "org.apache.camel.model.OptionalIdentifiedDefinition<java.lang.Object>", "oneOf": [ "route", "to", "toD" ], "deprecated": false, "autowired": false, "secret": false, "description": "To route from this REST service to a Camel endpoint, or an inlined route" }, + "to": { "kind": "element", "displayName": "To", "required": true, "type": "object", "javaType": "org.apache.camel.model.ToDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call." }, "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "description": { "kind": "element", "displayName": "Description", "required": false, "type": "object", "javaType": "org.apache.camel.model.DescriptionDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the description of this node" } } diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java index b362783f..bd71b18 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java @@ -57,7 +57,6 @@ import org.apache.camel.model.language.ConstantExpression; import org.apache.camel.model.language.ExpressionDefinition; import org.apache.camel.model.language.LanguageExpression; import org.apache.camel.model.language.SimpleExpression; -import org.apache.camel.model.rest.RestDefinition; import org.apache.camel.processor.loadbalancer.LoadBalancer; import org.apache.camel.spi.AsEndpointUri; import org.apache.camel.spi.AsPredicate; @@ -1116,22 +1115,6 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type> } /** - * Ends the current block and returns back to the {@link org.apache.camel.model.rest.RestDefinition rest()} DSL. - * - * @return the builder - */ - public RestDefinition endRest() { - ProcessorDefinition<?> def = this; - - RouteDefinition route = ProcessorDefinitionHelper.getRoute(def); - if (route != null) { - return route.getRestDefinition(); - } - - throw new IllegalArgumentException("Cannot find RouteDefinition to allow endRest"); - } - - /** * Ends the current block and returns back to the {@link TryDefinition doTry()} DSL. * * @return the builder diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestDefinition.java index e4c9f0e..14e2c92 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestDefinition.java @@ -36,10 +36,8 @@ import org.apache.camel.CamelContext; import org.apache.camel.ExtendedCamelContext; import org.apache.camel.RuntimeCamelException; import org.apache.camel.model.OptionalIdentifiedDefinition; -import org.apache.camel.model.ProcessorDefinition; import org.apache.camel.model.RouteDefinition; import org.apache.camel.model.ToDefinition; -import org.apache.camel.model.ToDynamicDefinition; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.RestConfiguration; import org.apache.camel.util.FileUtil; @@ -606,9 +604,8 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition> } /** - * Routes directly to the given static endpoint. - * <p/> - * If you need additional routing capabilities, then use {@link #route()} instead. + * The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that + * handles this REST call. * * @param uri the uri of the endpoint * @return this builder @@ -627,41 +624,6 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition> } /** - * Routes directly to the given dynamic endpoint. - * <p/> - * If you need additional routing capabilities, then use {@link #route()} instead. - * - * @param uri the uri of the endpoint - * @return this builder - */ - public RestDefinition toD(String uri) { - // add to last verb - if (getVerbs().isEmpty()) { - throw new IllegalArgumentException("Must add verb first, such as get/post/delete"); - } - - ToDynamicDefinition to = new ToDynamicDefinition(uri); - - VerbDefinition verb = getVerbs().get(getVerbs().size() - 1); - verb.setToD(to); - return this; - } - - public RouteDefinition route() { - // add to last verb - if (getVerbs().isEmpty()) { - throw new IllegalArgumentException("Must add verb first, such as get/post/delete"); - } - - // link them together so we can navigate using Java DSL - RouteDefinition route = new RouteDefinition(); - route.setRestDefinition(this); - VerbDefinition verb = getVerbs().get(getVerbs().size() - 1); - verb.setRoute(route); - return route; - } - - /** * Build the from endpoint uri for the verb */ public String buildFromUri(VerbDefinition verb) { @@ -804,15 +766,12 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition> private void addRouteDefinition( CamelContext camelContext, List<RouteDefinition> answer, String component, String producerComponent) { for (VerbDefinition verb : getVerbs()) { - // either the verb has a singular to or a embedded route - RouteDefinition route = verb.getRoute(); - if (route == null) { - // it was a singular to, so add a new route and add the singular - // to as output to this route - route = new RouteDefinition(); - ProcessorDefinition def = verb.getTo() != null ? verb.getTo() : verb.getToD(); - route.getOutputs().add(def); + // use a route as facade for this REST service + RouteDefinition route = new RouteDefinition(); + if (verb.getTo() == null) { + throw new IllegalArgumentException("Rest service: " + verb + " must have to endpoint configured."); } + route.getOutputs().add(verb.getTo()); // add the binding RestBindingDefinition binding = new RestBindingDefinition(); diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/VerbDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/VerbDefinition.java index a238bac..732eeaa 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/VerbDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/VerbDefinition.java @@ -24,16 +24,11 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementRef; -import javax.xml.bind.annotation.XmlElements; import javax.xml.bind.annotation.XmlTransient; -import org.apache.camel.model.Block; import org.apache.camel.model.OptionalIdentifiedDefinition; import org.apache.camel.model.OutputNode; -import org.apache.camel.model.ProcessorDefinition; -import org.apache.camel.model.RouteDefinition; import org.apache.camel.model.ToDefinition; -import org.apache.camel.model.ToDynamicDefinition; import org.apache.camel.spi.Metadata; /** @@ -41,7 +36,10 @@ import org.apache.camel.spi.Metadata; */ @Metadata(label = "rest") @XmlAccessorType(XmlAccessType.FIELD) -public abstract class VerbDefinition extends OptionalIdentifiedDefinition<VerbDefinition> implements Block, OutputNode { +public abstract class VerbDefinition extends OptionalIdentifiedDefinition<VerbDefinition> implements OutputNode { + + @XmlTransient + private RestDefinition rest; @XmlElementRef private List<RestOperationParamDefinition> params = new ArrayList<>(); @@ -82,25 +80,8 @@ public abstract class VerbDefinition extends OptionalIdentifiedDefinition<VerbDe private String outType; @XmlTransient private Class<?> outTypeClass; - // used by XML DSL to either select a <to>, <toD>, or <route> - // so we need to use the common type OptionalIdentifiedDefinition - // must select one of them, and hence why they are all set to required = - // true, but the XSD is set to only allow one of the element - @XmlElements({ - @XmlElement(required = true, name = "to", type = ToDefinition.class), - @XmlElement(required = true, name = "toD", type = ToDynamicDefinition.class), - @XmlElement(required = true, name = "route", type = RouteDefinition.class) }) - private OptionalIdentifiedDefinition<?> toOrRoute; - - // the Java DSL uses the to or route definition directory - @XmlTransient + @XmlElement(required = true) private ToDefinition to; - @XmlTransient - private ToDynamicDefinition toD; - @XmlTransient - private RouteDefinition route; - @XmlTransient - private RestDefinition rest; @Override public String getShortName() { @@ -112,15 +93,6 @@ public abstract class VerbDefinition extends OptionalIdentifiedDefinition<VerbDe return "verb"; } - @Override - public void addOutput(ProcessorDefinition<?> processorDefinition) { - if (route == null) { - route = new RouteDefinition(); - } - - route.addOutput(processorDefinition); - } - public String getDeprecated() { return deprecated; } @@ -328,70 +300,24 @@ public abstract class VerbDefinition extends OptionalIdentifiedDefinition<VerbDe this.apiDocs = apiDocs; } - public RestDefinition getRest() { - return rest; - } - - public void setRest(RestDefinition rest) { - this.rest = rest; - } - - public RouteDefinition getRoute() { - if (route != null) { - return route; - } else if (toOrRoute instanceof RouteDefinition) { - return (RouteDefinition) toOrRoute; - } else { - return null; - } - } - - public void setRoute(RouteDefinition route) { - this.route = route; - this.toOrRoute = route; - } - public ToDefinition getTo() { - if (to != null) { - return to; - } else if (toOrRoute instanceof ToDefinition) { - return (ToDefinition) toOrRoute; - } else { - return null; - } - } - - public ToDynamicDefinition getToD() { - if (toD != null) { - return toD; - } else if (toOrRoute instanceof ToDynamicDefinition) { - return (ToDynamicDefinition) toOrRoute; - } else { - return null; - } + return to; } + /** + * The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that + * handles this REST call. + */ public void setTo(ToDefinition to) { this.to = to; - this.toD = null; - this.toOrRoute = to; - } - - public void setToD(ToDynamicDefinition to) { - this.to = null; - this.toD = to; - this.toOrRoute = to; } - public OptionalIdentifiedDefinition<?> getToOrRoute() { - return toOrRoute; + public RestDefinition getRest() { + return rest; } - /** - * To route from this REST service to a Camel endpoint, or an inlined route - */ - public void setToOrRoute(OptionalIdentifiedDefinition<?> toOrRoute) { - this.toOrRoute = toOrRoute; + public void setRest(RestDefinition rest) { + this.rest = rest; } // Fluent API diff --git a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestAdviceWithTest.java b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestAdviceWithTest.java index 80903eb..ef040cc 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestAdviceWithTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestAdviceWithTest.java @@ -37,9 +37,11 @@ public class FromRestAdviceWithTest extends ContextTestSupport { context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { - rest("/say/hello").get().route().routeId("myRoute").transform().constant("Bye World").to("direct:hello"); + rest("/say/hello").get("direct:hello"); - from("direct:hello").to("mock:hello"); + from("direct:hello").routeId("myRoute") + .transform().constant("Bye World") + .to("mock:hello"); } }); diff --git a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java deleted file mode 100644 index b16c328..0000000 --- a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.rest; - -import org.apache.camel.ContextTestSupport; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.model.ToDefinition; -import org.apache.camel.model.rest.RestDefinition; -import org.apache.camel.spi.Registry; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class FromRestGetEmbeddedRouteTest extends ContextTestSupport { - - @Override - protected Registry createRegistry() throws Exception { - Registry jndi = super.createRegistry(); - jndi.bind("dummy-test", new DummyRestConsumerFactory()); - return jndi; - } - - protected int getExpectedNumberOfRoutes() { - return 3; - } - - @Test - public void testFromRestModel() throws Exception { - assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size()); - - assertEquals(2, context.getRestDefinitions().size()); - RestDefinition rest = context.getRestDefinitions().get(0); - assertNotNull(rest); - assertEquals("/say/hello", rest.getPath()); - assertEquals(1, rest.getVerbs().size()); - ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0)); - assertEquals("mock:hello", to.getUri()); - - rest = context.getRestDefinitions().get(1); - assertNotNull(rest); - assertEquals("/say/bye", rest.getPath()); - assertEquals(2, rest.getVerbs().size()); - assertEquals("application/json", rest.getVerbs().get(0).getConsumes()); - to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0)); - assertEquals("mock:bye", to.getUri()); - - // the rest becomes routes and the input is a seda endpoint created by - // the DummyRestConsumerFactory - getMockEndpoint("mock:update").expectedMessageCount(1); - template.sendBody("seda:post-say-bye", "I was here"); - assertMockEndpointsSatisfied(); - - String out = template.requestBody("seda:get-say-hello", "Me", String.class); - assertEquals("Hello World", out); - String out2 = template.requestBody("seda:get-say-bye", "Me", String.class); - assertEquals("Bye World", out2); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - restConfiguration().host("localhost"); - rest("/say/hello").get().route().to("mock:hello").transform(constant("Hello World")); - - rest("/say/bye").get().consumes("application/json").route().to("mock:bye").transform(constant("Bye World")) - .endRest().post().to("mock:update"); - } - }; - } -} diff --git a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java index 2f385b9..c34a450 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java @@ -44,7 +44,7 @@ public class FromRestGetEndPathTest extends FromRestGetTest { assertEquals("/say/bye", rest.getPath()); assertEquals(2, rest.getVerbs().size()); assertEquals("application/json", rest.getVerbs().get(0).getConsumes()); - to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0)); + to = rest.getVerbs().get(0).getTo(); assertEquals("direct:bye", to.getUri()); // the rest becomes routes and the input is a seda endpoint created by @@ -67,7 +67,9 @@ public class FromRestGetEndPathTest extends FromRestGetTest { restConfiguration().host("localhost"); rest("/say/hello").get().to("direct:hello"); - rest("/say/bye").get().consumes("application/json").route().to("direct:bye").endRest().post().to("mock:update"); + rest("/say/bye") + .get().consumes("application/json").to("direct:bye") + .post().to("mock:update"); from("direct:hello").transform().constant("Hello World"); diff --git a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetHttpErrorCodeTest.java b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetHttpErrorCodeTest.java index d3a6b8f..f9c0c50 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetHttpErrorCodeTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetHttpErrorCodeTest.java @@ -57,7 +57,10 @@ public class FromRestGetHttpErrorCodeTest extends ContextTestSupport { @Override public void configure() throws Exception { restConfiguration().host("localhost"); - rest("/say/bye").get().route().choice().when(body().contains("Kaboom")) + rest("/say/bye").get().to("direct:bye"); + + from("direct:bye") + .choice().when(body().contains("Kaboom")) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(404)) .setHeader(Exchange.CONTENT_TYPE, constant("text/plain")).setBody(constant("The data is invalid")) .otherwise().transform().constant("Bye World"); diff --git a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetInterceptTest.java b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetInterceptTest.java index e35da30..c97a05b 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetInterceptTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetInterceptTest.java @@ -52,7 +52,10 @@ public class FromRestGetInterceptTest extends ContextTestSupport { restConfiguration().host("localhost"); intercept().to("mock:intercept"); - rest("/say/hello").get().route().to("mock:hello").to("mock:bar").transform().constant("Bye World"); + rest("/say/hello").get().to("direct:hello"); + + from("direct:hello") + .to("mock:hello").to("mock:bar").transform().constant("Bye World"); } }; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetOnExceptionTest.java b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetOnExceptionTest.java index d25d28a..553c319 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetOnExceptionTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetOnExceptionTest.java @@ -50,7 +50,10 @@ public class FromRestGetOnExceptionTest extends ContextTestSupport { restConfiguration().host("localhost"); onException(IllegalArgumentException.class).handled(true).transform().constant("Handled the error"); - rest("/say/hello").get().route().to("mock:hello").throwException(new IllegalArgumentException("Forced")); + rest("/say/hello").get().to("direct:hello"); + + from("direct:hello") + .to("mock:hello").throwException(new IllegalArgumentException("Forced")); } }; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetPolicyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetPolicyTest.java index c1d4728..07729e9 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetPolicyTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetPolicyTest.java @@ -54,7 +54,10 @@ public class FromRestGetPolicyTest extends ContextTestSupport { public void configure() throws Exception { restConfiguration().host("localhost"); - rest("/say/hello").get().route().policy(new MyDummyPolicy()).to("mock:hello"); + rest("/say/hello").get().to("direct:hello"); + + from("direct:hello") + .policy(new MyDummyPolicy()).to("mock:hello"); } }; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetRouteOnExceptionTest.java b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetRouteOnExceptionTest.java index 69a1ee9..f96eac7 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetRouteOnExceptionTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetRouteOnExceptionTest.java @@ -26,7 +26,9 @@ public class FromRestGetRouteOnExceptionTest extends FromRestGetOnExceptionTest @Override public void configure() throws Exception { restConfiguration().host("localhost"); - rest("/say/hello").get().route().onException(IllegalArgumentException.class).handled(true).transform() + rest("/say/hello").get().to("direct:hello"); + + from("direct:hello").onException(IllegalArgumentException.class).handled(true).transform() .constant("Handled the error").end().to("mock:hello") .throwException(new IllegalArgumentException("Forced")); } diff --git a/core/camel-core/src/test/java/org/apache/camel/model/XmlRestParseToDTest.java b/core/camel-core/src/test/java/org/apache/camel/model/XmlRestParseToDTest.java deleted file mode 100644 index a0e2430..0000000 --- a/core/camel-core/src/test/java/org/apache/camel/model/XmlRestParseToDTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.model; - -import javax.xml.bind.JAXBException; - -import org.apache.camel.model.rest.GetDefinition; -import org.apache.camel.model.rest.RestContainer; -import org.apache.camel.model.rest.RestDefinition; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class XmlRestParseToDTest extends XmlTestSupport { - - @Test - public void testParseSimpleRestXml() throws Exception { - RestDefinition rest = assertOneRest("simpleRestToD.xml"); - assertEquals("/users", rest.getPath()); - - assertEquals(1, rest.getVerbs().size()); - GetDefinition get = (GetDefinition) rest.getVerbs().get(0); - assertEquals("/view/{id}", get.getPath()); - assertEquals("bean:getUser?id=${header.id}", get.getToD().getUri()); - } - - protected RestDefinition assertOneRest(String uri) throws JAXBException { - RestContainer context = assertParseRestAsJaxb(uri); - RestDefinition rest = assertOneElement(context.getRests()); - return rest; - } - -} diff --git a/core/camel-core/src/test/resources/org/apache/camel/model/simpleRestToD.xml b/core/camel-core/src/test/resources/org/apache/camel/model/simpleRestToD.xml deleted file mode 100644 index 4374076..0000000 --- a/core/camel-core/src/test/resources/org/apache/camel/model/simpleRestToD.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<rests xmlns="http://camel.apache.org/schema/spring"> - - <rest path="/users"> - <get path="/view/{id}"> - <toD uri="bean:getUser?id=${header.id}"/> - </get> - </rest> - -</rests> diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedFromRestGetEmbeddedRouteTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedFromRestGetEmbeddedRouteTest.java deleted file mode 100644 index 5c85250..0000000 --- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedFromRestGetEmbeddedRouteTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.management; - -import javax.management.MBeanServer; -import javax.management.ObjectName; - -import org.apache.camel.CamelContext; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.rest.DummyRestConsumerFactory; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledOnOs; -import org.junit.jupiter.api.condition.OS; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -@DisabledOnOs(OS.AIX) -public class ManagedFromRestGetEmbeddedRouteTest extends ManagementTestSupport { - - @Override - protected CamelContext createCamelContext() throws Exception { - CamelContext context = super.createCamelContext(); - context.getRegistry().bind("dummy-test", new DummyRestConsumerFactory()); - return context; - } - - @Test - public void testFromRestModel() throws Exception { - MBeanServer mbeanServer = getMBeanServer(); - - ObjectName on = getContextObjectName(); - - String xml = (String) mbeanServer.invoke(on, "dumpRestsAsXml", null, null); - assertNotNull(xml); - log.info(xml); - - assertTrue(xml.contains("<rests")); - assertTrue(xml.contains("<rest path=\"/say/hello\">")); - assertTrue(xml.contains("<rest path=\"/say/bye\">")); - assertTrue(xml.contains("</rest>")); - assertTrue(xml.contains("<get")); - assertTrue(xml.contains("<route")); - assertTrue(xml.contains("<transform")); - assertTrue(xml.contains("<post")); - assertTrue(xml.contains("application/json")); - assertTrue(xml.contains("</rests>")); - - String xml2 = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null); - log.info(xml2); - // and we should have rest in the routes that indicate its from a rest dsl - assertTrue(xml2.contains("rest=\"true\"")); - - // there should be 2 + 1 routes - assertEquals(2 + 1, context.getRouteDefinitions().size()); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - restConfiguration().host("localhost"); - rest("/say/hello") - .get() - .route() - .to("mock:hello") - .transform(constant("Hello World")); - - rest("/say/bye") - .get().consumes("application/json") - .route() - .to("mock:bye") - .transform(constant("Bye World")) - .endRest() - .post() - .to("mock:update"); - } - }; - } -} diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedRestRegistryTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedRestRegistryTest.java index 2707ef1..16ba651 100644 --- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedRestRegistryTest.java +++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedRestRegistryTest.java @@ -94,13 +94,15 @@ public class ManagedRestRegistryTest extends ManagementTestSupport { .get().to("direct:hello").description("Calling direct route"); rest("/say/bye").description("the bye rest service") - .get().consumes("application/json").description("I am saying bye world") - .route().routeId("myRestRoute").transform().constant("Bye World").endRest() - .post() - .to("mock:update"); + .get().consumes("application/json").description("I am saying bye world").to("direct:bye") + .post().to("mock:update"); from("direct:hello").description("The hello route") .transform().simple("Hello ${header.name}"); + + from("direct:bye").description("The bye route") + .transform().constant("Bye World"); + } }; } diff --git a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java index 5ff0aaf..f901428 100644 --- a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java +++ b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java @@ -2831,9 +2831,7 @@ public class ModelParser extends BaseParser { case "param": doAdd(doParseRestOperationParamDefinition(), def.getParams(), def::setParams); break; case "responseMessage": doAdd(doParseRestOperationResponseMsgDefinition(), def.getResponseMsgs(), def::setResponseMsgs); break; case "security": doAdd(doParseSecurityDefinition(), def.getSecurity(), def::setSecurity); break; - case "to": def.setToOrRoute(doParseToDefinition()); break; - case "toD": def.setToOrRoute(doParseToDynamicDefinition()); break; - case "route": def.setToOrRoute(doParseRouteDefinition()); break; + case "to": def.setTo(doParseToDefinition()); break; default: return optionalIdentifiedDefinitionElementHandler().accept(def, key); } return true; diff --git a/core/camel-xml-io/src/test/resources/simpleRestToD.xml b/core/camel-xml-io/src/test/resources/simpleRestToD.xml deleted file mode 100644 index 4374076..0000000 --- a/core/camel-xml-io/src/test/resources/simpleRestToD.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<rests xmlns="http://camel.apache.org/schema/spring"> - - <rest path="/users"> - <get path="/view/{id}"> - <toD uri="bean:getUser?id=${header.id}"/> - </get> - </rest> - -</rests>
