Skip to content

Commit

Permalink
support for ipp scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuth committed Mar 23, 2020
1 parent 5ca86e4 commit 51de61f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"))
)

Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion demo/go
Original file line number Diff line number Diff line change
@@ -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
Binary file modified demo/printjob.jar
Binary file not shown.
7 changes: 4 additions & 3 deletions src/main/java/ipp/PrintJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 51de61f

Please sign in to comment.