Java 谷歌云打印有时会出现错误
我有一个Java应用程序,它使用Google Cloud Print API()打印pdf。在大多数情况下,它就像一个符咒,但偶尔(大约100分之一)它会返回一个错误,看起来像“Det går inte at göraändringar i ett avslutat jobb”。 大致翻译成英语,上面写着:“不能对完成的工作进行更改” 更重要的是,无论有无错误,页面每次都能完美打印 每次调用GCP时,代码如下所示:Java 谷歌云打印有时会出现错误,java,google-cloud-print,Java,Google Cloud Print,我有一个Java应用程序,它使用Google Cloud Print API()打印pdf。在大多数情况下,它就像一个符咒,但偶尔(大约100分之一)它会返回一个错误,看起来像“Det går inte at göraändringar i ett avslutat jobb”。 大致翻译成英语,上面写着:“不能对完成的工作进行更改” 更重要的是,无论有无错误,页面每次都能完美打印 每次调用GCP时,代码如下所示: public static SubmitJobResponse subm
public static SubmitJobResponse submitPrintJob(String filename, String type){
String jsonTicket;
String printerId;
SubmitJobResponse response = null;
String jobtitle;
jobtitle = filename.substring(filename.lastIndexOf('/') + 1);
// Login to GCP
GoogleCloudPrint cloudPrint = gcpLogin();
jsonTicket = "{'version':'1.0','print':{'vendor_ticket_item':[],'color':{'type':1},'copies':{'copies':4}}}";
printerId = session("printerlabel");
try {
// Get file as byte array
Path path = Paths.get(filename);
byte[] content = Files.readAllBytes(path);
Gson gson = new Gson();
Ticket ticket = gson.fromJson(jsonTicket, Ticket.class);
String json = gson.toJson(ticket);
//create job
SubmitJob submitJob = new SubmitJob();
submitJob.setContent(content);
submitJob.setContentType("application/pdf");
submitJob.setPrinterId(printerId);
submitJob.setTicket(ticket);
submitJob.setTitle(jobtitle);
//send job
response = cloudPrint.submitJob(submitJob);
Logger.debug("PrinterID => {}", printerId);
Logger.debug("submit job response => {}", response.isSuccess() + "," + response.getMessage());
if(response.isSuccess()) {
Logger.debug("submit job id => {}", response.getJob().getId());
}
cloudPrint.disconnect();
} catch (Exception ex) {
Logger.warn(null, ex);
}
return response;
}
API使用一个调用“/submit?output=json&printerid=”在GCP上,那么为什么它说我正在尝试更改一个已完成的作业-我没有提交作业id-仅提交打印机id
如何消除这些错误?我的想法是职位必须是唯一的,但在使用静态职位的测试中,我无法重现错误