diff options
Diffstat (limited to 'libjava/classpath/gnu/javax/print')
-rw-r--r-- | libjava/classpath/gnu/javax/print/CupsServer.java | 31 | ||||
-rw-r--r-- | libjava/classpath/gnu/javax/print/ipp/IppRequest.java | 16 |
2 files changed, 38 insertions, 9 deletions
diff --git a/libjava/classpath/gnu/javax/print/CupsServer.java b/libjava/classpath/gnu/javax/print/CupsServer.java index 6d9601fb933..0486e69deb0 100644 --- a/libjava/classpath/gnu/javax/print/CupsServer.java +++ b/libjava/classpath/gnu/javax/print/CupsServer.java @@ -84,24 +84,43 @@ public class CupsServer /** * Creates a <code>CupsServer</code> object which - * tries to connect to the cups server on localhost. + * tries to connect to a cups server. + * + * If <code>gnu.javax.print.server</code> is explicitly set, then + * that hostname will be used. Otherwise it will default to localhost. * * @param username the username * @param password the password for the username. */ public CupsServer(String username, String password) { + this.username = username; + this.password = password; + + this.uri = null; + try + { + String serv = System.getProperty("gnu.javax.print.server"); + if( serv != null ) + this.uri = new URI("http://"+serv+":631"); + } + catch(URISyntaxException use) + { + throw new RuntimeException("gnu.javax.print.CupsServer value is not a valid hostname."); + } + catch(SecurityException se) + { + } + try { - this.uri = new URI("http://localhost:631"); + if( this.uri == null ) + this.uri = new URI("http://localhost:631"); } catch (URISyntaxException e) { // does not happen } - - this.username = username; - this.password = password; } /** @@ -193,7 +212,7 @@ public class CupsServer Map printerAttributes = (Map) prAttr.get(i); Set uris = (Set) printerAttributes.get(PrinterUriSupported.class); PrinterUriSupported uri = (PrinterUriSupported) uris.toArray()[0]; - + try { CupsPrintService cups = new CupsPrintService(uri.getURI(), diff --git a/libjava/classpath/gnu/javax/print/ipp/IppRequest.java b/libjava/classpath/gnu/javax/print/ipp/IppRequest.java index 8abab519282..05a6faae72e 100644 --- a/libjava/classpath/gnu/javax/print/ipp/IppRequest.java +++ b/libjava/classpath/gnu/javax/print/ipp/IppRequest.java @@ -119,6 +119,11 @@ public class IppRequest { /** + * The printer-poll timeout. + */ + private static final int timeout = 1000; + + /** * Helper class used to write the attributes of a request * into the supplied data output stream in the correct way. * @@ -789,7 +794,7 @@ public class IppRequest alreadySent = true; - OutputStream stream = stream = connection.getOutputStream(); + OutputStream stream = connection.getOutputStream(); DataOutputStream out = new DataOutputStream(stream); // the header 8 bytes long @@ -838,8 +843,13 @@ public class IppRequest out.flush(); stream.flush(); - - int responseCode = responseCode = connection.getResponseCode(); + + // Set the connection timeout, for if the printer is offline. + // FIXME: The print services polling should probably be done in its + // own thread. + connection.setConnectTimeout( timeout ); + + int responseCode = connection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { |