Claus Ibsen created CAMEL-26021:
-----------------------------------

             Summary: camel-solr - the deleteByQuery default, a converter that 
turns anything into an empty Map, and bodies that are not sent
                 Key: CAMEL-26021
                 URL: https://issues.apache.org/jira/browse/CAMEL-26021
             Project: Camel
          Issue Type: Bug
          Components: camel-solr
    Affects Versions: 4.18.0, 4.22.0, 4.23.0
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while checking the body types of the solr component for the catalog 
(CAMEL-24961).

h4. 1. The catalog says deleteByQuery defaults to true, the code to false

The catalog says {{deleteByQuery}} is true by default, but the field is false: 
{{@UriParam(defaultValue = "true") private boolean deleteByQuery = false;}} 
({{SolrConfiguration}}, main 07d2e7a987bc, lines 57-58, since CAMEL-21479). So 
a DELETE reads the body as ids, while the docs and the tooling say it reads it 
as a query.

Checked on 4.24.0-SNAPSHOT with {{camel run}} against {{camel infra run solr}}: 
a DELETE with the body {{id:docs-2}} deleted nothing, and with 
{{deleteByQuery=true}} it deleted docs-2.

*Proposed change*: make the catalog say false, as the code and the 
{{CamelSolrDeleteByQuery}} header do.

h4. 2. Any String or POJO converts to an empty Map when camel-solr is on the 
classpath

{{SolrResponseConverter}} has a type converter from Object to Map 
({{createSolrResponseMap}}, main 07d2e7a987bc, lines 38-41) that gives an empty 
Map for any value that is not a Solr NamedList. As a converter from Object it 
applies to every conversion to Map in the CamelContext. So with camel-solr on 
the classpath, a conversion that should fail gives {{{}}} instead, in routes 
that have nothing to do with Solr. {{createSolrPingResponse}} does the same for 
SolrPingResponse.

Checked on 4.24.0-SNAPSHOT with {{camel run}}, in a route with no solr step: 
{{convertBodyTo: java.util.Map}} of the text "hello" and of a POJO both gave an 
empty {{java.util.HashMap}}.

*Proposed change*: let these converters convert only a NamedList, and return 
null (no conversion) for anything else.

h4. 3. No body searches for, or deletes, the text java.lang.Object@...

With no body, the producer sets {{new Object()}} as the body so its converters 
run ({{SolrProducer}}, main 07d2e7a987bc, line 85). A SEARCH then queries the 
text "java.lang.Object@3dacb2a2" and finds nothing, and a DELETE deletes the id 
"java.lang.Object@..." and reports success.

Checked on 4.24.0-SNAPSHOT with {{camel run}} against {{camel infra run solr}}: 
SEARCH with no body gave {{q=java.lang.Object@3dacb2a2}} and {{numFound=0}}; 
DELETE with no body gave status 0.

*Proposed change*: fail with an error that says the body is missing, unless a 
header gives what the operation needs ({{CamelSolrQueryString}}, the 
{{CamelSolrField.}} headers).

h4. 4. An INSERT of a body that is not a document reports success and stores 
nothing

When the request has parameters, such as the commit that {{autoCommit=true}} 
adds or a {{CamelSolrParam.}} header, an INSERT of a body that is not a 
document is sent without it, as a request with only the parameters 
({{SolrRequestConverter}}, main 07d2e7a987bc, lines 254-257, meant for a commit 
with no body). It reports success and stores nothing.

Checked on 4.24.0-SNAPSHOT with {{camel run}} against {{camel infra run solr}}, 
with {{autoCommit=true}}: plain text, a byte array, a stream, a text file, a 
POJO without {{@Field}}, a number and no body all gave status 0, and none of 
them was stored.

*Proposed change*: send the request with only the parameters only when there is 
no body, and fail with the {{InvalidPayloadException}} that the same body gets 
without parameters.

h4. Also read in the code, not run

* XML text that starts with a declaration, such as the output of {{marshal: 
jaxb}}, is wrapped in {{<add>}} after the declaration 
({{SolrRequestConverter}}, lines 261-266), which is not well-formed XML.
* A Map body with a null value, or a {{CamelSolrField.}} header with a null 
value, fails with a NullPointerException in {{Collectors.toMap}} (line 273).
* The examples of the docs use {{solr://localhost:8983/solr}} without a 
collection, and fail with "CamelSolrCollection must be specified".

_Claude Code on behalf of davsclaus_



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

Reply via email to