Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-12890

Camel Printer unable to print to the network printer



    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.17.0
    • 2.21.4, 2.22.2, 2.23.0
    • camel-printer

      Camel version 2.17.0

      OS - RHEL Linux 

      Running as a standalone application with only following dependencies

      • camel-core
      • camel-spring
      • camel-printer




      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://"/>


      When this route is executed we see the following error:

      org.apache.camel.FailedToCreateProducerException: Failed to create Producer for endpoint: Endpoint[lpr://]. Reason: javax.print.PrintException: No printer found with name: 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:


      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

      services[i].getName().toLowerCase().endsWith(printer.toLowerCase()) will always evaluate to false. Because my service name is "B4-2nd-floor-right-wing" and printerName in the URI is "" so what you are checking is:

      if ("B4-2nd-floor-right-wing".toLowerCase().endsWith("".toLowerCase()) which is always false


      If  i change the condition to ("".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.





        1. testCamelPrinter.xml
          0.9 kB
          kalyan kumar bandi

        Issue Links



              acosentino Andrea Cosentino
              calyanbandi kalyan kumar bandi
              0 Vote for this issue
              4 Start watching this issue