Claus Ibsen created CAMEL-27662:
-----------------------------------

             Summary: camel-rest: null host from port, apiDoc host unused, dead 
swagger lookup, rest-api metadata
                 Key: CAMEL-27662
                 URL: https://issues.apache.org/jira/browse/CAMEL-27662
             Project: Camel
          Issue Type: Bug
          Components: rest
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while improving the option descriptions of camel-rest for CAMEL-23832 
(commit 
https://github.com/apache/camel/commit/c7124889e3a4b82a8c7a16e44c2aa8c94310d02b).
These are separate problems of the component; the descriptions commit only 
documents the current behavior.

h4. 1. The producer calls http://null:<port> when the rest configuration has a 
port but no host
In {{RestComponent.createEndpoint()}}, when the endpoint and the component have 
no {{host}}, the host is taken from the rest configuration and its port is 
appended when it is not 80 or 443. When the rest configuration has a port (as 
is usual for the consumer, e.g. {{restConfiguration().port(8080)}}) but no 
host, {{config.getHost()}} is null and the result is {{null:8080}}, which then 
becomes {{http://null:8080}}. {{RestEndpoint.validateHost()}} does not catch 
it, so the producer starts and sends the request to the host {{null}}, instead 
of failing with the message that a host must be configured.
{code:java}
h = config.getHost();
int port = config.getPort();
if (port > 0 && port != 80 && port != 443) {
    h += ":" + port;   // "null:8080" when the host is not set
}
{code}
Append the port only when the host of the rest configuration is set.

h4. 2. With apiDoc, the host and base path of the OpenAPI document are never 
used
{{RestEndpoint.createProducer()}} calls {{validateHost()}} before it creates 
the apiDoc factory, so a host is required. 
{{OpenApiRestProducerFactory.createHttpProducer()}} has a branch that takes the 
host and base path from the OpenAPI document when {{host}} is null, which is 
therefore never reached through the rest component. The old option text 
("override host in openapi schema") suggested that the host is optional with 
{{apiDoc}}.
Either allow an empty host when {{apiDoc}} is set, so the host of the document 
is used, or remove the unreachable branch.

h4. 3. RestApiEndpoint.createProducer() falls back to a swagger module that 
does not exist
When no {{RestApiProcessorFactory}} is found for the configured name (or 
{{openapi}}), {{RestApiEndpoint.createProducer()}} looks up 
{{restapi/swagger}}, which no Camel 4 module provides. When 
{{apiComponentName}} or the {{apiComponent}} of the rest configuration is set, 
the second lookup repeats the first with the same name.
Remove the second lookup.

h4. 4. rest-api is marked consumerOnly, but the Rest DSL sends to it
{{RestDefinition.asRouteApiDefinition()}} creates the API route as 
{{from("rest-api:X")}} {{.to("rest-api:X")}}, and {{DefaultRestRegistry}} also 
creates a producer of a rest-api endpoint. {{apiComponentName}} is read only by 
{{RestApiEndpoint.createProducer()}}. The {{@UriEndpoint}} of 
{{RestApiEndpoint}} has {{consumerOnly = true}}, and the endpoint options 
{{consumerComponentName}} and {{apiComponentName}} have no label.
Remove {{consumerOnly}} (or document the producer as internal), and label 
{{consumerComponentName}} as consumer and {{apiComponentName}} as producer.

h4. 5. routeId of rest is labeled common, but only the consumer reads it
{{routeId}} of {{RestEndpoint}} is labeled {{common}}, but only 
{{createConsumer()}} reads it (it goes to the rest registry). The producer 
ignores it.
Label it {{consumer}}.

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to