public static HttpURLConnection createURLConnection ( final URI uri , final RequestOptions options , UriQueryBuilder builder , final OperationContext opContext ) throws IOException , URISyntaxException , StorageException { if ( builder == null ) { builder = new UriQueryBuilder ( ) ; } if ( options . getTimeoutIntervalInMs ( ) != null && options . getTimeoutIntervalInMs ( ) != 0 ) { builder . add ( TIMEOUT , String . valueOf ( options . getTimeoutIntervalInMs ( ) / 1000 ) ) ; } final URL resourceUrl = builder . addToURI ( uri ) . toURL ( ) ; // Get the proxy settings Proxy proxy = OperationContext . getDefaultProxy ( ) ; if ( opContext != null && opContext . getProxy ( ) != null ) { proxy = opContext . getProxy ( ) ; } // Set up connection, optionally with proxy settings final HttpURLConnection retConnection ; if ( proxy != null ) { retConnection = ( HttpURLConnection ) resourceUrl . openConnection ( proxy ) ; } else { retConnection = ( HttpURLConnection ) resourceUrl . openConnection ( ) ; } /* * ReadTimeout must be explicitly set to avoid a bug in JDK 6. In certain cases, this bug causes an immediate * read timeout exception to be thrown even if ReadTimeout is not set. * * Both connect and read timeout are set to the same value as we have no way of knowing how to partition * the remaining time between these operations. The user can override these timeouts using the SendingRequest * event handler if more control is desired. */ int timeout = Utility . getRemainingTimeout ( options . getOperationExpiryTimeInMs ( ) , options . getTimeoutIntervalInMs ( ) ) ; retConnection . setReadTimeout ( timeout ) ; retConnection . setConnectTimeout ( timeout ) ; // Note : by default sends Accept behavior as text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 retConnection . setRequestProperty ( Constants . HeaderConstants . ACCEPT , Constants . HeaderConstants . XML_TYPE ) ; retConnection . setRequestProperty ( Constants . HeaderConstants . ACCEPT_CHARSET , Constants . UTF8_CHARSET ) ; // Note: by default sends Accept-Encoding as gzip retConnection . setRequestProperty ( Constants . HeaderConstants . ACCEPT_ENCODING , Constants . EMPTY_STRING ) ; // Note : by default sends Content-type behavior as application/x-www-form-urlencoded for posts. retConnection . setRequestProperty ( Constants . HeaderConstants . CONTENT_TYPE , Constants . EMPTY_STRING ) ; retConnection . setRequestProperty ( Constants . HeaderConstants . STORAGE_VERSION_HEADER , Constants . HeaderConstants . TARGET_STORAGE_VERSION ) ; retConnection . setRequestProperty ( Constants . HeaderConstants . USER_AGENT , getUserAgent ( ) ) ; retConnection . setRequestProperty ( Constants . HeaderConstants . CLIENT_REQUEST_ID_HEADER , opContext . getClientRequestID ( ) ) ; return retConnection ; }
Creates the web request .