gmuth / ipp-client-kotlin

A client implementation of the ipp protocol written in kotlin
MIT License
75 stars 10 forks source link

Initial connection fails #3

Closed jacczz closed 3 years ago

jacczz commented 3 years ago

Screen Shot 2021-07-20 at 3 35 27 PM I was having an issue connecting the IppPrinter, it keeps crashing.

Screen Shot 2021-07-21 at 1 48 51 PM

Do you have any idea about this error? I just found the ippPrinter using the terminal command 'ippfind'.

I'm using this code : val ippPrinter = IppPrinter(URI.create("ipp://BRWD812655BA041.local:631/ipp/print"))

Thank you.

gmuth commented 3 years ago

The log clearly refers to CupsClient. The exception log is not related to the code you mention (IppPrinter).

1) looking at the logs:

I assume the exception is thrown when you create a CupsClient using the default Constructor with the default values: constructor(host: String = "localhost", port: Int = 631) If this is what you want, make sure you have cups running on your local host, developer machine or android phone (unlikely but possible :-). If you want to connect to a remote CUPS server you must use it's hostname (not "localhost").

2) looking at the code:

The URI you discovered looks good. Some printers don't care about the resource path. So you could try without /ipp/print. If the printer BRWD812655BA041 can be reached you should be able to use the IppPrinter object or get an error message. As long as the printer supports ipp and the required document format (e.g. jpeg or png) I recommend to directly communicate with the printer and skip CUPS.

jacczz commented 3 years ago

I'm trying to integrate this library into android but I'm confused about my 1st step :

This is my only code but it keeps on crashing

val ippPrinter = IppPrinter(URI.create("ipp://BRWD812655BA041.local:631/ipp/print")) ippPrinter.logDetails() println("printer attributes:") for (ippAttribute in ippPrinter.attributes.values) { println("* ${ippAttribute.name} = ${ippAttribute.values.joinToString(",")}")}

Do you have suggestions on how to implement this on android? Thank you.

Screen Shot 2021-07-23 at 10 27 15 AM Screen Shot 2021-07-23 at 10 27 08 AM Screen Shot 2021-07-23 at 10 27 01 AM Screen Shot 2021-07-23 at 10 26 36 AM Screen Shot 2021-07-23 at 10 24 40 AM
gmuth commented 3 years ago

Your additional comment does not really provide additional information.

Overall I don't think your crash is caused by the ipp library. It looks like the app crashes due to a general android related issue.

gmuth commented 3 years ago

I've created a test case for this issue prepared with your printerUri. If the crash is related to the ipp library we should be able to reproduce the problem on a desktop system as well. Please run the test case from within your IDE on your local developer machine and provide the log produced.

run_issueNo3
gmuth commented 3 years ago

@jacczz, please provide the required feedback.

noma4i commented 3 years ago

I was able to replicate the issue. Issue is with a printer as the model we are talking about is QL-1110NWB. from here I was able to extract following info for IPP:

    document-format-supported = [
      "application/octet-stream" (mimeMediaType),
      "image/urf" (mimeMediaType) ],
    document-format-default = "application/octet-stream" (mimeMediaType),
    printer-is-accepting-jobs = true,

using this tool https://github.com/HPInc/jipp Im able to print but the output is garbage as printer is awaiting ESC/POS as input I think

noma4i commented 3 years ago

@gmuth as for the example above the output is as following(I have same label printer as @jacczz):

