[
https://issues.apache.org/jira/browse/CAMEL-12890?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Andrea Cosentino reassigned CAMEL-12890:
----------------------------------------
Assignee: Andrea Cosentino
> Camel Printer unable to print to the network printer
> ----------------------------------------------------
>
> Key: CAMEL-12890
> URL: https://issues.apache.org/jira/browse/CAMEL-12890
> Project: Camel
> Issue Type: Bug
> Components: camel-printer
> Affects Versions: 2.17.0
> Environment:
> Camel version 2.17.0
> OS - RHEL Linux
> Running as a standalone application with only following dependencies
> * camel-core
> * camel-spring
> * camel-printer
>
> Reporter: kalyan kumar bandi
> Assignee: Andrea Cosentino
> Priority: Major
> Labels: patch, ready-to-commit
> Fix For: 2.22.2, 2.23.0, 2.21.4
>
> Attachments: testCamelPrinter.xml
>
>
> Hi,
> We have developed a camel route to print a PDF file to a network printer that
> is configured on the machine. The route looks as follows:
>
> <route id="_route1">
> <from uri="file:/opt/user/data?fileName=test.PDF&noop=true"/>
> <to
> uri="lpr://1.2.3.4/B4-2nd-floor-right-wing?copies=1&sides=Sides.ONE_SIDED&mimeType=PDF&mediaSize=na-letter&flavor=DocFlavor.INPUT_STREAM&sendToPrinter=true"/>
> </route>
>
> When this route is executed we see the following error:
> org.apache.camel.FailedToCreateProducerException: Failed to create Producer
> for endpoint:
> Endpoint[lpr://1.2.3.4:9100/B4-2nd-floor-right-wing?copies=1&flavor=DocFlavor.INPUT_STREAM&mediaSize=na-letter&mediaTray=AUTOSENSE&mimeType=PDF&orientation=portrait&sendToPrinter=true&sides=one-sided].
> Reason: javax.print.PrintException: No printer found with name:
> 1.2.3.4/B4-2nd-floor-right-wing. Please verify that the host and printer are
> registered and reachable from this machine.
>
> With DEBUG logs enabled, i can that it is using the following printer name.
> 2018-10-17 21:01:05,628 | DEBUG | xtenderThread-26 | PrinterProducer
> | 794 - org.apache.camel.camel-core - 2.17.0.redhat-630310 | Using
> printer name: 1.2.3.4/B4-2nd-floor-right-wing
>
> After more debugging came across the following code in PrinterProducer.java
> in camel-printer component
> private int findPrinter(PrintService[] services, String printer) {
> int position = -1;
> for (int i = 0; i < services.length; i++) {
> if (services[i].getName().toLowerCase().endsWith(printer.toLowerCase())) {
> position = i;
> break;
> }
> }
> return position;
> }
> Printer services configured on the machine are:
> * B4-2nd-floor-right-wing
> * B4-2nd-floor-left-wing
> * B4-1st-floor-right-wing
> * B4-1st-floor-left-wing
>
> Here the if block condition
> {color:#FF0000}services[i].getName().toLowerCase().endsWith(printer.toLowerCase()){color}
> will always evaluate to false. Because my service name is
> "B4-2nd-floor-right-wing" and printerName in the URI is
> "1.2.3.4/B4-2nd-floor-right-wing" so what you are checking is:
> {color:#FF0000}if
> ("B4-2nd-floor-right-wing".toLowerCase().endsWith("1.2.3.4/B4-2nd-floor-right-wing".toLowerCase()){color}
> which is always false
>
> If i change the condition to
> ("1.2.3.4/B4-2nd-floor-right-wing".toLowerCase().endsWith("B4-2nd-floor-right-wing".toLowerCase())
> then it works fine
>
> I took the latest version (2.23.0-SNAPSHOT) from github which is also having
> the same condition. Modified the single line and ran my route and it worked
> fine.
>
> Note that the issue happens only when trying with remote printer and with
> local printer it works fine. I tested with local printer in my windows PC and
> it worked fine but none (Windows/Linux) worked with remote printer
> configuration.
>
> Thanks,
> Kalyan
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)