开发者

Using Java for FTP Put command over Squid HTTP Proxy error

I am a bit green with Java but I have ran into an issue when trying to UPLOAD a local file to a remote FTP server through a SQUID HTTP proxy (please note this obviously ties my hands so that 'FTP' and 'SOCKS' proxy types are not in scope).

So here is my code:

                       URL url = new URL(urlString);
                       OutputStream os ;                             

                       System.setProperty("proxySet", "true");
                       System.setProperty("proxyHost", proxyHost.trim());
                       System.setProperty("proxyPort", proxyPort.stringValue());


                       URLConnection ftpConn = url.openConnection() ;
                       ftpConn.setAllowUserInteraction(true); //threw this in to see if it would work, does nothing
                       ftpConn.setDoOutput(true); //here is where I set the setDoOutput
                       os = ftpConn.getOutputStream(); //here is where the exception occurs

I keep getting this exception:

Java call terminated by uncaught Java exception: java.net.ProtocolException: cannot wri开发者_Go百科te to a URLConnection if doOutput=false - call setDoOutput(true)

So I have tried this with an FTPURLConnection etc and have had the same issue.

When debugging this, it appears that there are no less than THREE variables that are called doOutput within the ftpConn.

Only one is editable (whereas the other two are not)

The first one (and it seems the one that is returned via the getDoOutput) returns true after the setting of the ftpConn.setDoOutput(true);.

looking over the source code for HttpURLConnection:

 public synchronized OutputStream getOutputStream()
                    throws IOException {

                try {
                    if (!doOutput) {
                        throw new ProtocolException(
                                "cannot write to a URLConnection"
                                        + " if doOutput=false - call setDoOutput(true)");
                    }

Looking over the Proxy handling in FtpURLConnection leads me to believe that when it determines that you are using an HTTP Proxy it passes off the the processing to the HttpURLConnection.

This is where I think the disconnect is happening (either for me or the library or the proxy).

Am I missing someway to set the setDoOutput or something else?

I have been able to successfully tunnel out of the proxy for GETs, but PUTs are all FAILING on the doOutput.

Thanks for any help or pointers to get this to work.

P.S. I am using Java 1.5.0_10 (we are here to remain consistent with other applications)


well found out this is a bug (Bug 6519647) in metalink. the workaround is pretty much use something different!

(this bug persists no matter how the proxy is set (with/wihtout the "http." and even via the proxy class)

sorry for the duplicate edit/answer, this is my first 'answer' to my own question.

switched over the ftp4j but still running into squid proxy issues (which is a whole different story).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