/Users/noma4i/Library/Java/JavaVirtualMachines/corretto-11.0.12/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=57803:/Applications/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/noma4i/work/ipp-client-kotlin/build/classes/kotlin/test:/Users/noma4i/work/ipp-client-kotlin/build/resources/test:/Users/noma4i/work/ipp-client-kotlin/build/classes/kotlin/main:/Users/noma4i/work/ipp-client-kotlin/build/resources/main:/Users/noma4i/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.30/b5a4b6d16ab13e34a88fae84c35cd5d68cac922c/slf4j-api-1.7.30.jar:/Users/noma4i/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.4.20/9be77b243a362b745e365f286627b8724337009c/kotlin-stdlib-1.4.20.jar:/Users/noma4i/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.4.20/c6761d7805b5312302f2bbd78cda68c976ce0c70/kotlin-stdlib-common-1.4.20.jar:/Users/noma4i/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar:/Users/noma4i/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test-junit/1.4.20/e071a8fda380cb9d347a40e920febab251b464e2/kotlin-test-junit-1.4.20.jar:/Users/noma4i/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test/1.4.20/37f4d139996ed0bbd88df805e4df833040431ff6/kotlin-test-1.4.20.jar:/Users/noma4i/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test-common/1.4.20/2191d43275c9a8558adea84729c1ca372a463e59/kotlin-test-common-1.4.20.jar:/Users/noma4i/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test-annotations-common/1.4.20/a82b48a34377ac287c138ea21e09b511ab21c374/kotlin-test-annotations-common-1.4.20.jar:/Users/noma4i/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.12.jar:/Users/noma4i/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar:/Users/noma4i/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-simple/1.7.30/e606eac955f55ecf1d8edcccba04eb8ac98088dd/slf4j-simple-1.7.30.jar de.gmuth.ipp.client.IssueNo3Kt
IssueNo3Kt                INFO  open http connection to http://192.168.68.134:631
IssueNo3Kt                INFO  response: 200 OK
IssueNo3Kt                INFO  content: 4246 bytes of type 'text/html'
IssueNo3Kt                INFO  open ipp connection to ipp://192.168.68.134:631/ipp/print
IppOutputStream           DEBUG version = 1.1
IppOutputStream           DEBUG code = 11 (Get-Printer-Attributes)
IppOutputStream           DEBUG requestId = 1
IppOutputStream           DEBUG --- operation-attributes-tag ---
IppOutputStream           DEBUG attributes-charset (charset) = utf-8
IppOutputStream           DEBUG attributes-natural-language (naturalLanguage) = en
IppOutputStream           DEBUG printer-uri (uri) = ipp://192.168.68.134:631/ipp/print
IppOutputStream           DEBUG requesting-user-name (nameWithoutLanguage) = noma4i
IppOutputStream           DEBUG --- end-of-attributes-tag ---
IppMessage                DEBUG wrote 153 raw bytes
IppMessage                DEBUG consumed documentInputStream
HttpURLConnectionClient   DEBUG null = [HTTP/1.1 200 OK]
HttpURLConnectionClient   DEBUG Server = [debut/1.30]
HttpURLConnectionClient   DEBUG Cache-Control = [no-cache]
HttpURLConnectionClient   DEBUG Connection = [Keep-Alive]
HttpURLConnectionClient   DEBUG Pragma = [no-cache]
HttpURLConnectionClient   DEBUG Accept-Encoding = [identity]
HttpURLConnectionClient   DEBUG Content-Length = [7479]
HttpURLConnectionClient   DEBUG Upgrade = [TLS/1.2, TLS/1.1, TLS/1.0]
HttpURLConnectionClient   DEBUG Content-Language = [*]
HttpURLConnectionClient   DEBUG Content-Type = [application/ipp]
IppInputStream            DEBUG version = 1.1
IppInputStream            DEBUG code = 0 (successful-ok)
IppInputStream            DEBUG requestId = 1
IppInputStream            DEBUG --- operation-attributes-tag ---
IppInputStream            DEBUG attributes-charset (charset) = utf-8
IppInputStream            DEBUG attributes-natural-language (naturalLanguage) = en
IppInputStream            DEBUG --- printer-attributes-tag ---
IppInputStream            DEBUG copies-default (integer) = 1
IppInputStream            DEBUG finishings-default (1setOf enum) = trim-after-pages
IppInputStream            DEBUG media-default (keyword) = om_brother-label-29x90mm_29x90mm
IppInputStream            DEBUG media-col-default (collection) = {media-type=labels media-size={x-dimension=2900 y-dimension=9000} media-bottom-margin=303 media-left-margin=154 media-right-margin=154 media-top-margin=303 media-source=main media-auto-dimension=false media-source-properties={media-source-feed-direction=short-edge-first media-source-feed-orientation=3}}
IppInputStream            DEBUG orientation-requested-default (enum) = portrait
IppInputStream            DEBUG output-bin-default (keyword) = face-down
IppInputStream            DEBUG output-mode-default (keyword) = monochrome
IppInputStream            DEBUG print-quality-default (enum) = normal
IppInputStream            DEBUG printer-resolution-default (resolution) = 300 dpi
IppInputStream            DEBUG sides-default (keyword) = one-sided
IppInputStream            DEBUG print-color-mode-default (keyword) = auto
IppInputStream            DEBUG print-content-optimize-default (keyword) = auto
IppInputStream            DEBUG print-scaling-default (keyword) = auto
IppInputStream            DEBUG copies-supported (rangeOfInteger) = 1-1
IppInputStream            DEBUG finishings-supported (1setOf enum) = none
IppInputStream            DEBUG  (enum) = 11
IppInputStream            DEBUG  (enum) = 60
IppInputStream            DEBUG  (enum) = 63
IppInputStream            DEBUG media-supported (1setOf keyword) = om_brother-label-29x90mm_29x90mm
IppInputStream            DEBUG  (keyword) = om_brother-label-38x90mm_38x90mm
IppInputStream            DEBUG  (keyword) = om_brother-label-29x62mm_29x62mm
IppInputStream            DEBUG  (keyword) = om_brother-label-62x100mm_62x100mm
IppInputStream            DEBUG  (keyword) = om_brother-label-17x54mm_17x54mm
IppInputStream            DEBUG  (keyword) = om_brother-label-17x87mm_17x87mm
IppInputStream            DEBUG  (keyword) = om_brother-label-58x58mm_58x58mm
IppInputStream            DEBUG  (keyword) = om_brother-label-29x42mm_29x42mm
IppInputStream            DEBUG  (keyword) = om_brother-label-29x52mm_29x52mm
IppInputStream            DEBUG  (keyword) = om_brother-label-23x23mm_23x23mm
IppInputStream            DEBUG  (keyword) = om_brother-label-39x48mm_39x48mm
IppInputStream            DEBUG  (keyword) = om_brother-label-12x12mm_12x12mm
IppInputStream            DEBUG  (keyword) = om_brother-label-24x24mm_24x24mm
IppInputStream            DEBUG  (keyword) = om_brother-label-60x86mm_60x86mm
IppInputStream            DEBUG  (keyword) = om_brother-label-103x164mm_103x164mm
IppInputStream            DEBUG  (keyword) = om_brother-label-51x102mm_51x102mm
IppInputStream            DEBUG  (keyword) = om_brother-label-102x152mm_102x152mm
IppInputStream            DEBUG  (keyword) = om_brother-label-42x62mm_42x62mm
IppInputStream            DEBUG  (keyword) = roll_min_12x12.7mm
IppInputStream            DEBUG  (keyword) = roll_max_103x1000mm
IppInputStream            DEBUG  (keyword) = custom_min_12x12.7mm
IppInputStream            DEBUG  (keyword) = custom_max_103x1000mm
IppInputStream            DEBUG media-col-supported (1setOf keyword) = media-type
IppInputStream            DEBUG  (keyword) = media-size
IppInputStream            DEBUG  (keyword) = media-top-margin
IppInputStream            DEBUG  (keyword) = media-left-margin
IppInputStream            DEBUG  (keyword) = media-right-margin
IppInputStream            DEBUG  (keyword) = media-bottom-margin
IppInputStream            DEBUG  (keyword) = media-source
IppInputStream            DEBUG orientation-requested-supported (1setOf enum) = portrait
IppInputStream            DEBUG  (enum) = 4
IppInputStream            DEBUG output-bin-supported (1setOf keyword) = face-down
IppInputStream            DEBUG output-mode-supported (keyword) = monochrome
IppInputStream            DEBUG  (keyword) = auto
IppInputStream            DEBUG  (keyword) = auto-monochrome
IppInputStream            DEBUG print-quality-supported (1setOf enum) = normal
IppInputStream            DEBUG  (enum) = 5
IppInputStream            DEBUG printer-resolution-supported (1setOf resolution) = 300 dpi
IppInputStream            DEBUG sides-supported (1setOf keyword) = one-sided
IppInputStream            DEBUG print-color-mode-supported (1setOf keyword) = monochrome
IppInputStream            DEBUG  (keyword) = auto
IppInputStream            DEBUG  (keyword) = auto-monochrome
IppInputStream            DEBUG print-content-optimize-supported (1setOf keyword) = auto
IppInputStream            DEBUG print-scaling-supported (1setOf keyword) = auto-fit
IppInputStream            DEBUG  (keyword) = fill
IppInputStream            DEBUG  (keyword) = fit
IppInputStream            DEBUG  (keyword) = none
IppInputStream            DEBUG  (keyword) = auto
IppInputStream            DEBUG generated-natural-language-supported (1setOf naturalLanguage) = en
IppInputStream            DEBUG printer-uri-supported (1setOf uri) = ipp://192.168.68.134/ipp/print
IppInputStream            DEBUG uri-security-supported (1setOf keyword) = none
IppInputStream            DEBUG uri-authentication-supported (1setOf keyword) = none
IppInputStream            DEBUG printer-name (nameWithoutLanguage) = BRW30C9AB0B16CE
IppInputStream            DEBUG printer-location (textWithoutLanguage) = 
IppInputStream            DEBUG printer-info (textWithoutLanguage) = Brother QL-1110NWB
IppInputStream            DEBUG printer-make-and-model (textWithoutLanguage) = Brother QL-1110NWB
IppInputStream            DEBUG printer-state (enum) = idle
IppInputStream            DEBUG printer-state-reasons (1setOf keyword) = none
IppInputStream            DEBUG ipp-versions-supported (1setOf keyword) = 1.0
IppInputStream            DEBUG  (keyword) = 1.1
IppInputStream            DEBUG  (keyword) = 2.0
IppInputStream            DEBUG operations-supported (1setOf enum) = Print-Job
IppInputStream            DEBUG  (enum) = 4
IppInputStream            DEBUG  (enum) = 5
IppInputStream            DEBUG  (enum) = 6
IppInputStream            DEBUG  (enum) = 8
IppInputStream            DEBUG  (enum) = 9
IppInputStream            DEBUG  (enum) = 10
IppInputStream            DEBUG  (enum) = 11
IppInputStream            DEBUG  (enum) = 60
IppInputStream            DEBUG multiple-document-jobs-supported (boolean) = false
IppInputStream            DEBUG multiple-operation-time-out (integer) = 150
IppInputStream            DEBUG natural-language-configured (naturalLanguage) = en
IppInputStream            DEBUG charset-configured (charset) = utf-8
IppInputStream            DEBUG charset-supported (1setOf charset) = utf-8
IppInputStream            DEBUG document-format-supported (1setOf mimeMediaType) = application/octet-stream
IppInputStream            DEBUG  (mimeMediaType) = image/urf
IppInputStream            DEBUG document-format-default (mimeMediaType) = application/octet-stream
IppInputStream            DEBUG printer-is-accepting-jobs (boolean) = true
IppInputStream            DEBUG queued-job-count (integer) = 0
IppInputStream            DEBUG pdl-override-supported (keyword) = attempted
IppInputStream            DEBUG printer-up-time (integer) = 2278
IppInputStream            DEBUG compression-supported (1setOf keyword) = none
IppInputStream            DEBUG color-supported (boolean) = false
IppInputStream            DEBUG job-creation-attributes-supported (1setOf keyword) = copies
IppInputStream            DEBUG  (keyword) = finishings
IppInputStream            DEBUG  (keyword) = ipp-attribute-fidelity
IppInputStream            DEBUG  (keyword) = job-name
IppInputStream            DEBUG  (keyword) = media
IppInputStream            DEBUG  (keyword) = media-col
IppInputStream            DEBUG  (keyword) = orientation-requested
IppInputStream            DEBUG  (keyword) = output-bin
IppInputStream            DEBUG  (keyword) = output-mode
IppInputStream            DEBUG  (keyword) = print-quality
IppInputStream            DEBUG  (keyword) = printer-resolution
IppInputStream            DEBUG  (keyword) = requesting-user-name
IppInputStream            DEBUG  (keyword) = sides
IppInputStream            DEBUG  (keyword) = print-color-mode
IppInputStream            DEBUG media-bottom-margin-supported (1setOf integer) = 303
IppInputStream            DEBUG  (integer) = 154
IppInputStream            DEBUG  (integer) = 288
IppInputStream            DEBUG  (integer) = 202
IppInputStream            DEBUG  (integer) = 262
IppInputStream            DEBUG  (integer) = 303
IppInputStream            DEBUG media-left-margin-supported (1setOf integer) = 154
IppInputStream            DEBUG  (integer) = 303
IppInputStream            DEBUG  (integer) = 288
IppInputStream            DEBUG  (integer) = 202
IppInputStream            DEBUG  (integer) = 154
IppInputStream            DEBUG  (integer) = 202
IppInputStream            DEBUG media-right-margin-supported (1setOf integer) = 154
IppInputStream            DEBUG  (integer) = 303
IppInputStream            DEBUG  (integer) = 288
IppInputStream            DEBUG  (integer) = 202
IppInputStream            DEBUG  (integer) = 154
IppInputStream            DEBUG  (integer) = 202
IppInputStream            DEBUG media-source-supported (1setOf keyword) = main
IppInputStream            DEBUG media-top-margin-supported (1setOf integer) = 303
IppInputStream            DEBUG  (integer) = 154
IppInputStream            DEBUG  (integer) = 288
IppInputStream            DEBUG  (integer) = 202
IppInputStream            DEBUG  (integer) = 262
IppInputStream            DEBUG  (integer) = 303
IppInputStream            DEBUG media-type-supported (1setOf keyword) = labels
IppInputStream            DEBUG  (nameWithoutLanguage) = roll
IppMessage                DEBUG read 4017 raw bytes
IppMessage                INFO  saved: decoding_ipp_response_1_failed.request
IppExchangeException      INFO  saved ipp request  file /Users/noma4i/work/ipp-client-kotlin/decoding_ipp_response_1_failed.request
IppMessage                INFO  saved: decoding_ipp_response_1_failed.response
IppExchangeException      INFO  saved ipp response file /Users/noma4i/work/ipp-client-kotlin/decoding_ipp_response_1_failed.response
IssueNo3Kt                ERROR failed to connect to ipp://192.168.68.134:631/ipp/print
de.gmuth.ipp.client.IppExchangeException: failed to decode ipp response
  at de.gmuth.ipp.client.IppClient.exchange(IppClient.kt:106)
  at de.gmuth.ipp.client.IppClient.exchangeSuccessful(IppClient.kt:64)
  at de.gmuth.ipp.client.IppPrinter.exchangeSuccessful(IppPrinter.kt:283)
  at de.gmuth.ipp.client.IppPrinter.exchangeSuccessfulIppRequest(IppPrinter.kt:287)
  at de.gmuth.ipp.client.IppPrinter.exchangeSuccessfulIppRequest$default(IppPrinter.kt:286)
  at de.gmuth.ipp.client.IppPrinter.getPrinterAttributes(IppPrinter.kt:171)
  at de.gmuth.ipp.client.IppPrinter.getPrinterAttributes$default(IppPrinter.kt:170)
  at de.gmuth.ipp.client.IppPrinter.updateAllAttributes(IppPrinter.kt:174)
  at de.gmuth.ipp.client.IppPrinter.<init>(IppPrinter.kt:31)
  at de.gmuth.ipp.client.IppPrinter.<init>(IppPrinter.kt:26)
  at de.gmuth.ipp.client.IssueNo3Kt.main(issueNo3.kt:37)
  at de.gmuth.ipp.client.IssueNo3Kt.main(issueNo3.kt)
Caused by: de.gmuth.ipp.core.IppException: expected additional value with tag 'keyword' but found  (nameWithoutLanguage) = roll
  at de.gmuth.ipp.core.IppAttribute.additionalValue(IppAttribute.kt:38)
  at de.gmuth.ipp.core.IppInputStream.readMessage(IppInputStream.kt:52)
  at de.gmuth.ipp.core.IppMessage.read(IppMessage.kt:83)
  at de.gmuth.ipp.client.IppClient.exchange(IppClient.kt:103)
  ... 11 more

Process finished with exit code 0
gmuth commented 3 years ago

It looks like the printer returns an invalid IPP message while trying to get the printer attributes. Could you please attach the binary file decoding_ipp_response_1_failed.response? This helps to reproduce the ipp issue without me having to buy the printer that triggers the issue.

noma4i commented 3 years ago

Here we go! @gmuth decoding_ipp_response_1_failed.response.zip

noma4i commented 3 years ago

@jacczz It looks like it works now. @gmuth will confirm. On the other hand the format is the next culprit. I highly recommend to set to Raster. image

possible valid docs are PWG

noma4i commented 3 years ago

This issue is ok to be closed. Handling of a bad IPP response has been fixed.

gmuth commented 3 years ago

Changes: