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

Camel Printer unable to print to the network printer

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • 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

       

    Description

      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

      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 "1.2.3.4/B4-2nd-floor-right-wing" so what you are checking is:

      if ("B4-2nd-floor-right-wing".toLowerCase().endsWith("1.2.3.4/B4-2nd-floor-right-wing".toLowerCase()) 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

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment