YSoft SafeQ Mobile Print SDK - Android

The document describes API for integrating with YSoft SafeQ. The document contains reference to source code.

The document describes requests for delivering job to Mobile Integration Gateway (MiG).

Delivering Print job via MiG

MiG = Mobile Integration Gateway which operates typically on port 8050. This services has full implementation of IPPS according to Apple's IPP documentation and it also comply with Mopria standard. It was the first server solution certified by Mopria for IPP delivery. IPP is described in RFC https://tools.ietf.org/html/rfc2911 - RFC is quite big, we will need just a subset.

To check whether MiG is running just enter following url to browser: https://safeq-server:8050/

Result should be web page with the string:

MIG hello

In web browser

images/download/attachments/192170548/07_27_47.jpg

Note: If you do not have valid certificate installed, we recommend to use Firefox for testing purpose, because it allows you to continue even with not valid certificate on HTTPS.

The job upload to MiG is just one POST request delivered to url: https://safeq-server:8050/ipp/print .


The request should be composed from following parts

  • HTTP Header:

    • Content-Type: application/ipp

    • Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2

    • Authorization: Basic BASE64_encoded_password

  • HTTP Body:

  • IPP encoded payload

Y Soft recommends to use OkHTTP: https://square.github.io/okhttp/ for upload . Here you may choose different stack, based on your application.

Following code will construct the header:

val request: Request = Request.Builder()
.url(uploadUrl)
.header("Content-Type", "application/ipp")
.header("Accept", "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2")
.header("Authorization", this.token)
.post(requestBody).build()

The request body could by generated using IppRequest class described by Petr Barton's his thesis written in 2016.
You can find the thesis here: https://is.muni.cz/th/wyl4x/?lang=en
PDF: https://is.muni.cz/th/wyl4x/thesis.pdf
Attachment here: https://is.muni.cz/th/wyl4x/attachement.zip
The class is here: android-printservice/app/src/main/java/com/ysoft/safeqprintservice/IppRequest.java

To serialize the ipp to request body you can use following code:

var ippRequest = IppRequest(myFile.name, myFile.readBytes())
 
val requestBody = ippRequest.bytes.toRequestBody()

Service discovery

One approach to solve service discovery is to register specific DNS A record and point it to print service. The application can search for subdomain by prepending the text to company domain provided by DHCP or VPN client.

Following code is able to read domain from DHCP info. Keep in mind that result could be none, one or multiple domains. In case of multiple domains there could be several different delimiters - semicolon, comma or space.

// based on: https://stackoverflow.com/questions/46065159/get-android-dhcpinfo-connected-via-ethernet
val connectivityManager: ConnectivityManager =
applicationContext.getSystemService(Service.CONNECTIVITY_SERVICE) as ConnectivityManager
 
val link = connectivityManager.getLinkProperties(connectivityManager.activeNetwork)
val domains = link?.domains
if (domains != null) {
domains.replace(",", " ").replace(";", " ")
val myDomainsInArray = domains.split(" ")
for (dhcpDomain in myDomainsInArray) {
...
}
}

The next step is to send request to verify that endpoint exist.

E.g. Company has domain ysoft.local, this was discovered using code above. MiG server has DNS A record with subdomain safeq6. The application should check url on domain safeq6.ysoft.local.

Verify MiG availability

Send HTTP GET to: /

Expected response: 200 OK with content MIG hello

Verify EUI availability

Send HTTP GET to: /end-user/ui/

Expected response: 200 OK with HTML page containing _csrf token.

Response codes

200 OK - job was accepted by MiG

401 Unauthorized - authorization header is missing or credentials are incorrect

404 Not found - request URL is incorrect and it's not pointing to working MiG /ipp/print