提交 b2f68393 编写于 作者: P prr

8032693: javax.print.PrintService does not find any CUPS-Printers on Linux

Reviewed-by: jgodinez, serb
上级 e2fd6ef5
......@@ -252,6 +252,7 @@ public class CUPSPrinter {
try {
return urlConnection.getOutputStream();
} catch (Exception e) {
IPPPrintService.debug_println(debugPrefix+e);
}
return null;
}
......@@ -282,6 +283,9 @@ public class CUPSPrinter {
if (responseMap != null && responseMap.length > 0) {
defaultMap = responseMap[0];
} else {
IPPPrintService.debug_println(debugPrefix+
" empty response map for GET_DEFAULT.");
}
if (defaultMap == null) {
......@@ -310,7 +314,10 @@ public class CUPSPrinter {
if (attribClass != null) {
printerInfo[0] = attribClass.getStringValue();
attribClass = (AttributeClass)defaultMap.get("device-uri");
attribClass = (AttributeClass)
defaultMap.get("printer-uri-supported");
IPPPrintService.debug_println(debugPrefix+
"printer-uri-supported="+attribClass);
if (attribClass != null) {
printerInfo[1] = attribClass.getStringValue();
} else {
......
......@@ -1906,9 +1906,8 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
new HashMap[respList.size()]);
} else {
debug_println(debugPrefix+
"readIPPResponse client error, IPP status code-"
+Integer.toHexString(response[2])+" & "
+Integer.toHexString(response[3]));
"readIPPResponse client error, IPP status code: 0x"+
toHex(response[2]) + toHex(response[3]));
return null;
}
......@@ -1921,6 +1920,10 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
}
}
private static String toHex(byte v) {
String s = Integer.toHexString(v&0xff);
return (s.length() == 2) ? s : "0"+s;
}
public String toString() {
return "IPP Printer : " + getName();
......
......@@ -238,9 +238,25 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
String[] printers = null; // array of printer names
String[] printerURIs = null; //array of printer URIs
getDefaultPrintService();
try {
getDefaultPrintService();
} catch (Throwable t) {
IPPPrintService.debug_println(debugPrefix+
"Exception getting default printer : " + t);
}
if (CUPSPrinter.isCupsRunning()) {
printerURIs = CUPSPrinter.getAllPrinters();
try {
printerURIs = CUPSPrinter.getAllPrinters();
IPPPrintService.debug_println("CUPS URIs = " + printerURIs);
if (printerURIs != null) {
for (int p = 0; p < printerURIs.length; p++) {
IPPPrintService.debug_println("URI="+printerURIs[p]);
}
}
} catch (Throwable t) {
IPPPrintService.debug_println(debugPrefix+
"Exception getting all CUPS printers : " + t);
}
if ((printerURIs != null) && (printerURIs.length > 0)) {
printers = new String[printerURIs.length];
for (int i=0; i<printerURIs.length; i++) {
......@@ -595,8 +611,10 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
(CUPSPrinter.isCupsRunning()));
if (CUPSPrinter.isCupsRunning()) {
String[] printerInfo = CUPSPrinter.getDefaultPrinter();
defaultPrinter = printerInfo[0];
psuri = printerInfo[1];
if (printerInfo != null && printerInfo.length >= 2) {
defaultPrinter = printerInfo[0];
psuri = printerInfo[1];
}
} else {
if (isMac() || isSysV()) {
defaultPrinter = getDefaultPrinterNameSysV();
......
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.AttributeSet;
import javax.print.attribute.HashAttributeSet;
import javax.print.attribute.standard.PrinterName;
/*
* @test
* @bug 8032693
* @summary Test that lpstat and JDK agree whether there are printers.
*/
public class CountPrintServices {
public static void main(String[] args) throws Exception {
String os = System.getProperty("os.name").toLowerCase();
System.out.println("OS is " + os);
if (!os.equals("linux")) {
System.out.println("Linux specific test. No need to continue");
return;
}
PrintService services[] =
PrintServiceLookup.lookupPrintServices(null, null);
if (services.length > 0) {
System.out.println("Services found. No need to test further.");
return;
}
String[] lpcmd = { "lpstat", "-a" };
Process proc = Runtime.getRuntime().exec(lpcmd);
proc.waitFor();
InputStreamReader ir = new InputStreamReader(proc.getInputStream());
BufferedReader br = new BufferedReader(ir);
int count = 0;
String printer;
while ((printer = br.readLine()) != null) {
System.out.println("lpstat:: " + printer);
count++;
}
if (count > 0) {
throw new RuntimeException("Services exist, but not found by JDK.");
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册