Java API GetPrinters() incorrect
Benjamin Wagner
ben_wagner at gmx.de
Wed May 3 15:15:50 PDT 2006
Hi all,
i want to use the CUPS Java API in my web app to print some file on the server side. Im using CUPS 1.1.23, Java 1.5, JBoss 4.0.3SP1 all running on a suse 9.3 system. I have 2 Problems:
1. this seems to me a bug in the API:
somtimes the cups.cupsGetPrinters() seems to hang - like its waiting for a response. The problem is in the 'case REQ_STATE_READ_RESPONSE:' Block of the Cups.doRequest() function:
when the http.read_header() function returns 0 while the http.status is OK (which is sometimes the case for me), the state flag is never changed and the loop is never ended - the http.read_header() function is called over and over again.
I made 2 changes to fix it:
a) added these two lines (line 750-755 including comments)
case REQ_STATE_READ_RESPONSE:
+ if (http.status == IPPHttp.HTTP_OK)
+ http.status = 0;
read_length = http.read_header();
b) changed (line 781 - 786)
if ((read_length > 0) && (state == REQ_STATE_READ_RESPONSE))
{
http.read_buffer = http.read(read_length);
ipp = http.processResponse();
state++;
}
into
if (state == REQ_STATE_READ_RESPONSE)
{
if (read_length == 0) {
return false;
}
http.read_buffer = http.read(read_length);
ipp = http.processResponse();
state++;
}
2. this is related to the first problem, but i don't know why it happens:
Sometimes i get the list with all the printers and sometimes i don't - nearly every second time. It happends when the http.read_header() function returns 0. So i added some debug outputs in this function, but in these cases there is no response (http.read_line() returns an empty string). It strange to my, since i have no problem to create a printer object by setting the printer name manualy - i get its attributes and can start print jobs. Any ideas??
regards
Ben
More information about the cups-devel
mailing list