This is an automated email from the ASF dual-hosted git repository. nfilotto pushed a commit to branch CAMEL-17792/doc-message-headers in repository https://gitbox.apache.org/repos/asf/camel.git
commit e121c3e7ada6b26d22c7de6f1a7ef3b06d01133e Author: Nicolas Filotto <nfilo...@talend.com> AuthorDate: Mon Apr 4 17:20:15 2022 +0200 CAMEL-17792: Add doc about the message headers of camel-rest --- .../org/apache/camel/component/rest/rest.json | 8 ++++ .../camel-rest/src/main/docs/rest-component.adoc | 4 +- .../apache/camel/component/rest/RestConstants.java | 44 ++++++++++++++++++++++ .../apache/camel/component/rest/RestEndpoint.java | 2 +- .../apache/camel/component/rest/RestProducer.java | 15 ++++---- .../rest/RestProducerBindingProcessor.java | 8 ++-- 6 files changed, 67 insertions(+), 14 deletions(-) diff --git a/components/camel-rest/src/generated/resources/org/apache/camel/component/rest/rest.json b/components/camel-rest/src/generated/resources/org/apache/camel/component/rest/rest.json index 2ae80f02515..251211a32db 100644 --- a/components/camel-rest/src/generated/resources/org/apache/camel/component/rest/rest.json +++ b/components/camel-rest/src/generated/resources/org/apache/camel/component/rest/rest.json @@ -32,6 +32,14 @@ "producerComponentName": { "kind": "property", "displayName": "Producer Component Name", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel Rest component to use for (producer) the REST transport, such as http, undertow. If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the [...] "autowiredEnabled": { "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which t [...] }, + "headers": { + "CamelRestHttpQuery": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The query parameters for the rest call to be used" }, + "CamelRestHttpUri": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The http uri for the rest call to be used" }, + "CamelHttpMethod": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The method should be in upper case" }, + "Content-Type": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The media type such as: 'text\/xml', or 'application\/json' this REST service returns." }, + "Accept": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The media type such as: 'text\/xml', or 'application\/json' this REST service accepts." }, + "CamelHttpResponseCode": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "Integer", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The http response code" } + }, "properties": { "method": { "kind": "path", "displayName": "Method", "group": "common", "label": "common", "required": true, "type": "string", "javaType": "java.lang.String", "enum": [ "get", "post", "put", "delete", "patch", "head", "trace", "connect", "options" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "HTTP method to use." }, "path": { "kind": "path", "displayName": "Path", "group": "common", "label": "common", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The base path" }, diff --git a/components/camel-rest/src/main/docs/rest-component.adoc b/components/camel-rest/src/main/docs/rest-component.adoc index 46496df0afd..d6b9568e3e9 100644 --- a/components/camel-rest/src/main/docs/rest-component.adoc +++ b/components/camel-rest/src/main/docs/rest-component.adoc @@ -38,7 +38,9 @@ include::partial$component-endpoint-options.adoc[] // endpoint options: START // endpoint options: END - +// component headers: START +include::partial$component-endpoint-headers.adoc[] +// component headers: END == Supported rest components diff --git a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestConstants.java b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestConstants.java new file mode 100644 index 00000000000..1e3973a19ca --- /dev/null +++ b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestConstants.java @@ -0,0 +1,44 @@ +/* + * 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.Exchange; +import org.apache.camel.spi.Metadata; + +public final class RestConstants { + + @Metadata(label = "producer", description = "The query parameters for the rest call to be used", javaType = "String") + public static final String REST_HTTP_QUERY = Exchange.REST_HTTP_QUERY; + @Metadata(label = "producer", description = "The http uri for the rest call to be used", javaType = "String") + public static final String REST_HTTP_URI = Exchange.REST_HTTP_URI; + @Metadata(label = "producer", description = "The method should be in upper case", javaType = "String") + public static final String HTTP_METHOD = Exchange.HTTP_METHOD; + @Metadata(label = "producer", + description = "The media type such as: 'text/xml', or 'application/json' this REST service returns.", + javaType = "String") + public static final String CONTENT_TYPE = Exchange.CONTENT_TYPE; + @Metadata(label = "producer", + description = "The media type such as: 'text/xml', or 'application/json' this REST service accepts.", + javaType = "String") + public static final String ACCEPT = "Accept"; + @Metadata(label = "producer", description = "The http response code", javaType = "Integer") + public static final String HTTP_RESPONSE_CODE = Exchange.HTTP_RESPONSE_CODE; + + private RestConstants() { + + } +} diff --git a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java index e81cec871c7..5672a9a9730 100644 --- a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java +++ b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java @@ -50,7 +50,7 @@ import static org.apache.camel.support.RestProducerFactoryHelper.setupComponent; * Expose REST services or call external REST services. */ @UriEndpoint(firstVersion = "2.14.0", scheme = "rest", title = "REST", syntax = "rest:method:path:uriTemplate", - category = { Category.CORE, Category.REST }, lenientProperties = true) + category = { Category.CORE, Category.REST }, lenientProperties = true, headersClass = RestConstants.class) public class RestEndpoint extends DefaultEndpoint { public static final String[] DEFAULT_REST_CONSUMER_COMPONENTS diff --git a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducer.java b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducer.java index 7d701bf7ead..2835ff49a64 100644 --- a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducer.java +++ b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducer.java @@ -52,7 +52,6 @@ import static org.apache.camel.util.ObjectHelper.isNotEmpty; */ public class RestProducer extends DefaultAsyncProducer { - private static final String ACCEPT = "Accept"; private final CamelContext camelContext; private final RestConfiguration configuration; private boolean prepareUriTemplate = true; @@ -177,7 +176,7 @@ public class RestProducer extends DefaultAsyncProducer { if (query != null) { // the query parameters for the rest call to be used - inMessage.setHeader(Exchange.REST_HTTP_QUERY, query); + inMessage.setHeader(RestConstants.REST_HTTP_QUERY, query); } if (hasPath) { @@ -194,7 +193,7 @@ public class RestProducer extends DefaultAsyncProducer { overrideUri += "/" + resolvedUriTemplate; } // the http uri for the rest call to be used - inMessage.setHeader(Exchange.REST_HTTP_URI, overrideUri); + inMessage.setHeader(RestConstants.REST_HTTP_URI, overrideUri); // when chaining RestConsumer with RestProducer, the // HTTP_PATH header will be present, we remove it here @@ -209,17 +208,17 @@ public class RestProducer extends DefaultAsyncProducer { if (method != null) { // the method should be in upper case String upper = method.toUpperCase(Locale.US); - inMessage.setHeader(Exchange.HTTP_METHOD, upper); + inMessage.setHeader(RestConstants.HTTP_METHOD, upper); } final String produces = getEndpoint().getProduces(); - if (isEmpty(inMessage.getHeader(Exchange.CONTENT_TYPE)) && isNotEmpty(produces)) { - inMessage.setHeader(Exchange.CONTENT_TYPE, produces); + if (isEmpty(inMessage.getHeader(RestConstants.CONTENT_TYPE)) && isNotEmpty(produces)) { + inMessage.setHeader(RestConstants.CONTENT_TYPE, produces); } final String consumes = getEndpoint().getConsumes(); - if (isEmpty(inMessage.getHeader(ACCEPT)) && isNotEmpty(consumes)) { - inMessage.setHeader(ACCEPT, consumes); + if (isEmpty(inMessage.getHeader(RestConstants.ACCEPT)) && isNotEmpty(consumes)) { + inMessage.setHeader(RestConstants.ACCEPT, consumes); } } diff --git a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducerBindingProcessor.java b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducerBindingProcessor.java index 2fc4bdb4d6d..32db587dea3 100644 --- a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducerBindingProcessor.java +++ b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducerBindingProcessor.java @@ -270,7 +270,7 @@ public class RestProducerBindingProcessor extends DelegateAsyncProcessor { } if (skipBindingOnErrorCode) { - Integer code = exchange.getMessage().getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class); + Integer code = exchange.getMessage().getHeader(RestConstants.HTTP_RESPONSE_CODE, Integer.class); // if there is a custom http error code then skip binding if (code != null && code >= 300) { return; @@ -327,7 +327,7 @@ public class RestProducerBindingProcessor extends DelegateAsyncProcessor { return; } - contentType = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class); + contentType = exchange.getIn().getHeader(RestConstants.CONTENT_TYPE, String.class); // need to lower-case so the contains check below can match if using upper case contentType = contentType.toLowerCase(Locale.US); try { @@ -367,13 +367,13 @@ public class RestProducerBindingProcessor extends DelegateAsyncProcessor { // make sure there is a content-type with json String type = ExchangeHelper.getContentType(exchange); if (type == null) { - exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json"); + exchange.getIn().setHeader(RestConstants.CONTENT_TYPE, "application/json"); } } else if (isXml) { // make sure there is a content-type with xml String type = ExchangeHelper.getContentType(exchange); if (type == null) { - exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/xml"); + exchange.getIn().setHeader(RestConstants.CONTENT_TYPE, "application/xml"); } } }