Claus Ibsen created CAMEL-27703:
-----------------------------------

             Summary: camel-servicenow: GENEVA NPE, model prefixes and maps, 
cart/items dispatch and paths, metadata
                 Key: CAMEL-27703
                 URL: https://issues.apache.org/jira/browse/CAMEL-27703
             Project: Camel
          Issue Type: Bug
          Components: camel-servicenow
            Reporter: Claus Ibsen
             Fix For: 4.24.0


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

h4. 1. release=GENEVA fails with a NullPointerException
{{ServiceNowRelease.GENEVA.get()}} returns null, and 
{{ServiceNowEndpoint.createProducer()}} then calls {{producer.getRelease()}} in 
its log statement. GENEVA is offered in the enum of the {{release}} option, so 
a user who picks it gets an NPE when the producer is created.
Proposed change: remove GENEVA from the enum (or map it to the Fuji or Helsinki 
producer), and fail with a clear message for an unsupported release.

h4. 2. The request-model. and response-model. prefixes are not read
The metadata of {{requestModels}} and {{responseModels}} gives the prefixes 
{{request-model.}} and {{response-model.}}, but 
{{ServiceNowComponent.createEndpoint()}} extracts {{requestModel.}} and 
{{responseModel.}}. An endpoint URI with the documented 
{{request-model.incident=...}} leaves the parameter unconsumed, and endpoint 
creation fails with an unknown parameter.
Proposed change: make the code and the {{@UriParam}} prefixes the same (accept 
both forms for compatibility).

h4. 3. Only the last response model is kept
{{ServiceNowConfiguration.addResponseModel()}} calls {{responseModels.clear()}} 
before each put. With {{model.a=...&model.b=...}} on the URI, 
{{createEndpoint()}} calls {{addModel()}} per entry, so only the last table 
keeps its response model and the others fall back to a Map. Also 
{{setResponseModels()}} does not clear the map, while {{setRequestModels()}} 
does.
Proposed change: remove the {{clear()}} from {{addResponseModel()}} and make 
the two setters behave the same.

h4. 4. Endpoints share the model maps of the component configuration
{{ServiceNowConfiguration.copy()}} is a shallow {{clone()}}. When the component 
configuration has request or response models, each endpoint copy shares the 
same {{HashMap}}, and the models that {{createEndpoint()}} adds for one 
endpoint URI change the component configuration and every other endpoint.
Proposed change: copy the two maps in {{copy()}}.

h4. 5. getResponseModel(Message) returns the request model
{{AbstractServiceNowProcessor.getResponseModel(Message)}} calls 
{{getRequestModel(message, null)}}. The service catalog, cart, categories, misc 
and scorecards processors use this method, so they read the 
{{CamelServiceNowRequestModel}} header for the response and ignore 
{{CamelServiceNowResponseModel}}.
Proposed change: call {{getResponseModel(message, null)}}.

h4. 6. retrieve on service_catalog_cart without a subject fails
{{HelsinkiServiceNowServiceCatalogCartsProcessor}} registers 
{{retrieveCheckoutCart}} and {{retrieveCarts}} for the same action and subject 
(retrieve, checkout). The first one always wins, so {{retrieveCarts}} (GET 
/sn_sc/servicecatalog/cart) is never called, and retrieve without a subject 
fails with "Unable to process exchange".
Proposed change: register {{retrieveCarts}} for retrieve with no subject.

h4. 7. Wrong paths and a missing body in service_catalog_items
In {{HelsinkiServiceNowServiceCatalogItemsProcessor}}:
* {{retrieveItems()}} with a sys_id calls 
{{/sn_sc/\{version\}/items/items/\{sys_id\}}} instead of 
{{/sn_sc/\{version\}/servicecatalog/items/\{sys_id\}}}.
* {{checkoutItemGuide()}} posts to {{.../items/\{sys_id\}/submit_guide}} 
instead of {{checkout_guide}}, so it does the same as the submit_guide subject.
* {{addItemToCart()}} posts with no body, so the message body (sysparm_quantity 
and the variables) is not sent.
Proposed change: fix the two paths and send the body for add_to_cart.

h4. 8. sysparm_query is sent twice by the aggregate resource
{{FujiServiceNowAggregateProcessor}} and 
{{HelsinkiServiceNowAggregateProcessor}} call 
{{.query(ServiceNowParams.SYSPARM_QUERY, in)}} twice, so the stats request 
carries the parameter twice.
Proposed change: remove the second call.

h4. 9. The attachment upload ignores the table option
{{HelsinkiServiceNowAttachmentProcessor.uploadContent()}} sets {{table_name}} 
with {{ServiceNowParams.PARAM_TABLE_NAME}}, which has no default from the 
configuration, so only the {{CamelServiceNowTable}} header is used and the 
{{table}} option is not. The other actions fall back to the {{table}} option.
Proposed change: fall back to the {{table}} option, as {{getTableName()}} does.

h4. 10. The model headers set after a call affect the next call
{{AbstractServiceNowProcessor.setHeaders()}} puts {{CamelServiceNowModel}} and 
{{CamelServiceNowResponseModel}} with the name of the response model class when 
they are absent. A following ServiceNow call in the same route then uses that 
class as its request and response model, also for another table.
Proposed change: do not set the input headers {{CamelServiceNowModel}} and 
{{CamelServiceNowResponseModel}} on the result, or document it in the upgrade 
guide if it is removed.

h4. 11. Undocumented headers
The producer sets {{CamelServiceNowOffsetNext}}, {{CamelServiceNowOffsetPrev}}, 
{{CamelServiceNowOffsetFirst}}, {{CamelServiceNowOffsetLast}} (from the Link 
header, in {{ServiceNowHelper.findOffsets()}}) and 
{{CamelServiceNowContentEncoding}}, but {{ServiceNowConstants}} has no 
{{@Metadata}} for them, so they are missing from the header list of the 
documentation.
Proposed change: add {{@Metadata}} with a description and javaType.

h4. 12. Metadata of oauthTokenUrl and apiUrl
{{oauthTokenUrl}} is marked {{security = "secret"}}, though it is a URL and not 
a secret, so tools mask it. {{apiUrl}} has the label {{security}}, though it is 
the base URL of the REST API.
Proposed change: remove the secret flag of {{oauthTokenUrl}}, and give both URL 
options a label such as {{common}} or {{advanced}}.

_Claude Code on behalf of davsclaus_



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

Reply via email to