Forum How do I...?

Java http-proxy

sonyEU
I am using prince 6.0 rev 5 and using java input output streams to generate pdf. The generated pdf does not include images if my java application runs under a http-proxy. To overcome this issue I modified Prince.java as below, to indicate the proxy for prince.exe. After that pdf is being generated with images, but now the css, depicted in html, is not being applied.
Do you have an idea to use http-proxy without any malfunctionality?

Application Code
is = url.openStream();
fos = new FileOutputStream( pdfFilePath );
prince.setBaseURL(url.toString());
success = prince.convert(is, fos);


Prince.java
public class Prince{
    //Proxy settings
    private String mHttpProxyHost;
    private String mHttpProxyPort;
    ...
    private List getCommandLine(){
        ....

    cmdline.add("--http-proxy="+mHttpProxyHost+":"+mHttpProxyPort);
        ...
    }
}

Generated commandline
[C:\Program Files\Prince\Engine\bin\Prince.exe, --input=html, --baseurl=http://localhost/pdf/PMW-EX1.html, --http-proxy=someIP:8080, --server, --silent, -]
sonyEU
I found the reason, this malfunctionality occurs for urls with domain "localhost". For input streams opened from localhost domain, if a proxy defined, reponse returns http error 503 (Service unavailable). I think given http-proxy should be discarded for localhost and 127.0.0.1 domains. This should be implemented in prince.exe.
mikeday
Thanks, we'll fix this issue for the next maintenance release of Prince.
mikeday
The new Prince 6.0 rev 6 release includes a fix for this issue, and it should not use the specified HTTP proxy for localhost URLs. Thanks for reporting the issue! :)
fran
It would be nice if we could specify host that we don't want to use proxy when we specify a proxy:

example :
 prince http://192.168.0.1/test.html -o out.pdf --http-proxy=proxy:8080 --non-proxy-hosts=192.168.0.1,localhost,...


It is more flexible.

Thanks,
François
bookdev
Could you please be so kind as to let me know we you can specify a password for a proxy, if you don't mind? I tried --http-proxy=ip:port:name:password but that didn't work. Thanks.
mikeday
How about "--http-proxy=http://name:password@ip:port"?
bookdev
Yes, that works. Thanks, Mike!