Skip to content

Commit

Permalink
added 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 27cb503 commit bdc78e2
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,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 @@ -42,7 +41,7 @@ If you don't know the printer uri try `ippfind`.
The equivalent kotlin code is:

printJobStreamingVersion(
URI.create("http://colorjet:631/ipp/printer"),
URI.create("ipp://colorjet:631/ipp/printer"),
FileInputStream(File("A4-blank.pdf"))
)

Expand All @@ -59,13 +58,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 build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tasks.withType<ShadowJar>() {
archiveBaseName.set("printjob")
archiveClassifier.set("")
manifest {
attributes(mapOf("Main-Class" to "ipp.PrintJobKt"))
attributes(mapOf("Main-Class" to "ipp.PrintJobStreamingVersionKt"))
}
}

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.
4 changes: 3 additions & 1 deletion src/main/kotlin/ipp/printJobByteArrayVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ fun printJobByteArrayVersion(uri: URI, documentInputStream: InputStream) {

// exchange ipp messages via http
println("send ipp request to $uri")
val ippResponse = with(uri.toURL().openConnection() as HttpURLConnection) {
val httpScheme = uri.scheme.replace("ipp", "http")
val httpUri = URI.create("${httpScheme}:${uri.schemeSpecificPart}")
val ippResponse = with(httpUri.toURL().openConnection() as HttpURLConnection) {
val ippContentType = "application/ipp"
setConnectTimeout(3000)
setDoOutput(true)
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/ipp/printJobStreamingVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ fun printJobStreamingVersion(uri: URI, documentInputStream: InputStream) {
val ippContentType = "application/ipp"

println("send ipp request to $uri")
val httpURLConnection = uri.toURL().openConnection() as HttpURLConnection
val httpScheme = uri.scheme.replace("ipp", "http")
val httpUri = URI.create("${httpScheme}:${uri.schemeSpecificPart}")
val httpURLConnection = httpUri.toURL().openConnection() as HttpURLConnection
with(httpURLConnection) {
setConnectTimeout(3000)
setDoOutput(true)
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/ipp/printJobWithStatusOnly.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ fun main(args: Array<String>) {

fun printJobWithStatusOnly(uri: URI, documentInputStream: InputStream) {
val charset = Charsets.UTF_8
with(uri.toURL().openConnection() as HttpURLConnection) {
val httpScheme = uri.scheme.replace("ipp", "http")
val httpUri = URI.create("${httpScheme}:${uri.schemeSpecificPart}")
with(httpUri.toURL().openConnection() as HttpURLConnection) {
setDoOutput(true)
setRequestProperty("Content-Type", "application/ipp")
// encode ipp request 'Print-Job operation'
Expand Down

0 comments on commit bdc78e2

Please sign in to comment.