You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2024/04/12 08:33:19 UTC
(camel) 06/07: (chores) camel-core-model: extract independent code snippets from large code blocks
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 7e7a04dc045b2285e1c49be1dc829fa19cb85a72
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Thu Apr 11 13:35:20 2024 +0200
(chores) camel-core-model: extract independent code snippets from large code blocks
---
.../apache/camel/model/ProcessorDefinition.java | 25 ++++----
.../apache/camel/model/rest/RestDefinition.java | 68 +++++++++++++---------
2 files changed, 54 insertions(+), 39 deletions(-)
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 8adb212460b..bff79bdb6ad 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
@@ -782,17 +782,9 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
// set it on last output as this is what the user means to do
// for Block(s) with non empty getOutputs() the id probably refers
// to the last definition in the current Block
- List<ProcessorDefinition<?>> outputs = getOutputs();
- if (!blocks.isEmpty()) {
- if (blocks.getLast() instanceof ProcessorDefinition) {
- ProcessorDefinition<?> block = (ProcessorDefinition<?>) blocks.getLast();
- if (!block.getOutputs().isEmpty()) {
- outputs = block.getOutputs();
- }
- }
- }
+ final List<ProcessorDefinition<?>> definitions = getProcessorDefinitions();
if (!getOutputs().isEmpty()) {
- outputs.get(outputs.size() - 1).setDisabled(disabled);
+ definitions.get(definitions.size() - 1).setDisabled(disabled);
} else {
// the output could be empty
setDisabled(disabled);
@@ -802,6 +794,19 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
return asType();
}
+ private List<ProcessorDefinition<?>> getProcessorDefinitions() {
+ List<ProcessorDefinition<?>> outputs = getOutputs();
+ if (!blocks.isEmpty()) {
+ if (blocks.getLast() instanceof ProcessorDefinition) {
+ ProcessorDefinition<?> block = (ProcessorDefinition<?>) blocks.getLast();
+ if (!block.getOutputs().isEmpty()) {
+ outputs = block.getOutputs();
+ }
+ }
+ }
+ return outputs;
+ }
+
/**
* <a href="http://camel.apache.org/multicast.html">Multicast EIP:</a> Multicasts messages to all its child outputs;
* so that each processor and destination gets a copy of the original message to avoid the processors interfering
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 a716672a2ee..5b0bc0d8394 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
@@ -979,28 +979,7 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
// add dummy empty stop
route.getOutputs().add(new StopDefinition());
- String mode = getBindingMode();
- if (mode == null) {
- mode = camelContext.getRestConfiguration().getBindingMode().name();
- }
-
- RestBindingDefinition binding = new RestBindingDefinition();
- binding.setComponent(component);
- if ("json".equals(mode)) {
- binding.setConsumes("application/json");
- binding.setProduces("application/json");
- } else if ("xml".equals(mode)) {
- binding.setConsumes("application/xml");
- binding.setProduces("application/xml");
- } else if ("json_xml".equals(mode)) {
- binding.setConsumes("application/json;application/xml");
- binding.setProduces("application/json;application/xml");
- }
- binding.setBindingMode(mode);
- binding.setSkipBindingOnErrorCode(getSkipBindingOnErrorCode());
- binding.setClientRequestValidation(getClientRequestValidation());
- binding.setEnableCORS(getEnableCORS());
- binding.setEnableNoContentResponse(getEnableNoContentResponse());
+ final RestBindingDefinition binding = getRestBindingDefinition(camelContext, component);
route.setRestBindingDefinition(binding);
// append options
@@ -1053,6 +1032,32 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
answer.add(route);
}
+ private RestBindingDefinition getRestBindingDefinition(CamelContext camelContext, String component) {
+ String mode = getBindingMode();
+ if (mode == null) {
+ mode = camelContext.getRestConfiguration().getBindingMode().name();
+ }
+
+ RestBindingDefinition binding = new RestBindingDefinition();
+ binding.setComponent(component);
+ if ("json".equals(mode)) {
+ binding.setConsumes("application/json");
+ binding.setProduces("application/json");
+ } else if ("xml".equals(mode)) {
+ binding.setConsumes("application/xml");
+ binding.setProduces("application/xml");
+ } else if ("json_xml".equals(mode)) {
+ binding.setConsumes("application/json;application/xml");
+ binding.setProduces("application/json;application/xml");
+ }
+ binding.setBindingMode(mode);
+ binding.setSkipBindingOnErrorCode(getSkipBindingOnErrorCode());
+ binding.setClientRequestValidation(getClientRequestValidation());
+ binding.setEnableCORS(getEnableCORS());
+ binding.setEnableNoContentResponse(getEnableNoContentResponse());
+ return binding;
+ }
+
private void addRouteDefinition(
CamelContext camelContext, List<VerbDefinition> verbs, List<RouteDefinition> answer,
String component, String producerComponent) {
@@ -1186,13 +1191,7 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
// description 2) verb description 3) rest description
// this allows end users to define general descriptions and override
// then per to/route or verb
- String description = verb.getTo() != null ? verb.getTo().getDescriptionText() : route.getDescriptionText();
- if (description == null) {
- description = verb.getDescriptionText();
- }
- if (description == null) {
- description = getDescriptionText();
- }
+ final String description = getDescription(verb, route);
if (description != null) {
options.put("description", parseText(camelContext, description));
}
@@ -1275,6 +1274,17 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
}
}
+ private String getDescription(VerbDefinition verb, RouteDefinition route) {
+ String description = verb.getTo() != null ? verb.getTo().getDescriptionText() : route.getDescriptionText();
+ if (description == null) {
+ description = verb.getDescriptionText();
+ }
+ if (description == null) {
+ description = getDescriptionText();
+ }
+ return description;
+ }
+
private Set<String> uriTemplating(
CamelContext camelContext, VerbDefinition verb,
String path, boolean query) {