wjhk.jupload2.upload.helper
Class HttpConnect

java.lang.Object
  extended by wjhk.jupload2.upload.helper.HttpConnect

public class HttpConnect
extends java.lang.Object

This class implements the task of connecting to a HTTP(S) url using a proxy.

Author:
felfert

Field Summary
private static java.lang.String HTTPCONNECT_DEFAULT_PROTOCOL
           
private  UploadPolicy uploadPolicy
          The current upload policy.
 
Constructor Summary
HttpConnect(UploadPolicy policy)
          Creates a new instance.
 
Method Summary
private  void changePostURL(java.lang.String newLocation)
          Reaction of the applet when a 301, 302 et 303 return code is returned.
 java.net.Socket connect(java.net.URL url)
          Connects to a given URL automatically using a proxy.
 java.net.Socket connect(java.net.URL url, java.net.Proxy proxy)
          Connects to a given URL.
 java.lang.String getProtocol()
          Retrieve the protocol to be used for the postURL of the current policy.
private  java.net.Socket HttpProxyConnect(java.net.Proxy proxy, java.lang.String host, int port)
          Helper function for perforing a proxy CONNECT request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTPCONNECT_DEFAULT_PROTOCOL

private static final java.lang.String HTTPCONNECT_DEFAULT_PROTOCOL
See Also:
Constant Field Values

uploadPolicy

private UploadPolicy uploadPolicy
The current upload policy. Used for logging, and to get the post URL. Also used to change this URL, when it has moved (301, 302 or 303 return code)

Constructor Detail

HttpConnect

public HttpConnect(UploadPolicy policy)
Creates a new instance.

Parameters:
policy - The UploadPolicy to be used for logging.
Method Detail

HttpProxyConnect

private java.net.Socket HttpProxyConnect(java.net.Proxy proxy,
                                         java.lang.String host,
                                         int port)
                                  throws java.net.UnknownHostException,
                                         java.io.IOException,
                                         java.net.ConnectException
Helper function for perforing a proxy CONNECT request.

Parameters:
proxy - The proxy to use.
host - The destination's hostname.
port - The destination's port
Returns:
An established socket connection to the proxy.
Throws:
java.net.ConnectException - if the proxy response code is not 200
java.net.UnknownHostException
java.io.IOException

connect

public java.net.Socket connect(java.net.URL url,
                               java.net.Proxy proxy)
                        throws java.security.NoSuchAlgorithmException,
                               java.security.KeyManagementException,
                               java.net.ConnectException,
                               java.net.UnknownHostException,
                               java.io.IOException,
                               java.security.KeyStoreException,
                               java.security.cert.CertificateException,
                               java.lang.IllegalArgumentException,
                               java.security.UnrecoverableKeyException
Connects to a given URL.

Parameters:
url - The URL to connect to
proxy - The proxy to be used, may be null if direct connection is needed
Returns:
A socket, connected to the specified URL. May be null if an error occurs.
Throws:
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
java.io.IOException
java.net.UnknownHostException
java.net.ConnectException
java.security.cert.CertificateException
java.security.KeyStoreException
java.security.UnrecoverableKeyException
java.lang.IllegalArgumentException

connect

public java.net.Socket connect(java.net.URL url)
                        throws java.security.NoSuchAlgorithmException,
                               java.security.KeyManagementException,
                               java.net.ConnectException,
                               java.net.UnknownHostException,
                               java.io.IOException,
                               java.net.URISyntaxException,
                               java.security.KeyStoreException,
                               java.security.cert.CertificateException,
                               java.lang.IllegalArgumentException,
                               java.security.UnrecoverableKeyException
Connects to a given URL automatically using a proxy.

Parameters:
url - The URL to connect to
Returns:
A socket, connected to the specified URL. May be null if an error occurs.
Throws:
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
java.io.IOException
java.net.UnknownHostException
java.net.ConnectException
java.net.URISyntaxException
java.security.UnrecoverableKeyException
java.security.cert.CertificateException
java.security.KeyStoreException
java.security.UnrecoverableKeyException
java.lang.IllegalArgumentException

getProtocol

public java.lang.String getProtocol()
                             throws java.net.URISyntaxException,
                                    java.security.KeyManagementException,
                                    java.security.NoSuchAlgorithmException,
                                    java.net.UnknownHostException,
                                    java.security.KeyStoreException,
                                    java.security.cert.CertificateException,
                                    java.lang.IllegalArgumentException,
                                    java.security.UnrecoverableKeyException,
                                    java.io.IOException,
                                    JUploadException
Retrieve the protocol to be used for the postURL of the current policy. This method issues a HEAD request to the postURL and then examines the protocol version returned in the response.

Returns:
The string, describing the protocol (e.g. "HTTP/1.1")
Throws:
java.net.URISyntaxException
java.io.IOException
java.security.UnrecoverableKeyException
java.lang.IllegalArgumentException
java.security.cert.CertificateException
java.security.KeyStoreException
java.net.UnknownHostException
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
JUploadException

changePostURL

private void changePostURL(java.lang.String newLocation)
                    throws JUploadException
Reaction of the applet when a 301, 302 et 303 return code is returned. The postURL is changed according to the Location header returned.

Parameters:
newLocation - This new location may contain the http://host.name.domain part of the URL ... or not
Throws:
JUploadException