You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/02/06 06:50:22 UTC
[camel] branch camel-2.19.x updated: CAMEL-12228: Print command
fails in case of multiple copies
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch camel-2.19.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.19.x by this push:
new 90943ce CAMEL-12228: Print command fails in case of multiple copies
90943ce is described below
commit 90943cefeb8fe4020fc9a115f3056eee0fd88d49
Author: Dmitry Volodin <dm...@gmail.com>
AuthorDate: Mon Feb 5 23:30:44 2018 +0300
CAMEL-12228: Print command fails in case of multiple copies
---
.../component/printer/PrinterConfiguration.java | 6 +-
.../camel/component/printer/PrinterOperations.java | 68 ++++++++++------------
.../camel/component/printer/PrinterProducer.java | 4 +-
3 files changed, 37 insertions(+), 41 deletions(-)
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 85cbd55..5e7aecf 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.Metadata;
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 class PrinterConfiguration {
// 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 2075002..bed8be2 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 @@ public class PrinterOperations implements PrinterOperationsInterface {
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 class PrinterOperations implements PrinterOperationsInterface {
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 class PrinterOperations implements PrinterOperationsInterface {
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 ea8fd99..7e69aa7 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 class PrinterProducer extends DefaultProducer {
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);
}
}
--
To stop receiving notification emails like this one, please contact
acosentino@apache.org.