[
https://issues.apache.org/jira/browse/CAMEL-12228?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16353471#comment-16353471
]
ASF GitHub Bot commented on CAMEL-12228:
----------------------------------------
oscerd closed pull request #2208: CAMEL-12228: Print command fails in case of
multiple copies
URL: https://github.com/apache/camel/pull/2208
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/PrinterConfiguration.java
b/components/camel-printer/src/main/java/org/apache/camel/component/printer/PrinterConfiguration.java
index 85cbd550535..5e7aecf2914 100644
---
a/components/camel-printer/src/main/java/org/apache/camel/component/printer/PrinterConfiguration.java
+++
b/components/camel-printer/src/main/java/org/apache/camel/component/printer/PrinterConfiguration.java
@@ -28,7 +28,7 @@
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
import org.apache.camel.spi.UriPath;
-import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.StringHelper;
import org.apache.camel.util.URISupport;
@UriParams
@@ -85,8 +85,8 @@ public void parseURI(URI uri) throws Exception {
// use path as printer name, but without any leading slashes
String path = uri.getPath();
- path = ObjectHelper.removeStartingCharacters(path, '/');
- path = ObjectHelper.removeStartingCharacters(path, '\\');
+ path = StringHelper.removeStartingCharacters(path, '/');
+ path = StringHelper.removeStartingCharacters(path, '\\');
setPrintername(path);
Map<String, Object> printSettings = URISupport.parseParameters(uri);
diff --git
a/components/camel-printer/src/main/java/org/apache/camel/component/printer/PrinterOperations.java
b/components/camel-printer/src/main/java/org/apache/camel/component/printer/PrinterOperations.java
index 20750028627..bed8be27ab7 100644
---
a/components/camel-printer/src/main/java/org/apache/camel/component/printer/PrinterOperations.java
+++
b/components/camel-printer/src/main/java/org/apache/camel/component/printer/PrinterOperations.java
@@ -45,7 +45,7 @@
private PrintRequestAttributeSet printRequestAttributeSet;
private Doc doc;
- public PrinterOperations() throws PrintException {
+ public PrinterOperations() throws PrintException {
printService = PrintServiceLookup.lookupDefaultPrintService();
if (printService == null) {
throw new PrintException("Printer lookup failure. No default
printer set up for this host");
@@ -63,46 +63,42 @@ public PrinterOperations(PrintService printService,
DocFlavor flavor, PrintReque
this.setPrintRequestAttributeSet(printRequestAttributeSet);
}
- public void print(Doc doc, int copies, boolean sendToPrinter, String
mimeType, String jobName) throws PrintException {
+ public void print(Doc doc, boolean sendToPrinter, String mimeType, String
jobName) throws PrintException {
LOG.trace("Print Service: " + this.printService.getName());
- LOG.trace("About to print " + copies + " copy(s)");
-
- for (int i = 0; i < copies; i++) {
- if (!sendToPrinter) {
- LOG.debug("Print flag is set to false. This job will not be
printed until this setting remains in effect."
- + " Please set the flag to true or remove the
setting.");
-
- File file;
- if (mimeType.equalsIgnoreCase("GIF") ||
mimeType.equalsIgnoreCase("RENDERABLE_IMAGE")) {
- file = new File("./target/TestPrintJobNo" + i + "_" +
UUID.randomUUID() + ".gif");
- } else if (mimeType.equalsIgnoreCase("JPEG")) {
- file = new File("./target/TestPrintJobNo" + i + "_" +
UUID.randomUUID() + ".jpeg");
- } else if (mimeType.equalsIgnoreCase("PDF")) {
- file = new File("./target/TestPrintJobNo" + i + "_" +
UUID.randomUUID() + ".pdf");
- } else {
- file = new File("./target/TestPrintJobNo" + i + "_" +
UUID.randomUUID() + ".txt");
- }
-
- LOG.debug("Writing print job to file: " +
file.getAbsolutePath());
- try {
- InputStream in = doc.getStreamForBytes();
- FileOutputStream fos = new FileOutputStream(file);
- IOHelper.copyAndCloseInput(in, fos);
- IOHelper.close(fos);
- } catch (Exception e) {
- throw new PrintException("Error writing Document to the
target file " + file.getAbsolutePath());
- }
+
+ if (!sendToPrinter) {
+ LOG.debug("Print flag is set to false. This job will not be
printed until this setting remains in effect." + " Please set the flag to true
or remove the setting.");
+
+ File file;
+ if (mimeType.equalsIgnoreCase("GIF") ||
mimeType.equalsIgnoreCase("RENDERABLE_IMAGE")) {
+ file = new File("./target/PrintOutput_" + UUID.randomUUID() +
".gif");
+ } else if (mimeType.equalsIgnoreCase("JPEG")) {
+ file = new File("./target/PrintOutput_" + UUID.randomUUID() +
".jpeg");
+ } else if (mimeType.equalsIgnoreCase("PDF")) {
+ file = new File("./target/PrintOutput_" + UUID.randomUUID() +
".pdf");
} else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Issuing Job {} to Printer: {}", i,
this.printService.getName());
- }
- print(doc, jobName);
+ file = new File("./target/PrintOutput_" + UUID.randomUUID() +
".txt");
+ }
+
+ LOG.debug("Writing print job to file: " + file.getAbsolutePath());
+ try {
+ InputStream in = doc.getStreamForBytes();
+ FileOutputStream fos = new FileOutputStream(file);
+ IOHelper.copyAndCloseInput(in, fos);
+ IOHelper.close(fos);
+ } catch (Exception e) {
+ throw new PrintException("Error writing Document to the target
file " + file.getAbsolutePath());
}
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Issuing Job to Printer: {}",
this.printService.getName());
+ }
+ print(doc, jobName);
}
}
-
+
public void print(Doc doc, String jobName) throws PrintException {
- // we need create a new job for each print
+ // we need create a new job for each print
DocPrintJob job = getPrintService().createPrintJob();
PrintRequestAttributeSet attrs = new
HashPrintRequestAttributeSet(printRequestAttributeSet);
attrs.add(new JobName(jobName, Locale.getDefault()));
@@ -116,7 +112,7 @@ public PrintService getPrintService() {
public void setPrintService(PrintService printService) {
this.printService = printService;
}
-
+
public DocFlavor getFlavor() {
return flavor;
}
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 ea8fd99c872..7e69aa7759b 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
@@ -53,8 +53,8 @@ public void process(Exchange exchange) throws Exception {
private void print(InputStream body, String jobName) throws PrintException
{
if
(printerOperations.getPrintService().isDocFlavorSupported(printerOperations.getFlavor()))
{
- PrintDocument printDoc = new PrintDocument(body,
printerOperations.getFlavor());
- printerOperations.print(printDoc, config.getCopies(),
config.isSendToPrinter(), config.getMimeType(), jobName);
+ PrintDocument printDoc = new PrintDocument(body,
printerOperations.getFlavor());
+ printerOperations.print(printDoc, config.isSendToPrinter(),
config.getMimeType(), jobName);
}
}
----------------------------------------------------------------
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]
> Print command fails in case of multiple copies
> ----------------------------------------------
>
> Key: CAMEL-12228
> URL: https://issues.apache.org/jira/browse/CAMEL-12228
> Project: Camel
> Issue Type: Bug
> Components: camel-printer
> Affects Versions: 2.18.1, 2.19.0, 2.20.0
> Reporter: Robin Vanderhallen
> Assignee: Dmitry Volodin
> Priority: Major
> Fix For: 2.19.5, 2.20.3, 2.21.0
>
>
> When the printer component is configured to print multiple copies, two print
> jobs are created. The first one runs OK, the second one fails.
> {code}
> lpr://localhost/printer?copies=2&mediaSize=ISO_A4&flavor=DocFlavor.INPUT_STREAM
> {code}
> {code}
> org.apache.camel.component.printer.PrinterOperations DEBUG Issuing Job 0 to
> Printer: printer
> org.apache.camel.component.printer.PrinterOperations DEBUG Issuing Job 1 to
> Printer: printer
> ERROR ID-47935-1516954952584-8-4
> java.io.IOException: error=1 running: '/usr/bin/lpr' '-Pprinter' '-J
> file.pdf' '-#2' '-o media=A4 sides=one-sided'
> '/opt/tomcat/temp/javaprint7376295310894617090'
> /usr/bin/lpr: No file in print request.
> javax.print.PrintException: java.io.IOException: error=1 running:
> '/usr/bin/lpr' '-PBriefing' '-J file.pdf' '-#2' '-o media=A4 sides=one-sided'
> '/opt/tomcat/temp/javaprint7376295310894617090'
> /usr/bin/lpr: No file in print request.
> at sun.print.UnixPrintJob$PrinterSpooler.run(UnixPrintJob.java:1017)
> at java.security.AccessController.doPrivileged(Native Method)
> at sun.print.UnixPrintJob.print(UnixPrintJob.java:608)
> at
> org.apache.camel.component.printer.PrinterOperations.print(PrinterOperations.java:109)
> at
> org.apache.camel.component.printer.PrinterOperations.print(PrinterOperations.java:99)
> at
> org.apache.camel.component.printer.PrinterProducer.print(PrinterProducer.java:57)
> at
> org.apache.camel.component.printer.PrinterProducer.process(PrinterProducer.java:51)
> at
> org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
> at
> org.apache.camel.processor.SendDynamicProcessor$1.doInAsyncProducer(SendDynamicProcessor.java:124)
> at
> org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:436)
> at
> org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicProcessor.java:119)
> at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
> at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542)
> at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
> at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
> at
> org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)
> at
> org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
> at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
> at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542)
> at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
> at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
> at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
> at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542)
> at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
> at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109)
> at
> org.apache.camel.processor.MulticastProcessor.doProcessParallel(MulticastProcessor.java:827)
> at
> org.apache.camel.processor.MulticastProcessor.access$200(MulticastProcessor.java:85)
> at
> org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:320)
> at
> org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:305)
> at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> at java.lang.Thread.run(Thread.java:745)
> {code}
> The second job should not be created because the -#2 parameter in the lpr
> command already schedules the desired number of copies.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)