You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "kalyan kumar bandi (JIRA)" <ji...@apache.org> on 2018/10/18 08:24:00 UTC
[jira] [Created] (CAMEL-12890) Camel Printer unable to print to the
network printer
kalyan kumar bandi created CAMEL-12890:
------------------------------------------
Summary: 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
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)