diff --git a/README.md b/README.md index e335afd..4f72702 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,11 @@ containing the Printer Simulator. ### Usage The tool takes two arguments: *printer-uri* and *file-name*. -The url scheme `ipp://` is not supported - use `http://` instead. If you don't know the printer uri try `ippfind`. - java -jar printjob.jar http://colorjet:631/ipp/printer A4-blank.pdf + java -jar printjob.jar ipp://colorjet:631/ipp/printer A4-blank.pdf - send ipp request to http://colorjet:631/ipp/printer + send ipp request to ipp://colorjet:631/ipp/printer ipp version 1.1 ipp response status: 0000 group 01 @@ -41,7 +40,7 @@ If you don't know the printer uri try `ippfind`. The equivalent java code is: new PrintJob().printDocument( - URI.create("http://colorjet:631/ipp/printer"), + URI.create("ipp://colorjet:631/ipp/printer"), FileInputStream(File("A4-blank.pdf")) ) @@ -58,13 +57,13 @@ If required by your printer, you can set the document format programmatically by If you use an unsupported `printer-uri` you will get a response similar to this one: - send ipp request to http://localhost:8632/ipp/norona + send ipp request to ipp://localhost:8632/ipp/norona ipp version 1.1 ipp status 0400 group 01 attributes-charset (47) = utf-8 attributes-natural-language (48) = en - status-message (41) = Bad printer-uri "http://localhost:8632/ipp/norona". + status-message (41) = Bad printer-uri "ipp://localhost:8632/ipp/norona". group 03 You can use `ippfind` or `dns-sd -Z _ipp._tcp` (look at the rp value) to discover your printer's uri. diff --git a/demo/go b/demo/go index dc29881..d182f43 100755 --- a/demo/go +++ b/demo/go @@ -1 +1 @@ -java -jar printjob.jar http://localhost:8632/printers/laser A4-blank.pdf +java -jar printjob.jar ipp://localhost:8632/printers/laser A4-blank.pdf diff --git a/demo/printjob.jar b/demo/printjob.jar index db04b7e..c1000e1 100644 Binary files a/demo/printjob.jar and b/demo/printjob.jar differ diff --git a/src/main/java/ipp/PrintJob.java b/src/main/java/ipp/PrintJob.java index 9635416..31a969e 100644 --- a/src/main/java/ipp/PrintJob.java +++ b/src/main/java/ipp/PrintJob.java @@ -38,9 +38,10 @@ public static void main(final String[] args) { public void printDocument(final URI uri, final InputStream documentInputStream) throws IOException { System.out.println(String.format("send ipp request to %s", uri.toString())); - - HttpURLConnection httpUrlConnection = (HttpURLConnection) uri.toURL().openConnection(); - httpUrlConnection.setConnectTimeout(3000); + String httpScheme = uri.getScheme().replace("ipp", "http"); + URI httpUri = URI.create(String.format("%s:%s", httpScheme, uri.getSchemeSpecificPart())); + HttpURLConnection httpUrlConnection = (HttpURLConnection) httpUri.toURL().openConnection(); + httpUrlConnection.setConnectTimeout(5000); httpUrlConnection.setDoOutput(true); httpUrlConnection.setRequestProperty("Content-Type", ippContentType);