This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 4177af0d68b camel-jbang - camel-rest is optional and the rest dev
console should support this.
4177af0d68b is described below
commit 4177af0d68b128a11c46d67dd3724ec0b6d305e6
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Sep 4 07:17:08 2024 +0200
camel-jbang - camel-rest is optional and the rest dev console should
support this.
---
.../apache/camel/impl/console/RestDevConsole.java | 108 ++++++++++++---------
1 file changed, 61 insertions(+), 47 deletions(-)
diff --git
a/core/camel-console/src/main/java/org/apache/camel/impl/console/RestDevConsole.java
b/core/camel-console/src/main/java/org/apache/camel/impl/console/RestDevConsole.java
index ec9c4636586..c2fd1c4143a 100644
---
a/core/camel-console/src/main/java/org/apache/camel/impl/console/RestDevConsole.java
+++
b/core/camel-console/src/main/java/org/apache/camel/impl/console/RestDevConsole.java
@@ -32,35 +32,48 @@ public class RestDevConsole extends AbstractDevConsole {
super("camel", "rest", "Rest", "Rest DSL Registry information");
}
+ private RestRegistry rr;
+
+ @Override
+ protected void doInit() throws Exception {
+ super.doInit();
+ try {
+ rr = getCamelContext().getRestRegistry();
+ } catch (IllegalArgumentException e) {
+ // ignore as this is optional
+ }
+ }
+
@Override
protected String doCallText(Map<String, Object> options) {
StringBuilder sb = new StringBuilder();
- RestRegistry rr = getCamelContext().getRestRegistry();
- for (RestRegistry.RestService rs : rr.listAllRestServices()) {
- if (!sb.isEmpty()) {
- sb.append("\n");
- }
- sb.append(String.format("\n Url: %s", rs.getUrl()));
- sb.append(String.format("\n Method: %s", rs.getMethod()));
- sb.append(String.format("\n State: %s", rs.getState()));
- if (rs.getConsumes() != null) {
- sb.append(String.format("\n Consumes: %s",
rs.getConsumes()));
- }
- if (rs.getProduces() != null) {
- sb.append(String.format("\n Produces: %s",
rs.getProduces()));
- }
- if (rs.getInType() != null) {
- sb.append(String.format("\n In Type: %s", rs.getInType()));
- }
- if (rs.getOutType() != null) {
- sb.append(String.format("\n Out Type: %s",
rs.getOutType()));
- }
- if (rs.getDescription() != null) {
- sb.append(String.format("\n Description: %s",
rs.getDescription()));
+ if (rr != null) {
+ for (RestRegistry.RestService rs : rr.listAllRestServices()) {
+ if (!sb.isEmpty()) {
+ sb.append("\n");
+ }
+ sb.append(String.format("\n Url: %s", rs.getUrl()));
+ sb.append(String.format("\n Method: %s", rs.getMethod()));
+ sb.append(String.format("\n State: %s", rs.getState()));
+ if (rs.getConsumes() != null) {
+ sb.append(String.format("\n Consumes: %s",
rs.getConsumes()));
+ }
+ if (rs.getProduces() != null) {
+ sb.append(String.format("\n Produces: %s",
rs.getProduces()));
+ }
+ if (rs.getInType() != null) {
+ sb.append(String.format("\n In Type: %s",
rs.getInType()));
+ }
+ if (rs.getOutType() != null) {
+ sb.append(String.format("\n Out Type: %s",
rs.getOutType()));
+ }
+ if (rs.getDescription() != null) {
+ sb.append(String.format("\n Description: %s",
rs.getDescription()));
+ }
}
+ sb.append("\n");
}
- sb.append("\n");
return sb.toString();
}
@@ -69,32 +82,33 @@ public class RestDevConsole extends AbstractDevConsole {
protected Map<String, Object> doCallJson(Map<String, Object> options) {
JsonObject root = new JsonObject();
- List<JsonObject> list = new ArrayList<>();
- root.put("rests", list);
+ if (rr != null) {
+ List<JsonObject> list = new ArrayList<>();
+ root.put("rests", list);
- RestRegistry rr = getCamelContext().getRestRegistry();
- for (RestRegistry.RestService rs : rr.listAllRestServices()) {
- JsonObject jo = new JsonObject();
- jo.put("url", rs.getUrl());
- jo.put("method", rs.getMethod());
- jo.put("contractFirst", rs.isContractFirst());
- jo.put("state", rs.getState());
- if (rs.getConsumes() != null) {
- jo.put("consumes", rs.getConsumes());
- }
- if (rs.getProduces() != null) {
- jo.put("produces", rs.getProduces());
- }
- if (rs.getInType() != null) {
- jo.put("inType", rs.getInType());
- }
- if (rs.getOutType() != null) {
- jo.put("outType", rs.getOutType());
- }
- if (rs.getDescription() != null) {
- jo.put("description", rs.getDescription());
+ for (RestRegistry.RestService rs : rr.listAllRestServices()) {
+ JsonObject jo = new JsonObject();
+ jo.put("url", rs.getUrl());
+ jo.put("method", rs.getMethod());
+ jo.put("contractFirst", rs.isContractFirst());
+ jo.put("state", rs.getState());
+ if (rs.getConsumes() != null) {
+ jo.put("consumes", rs.getConsumes());
+ }
+ if (rs.getProduces() != null) {
+ jo.put("produces", rs.getProduces());
+ }
+ if (rs.getInType() != null) {
+ jo.put("inType", rs.getInType());
+ }
+ if (rs.getOutType() != null) {
+ jo.put("outType", rs.getOutType());
+ }
+ if (rs.getDescription() != null) {
+ jo.put("description", rs.getDescription());
+ }
+ list.add(jo);
}
- list.add(jo);
}
return root;