webapp-hardware-bridge icon indicating copy to clipboard operation
webapp-hardware-bridge copied to clipboard

URL with parameters

Open forcecodema opened this issue 2 years ago • 0 comments

There seems to be a problem when the url passed to print the document from contains parameters. Example log file contains the following:

14:33:48.753 [DESKTOP-0UKK3G6][WebSocketWorker-46] INFO  tigerworkshop.webapphardwarebridge.utils.DownloadUtil.file() @21 - Downloading file from: https://some.domain.name/move/label/fetch?zpl=1&raw=1&itemId=32521&qty=10
14:33:49.228 [DESKTOP-0UKK3G6][WebSocketWorker-46] ERROR tigerworkshop.webapphardwarebridge.websocketservices.PrinterWebSocketService.onDataReceived() @61 - java.io.FileNotFoundException
14:33:49.229 [DESKTOP-0UKK3G6][WebSocketWorker-46] DEBUG tigerworkshop.webapphardwarebridge.websocketservices.PrinterWebSocketService.onDataReceived() @62 - documents\fetch?zpl=1&raw=1&itemId=32521&qty=10 (Nazwa pliku, nazwa katalogu lub składnia etykiety woluminu jest niepoprawna)
java.io.FileNotFoundException: documents\fetch?zpl=1&raw=1&itemId=32521&qty=10 (Nazwa pliku, nazwa katalogu lub składnia etykiety woluminu jest niepoprawna)

The error is that the filename output from getPathFromUrl function is incorrect.

public static String getPathFromUrl(String urlString) {
    urlString = urlString.replace(" ", "%20");
    String filename = urlString.substring(urlString.lastIndexOf("/") + 1);
    return Config.DOCUMENT_PATH + filename;
}

I would suggest to either escape the filename so it produces a valid filename or generate filename randomly. Something like this would do the trick, especially that the file is deleted after sending to printer or print queue.

import java.util.UUID;

public static String getPathFromUrl(String urlString) {
    return Config.DOCUMENT_PATH + UUID.randomUUID().toString();
}

forcecodema avatar Jan 12 '23 13:01 forcecodema