[ 
https://issues.apache.org/jira/browse/CAMEL-12890?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16658601#comment-16658601
 ] 

ASF GitHub Bot commented on CAMEL-12890:
----------------------------------------

oscerd closed pull request #2572: Fixing issue CAMEL-12890
URL: https://github.com/apache/camel/pull/2572
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/components/camel-printer/src/main/java/org/apache/camel/component/printer/PrinterProducer.java
 
b/components/camel-printer/src/main/java/org/apache/camel/component/printer/PrinterProducer.java
index 7e69aa7759b..e19f9f0b08a 100644
--- 
a/components/camel-printer/src/main/java/org/apache/camel/component/printer/PrinterProducer.java
+++ 
b/components/camel-printer/src/main/java/org/apache/camel/component/printer/PrinterProducer.java
@@ -148,7 +148,7 @@ private int findPrinter(PrintService[] services, String 
printer) {
             // align slashes so we match / or \
             printerName = printerName.toLowerCase(Locale.US);
             printerName = printerName.replace('\\', '/');
-            if (printerName.endsWith(printer)) {
+            if (printer.endsWith(printerName)) {
                 position = i;
                 break;
             }
diff --git 
a/components/camel-printer/src/test/java/org/apache/camel/component/printer/PrinterPrintTest.java
 
b/components/camel-printer/src/test/java/org/apache/camel/component/printer/PrinterPrintTest.java
index 8c099c48305..5a02c8b8f23 100644
--- 
a/components/camel-printer/src/test/java/org/apache/camel/component/printer/PrinterPrintTest.java
+++ 
b/components/camel-printer/src/test/java/org/apache/camel/component/printer/PrinterPrintTest.java
@@ -306,6 +306,36 @@ public void configure() {
         verify(job1, times(1)).print(any(Doc.class), 
any(PrintRequestAttributeSet.class));
     }
 
+    /*
+     * Test for CAMEL-12890
+     * Unable to send to remote printer
+     * */
+    @Test
+    public void testSendingFileToRemotePrinter() throws Exception {
+        // setup javax.print 
+        PrintService ps1 = mock(PrintService.class);
+        when(ps1.getName()).thenReturn("printer1");
+        
when(ps1.isDocFlavorSupported(any(DocFlavor.class))).thenReturn(Boolean.TRUE);
+        boolean res1 = PrintServiceLookup.registerService(ps1);
+        assertTrue("The Remote PrintService #1 should be registered.", res1);
+        DocPrintJob job1 = mock(DocPrintJob.class);
+        when(ps1.createPrintJob()).thenReturn(job1);
+
+        context.addRoutes(new RouteBuilder() {
+
+            public void configure() {
+                
from("direct:start1").to("lpr://remote/printer1?sendToPrinter=true");
+            }
+        });
+        context.start();
+
+        template.sendBody("direct:start1", "Hello Printer 1");
+
+        context.stop();
+
+        verify(job1, times(1)).print(any(Doc.class), 
any(PrintRequestAttributeSet.class));
+    }
+
     @Test
     public void setJobName() throws Exception {
         if (isAwtHeadless()) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> 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&amp;noop=true"/>
>  <to 
> uri="lpr://1.2.3.4/B4-2nd-floor-right-wing?copies=1&amp;sides=Sides.ONE_SIDED&amp;mimeType=PDF&amp;mediaSize=na-letter&amp;flavor=DocFlavor.INPUT_STREAM&amp;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)

Reply via email to