[
https://issues.apache.org/jira/browse/CAMEL-27614?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen updated CAMEL-27614:
--------------------------------
Fix Version/s: 4.24.0
(was: 4.25.0)
> camel-printer: NPE with sendToPrinter=false, silent doc flavor fallback,
> missing defaults
> -----------------------------------------------------------------------------------------
>
> Key: CAMEL-27614
> URL: https://issues.apache.org/jira/browse/CAMEL-27614
> Project: Camel
> Issue Type: Bug
> Components: camel-printer
> Reporter: Claus Ibsen
> Assignee: shashank
> Priority: Minor
> Fix For: 4.24.0
>
>
> Found while improving the option descriptions of camel-printer for
> CAMEL-23832 (PR https://github.com/apache/camel/pull/30950).
> These are separate problems of the component; the descriptions PR only
> documents the current behavior.
> h4. 1. sendToPrinter=false without mimeType fails with a NullPointerException
> {{PrinterConfiguration.assignDocFlavor()}} applies the {{AUTOSENSE}} default
> to a local variable only, so {{PrinterConfiguration.getMimeType()}} stays
> {{null}} when the {{mimeType}} option is not set. {{PrinterProducer.print()}}
> passes that {{null}} to {{PrinterOperations.print(Doc, boolean, String,
> String)}}, which calls {{mimeType.equalsIgnoreCase("GIF")}} when
> {{sendToPrinter}} is false. For example,
> {{lpr://localhost/myprinter?sendToPrinter=false}} fails every exchange with a
> {{NullPointerException}} once the print service supports the doc flavor.
> Proposed change: store the default {{AUTOSENSE}} in the {{mimeType}} field,
> or treat a {{null}} mime type as {{AUTOSENSE}} (extension {{.txt}}) in
> {{PrinterOperations.print()}}.
> h4. 2. An unknown flavor and mimeType combination silently prints as
> BYTE_ARRAY.AUTOSENSE
> {{PrinterConfiguration.assignDocFlavor()}} and the
> {{DocFlavorAssigner.forMimeType*()}} methods start from
> {{DocFlavor.BYTE_ARRAY.AUTOSENSE}} and keep it when the {{flavor}} or the
> {{mimeType}} value is not one they know. A misspelled value, or a valid pair
> the assigner does not map (for example the default {{flavor}}
> {{DocFlavor.BYTE_ARRAY}} with {{mimeType=TEXT_PLAIN}}, which maps only
> {{CHAR_ARRAY}}, {{READER}} and {{STRING}}), prints with a different doc
> flavor than the user asked for, without an error or a log message.
> Proposed change: fail the endpoint creation with an
> {{IllegalArgumentException}} that lists the accepted values, as
> {{MediaSizeAssigner.selectMediaSizeName()}} does for an unknown {{mediaSize}}.
> h4. 3. The SERVICE_FORMATTED doc flavors get an InputStream as print data
> With {{mimeType}} {{PAGEABLE}}, {{PRINTABLE}} or {{RENDERABLE_IMAGE}},
> {{DocFlavorAssigner}} selects {{DocFlavor.SERVICE_FORMATTED.*}}, whose print
> data must be a {{java.awt.print.Pageable}}, {{java.awt.print.Printable}} or
> {{java.awt.image.renderable.RenderableImage}}. {{PrinterProducer.process()}}
> always reads the body as an {{InputStream}}, and
> {{PrintDocument.getPrintData()}} returns that stream, so the data does not
> match the representation class of the doc flavor.
> Proposed change: pass the body converted to the representation class of the
> doc flavor (or the body object itself for {{SERVICE_FORMATTED}}), or remove
> these three values.
> h4. 4. sendToPrinter=false writes to a fixed ./target directory
> {{PrinterOperations.print(Doc, boolean, String, String)}} writes the document
> to {{./target/PrintOutput_<uuid>.<ext>}} relative to the working directory.
> When the {{target}} directory does not exist, the {{FileOutputStream}} fails
> and the exchange fails with a {{PrintException}}. The directory cannot be
> configured.
> Proposed change: create the directory if missing, or add an option for the
> output directory.
> h4. 5. Metadata: flavor and mimeType have no defaultValue
> The code defaults are {{DocFlavor.BYTE_ARRAY}} for {{flavor}} and
> {{AUTOSENSE}} for {{mimeType}} ({{PrinterConfiguration.assignDocFlavor()}}),
> but their {{@UriParam}} in {{PrinterConfiguration}} has no {{defaultValue}},
> so the catalog and the tooling show no default.
> Proposed change: add {{defaultValue = "DocFlavor.BYTE_ARRAY"}} and
> {{defaultValue = "AUTOSENSE"}}, together with the fix of item 1.
> h4. 6. Metadata: the port path parameter does nothing for printing
> {{PrinterProducer.assignPrintService()}} looks up the printer by name only.
> The {{port}} of {{lpr:hostname:port/printername}} is used only in
> {{PrinterEndpoint.getServiceUrl()}}.
> Proposed change: say so in the documentation of the syntax, or deprecate the
> path parameter.
> _Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)