* @throws UpdateException
* @throws IOException
*/
private File searchForVersion ( Map<String, String> map ) throws UpdateException, IOException {
PostMethod method = doGet( url, map );
int ret = method.getStatusCode();
if ( ret == 200 ) {
// Get the version of the jar.
try {
newMinor = method.getResponseHeader( "Minor-Version" ).getValue();
if ( newMinor.trim().length() > 0 ) {
String[] minorArr = newMinor.split( "_" );
if ( minorArr.length > 1 ) {
logger.info( Messages.getString( "UpdateAgent.text.latest.version" ) + minorArr[0] + " / " + minorArr[1] );
} else {
logger.info( Messages.getString( "UpdateAgent.text.latest.version" ) + minorArr[0] );
}
newVersion = minorArr[0];
logger.info( " " );
} else {
throw new Exception();
}
} catch ( Exception e ) {
logger.debug( Messages.getString( "UpdateAgent.error.no.minor.version" ), e );
throw new UpdateException( Messages.getString( "UpdateAgent.error.no.minor.version" ), UpdateException.ERROR );
}
String fileName = "update_" + newVersion + ".zip";
File updateFile = new File( getDistributionPath() + File.separator + FOLDER_HOME_UPDATER + File.separator + "updates" + File.separator + fileName );
if ( updateFile.exists() ) {
//check md5 of file
String MD5 = null;
boolean hasMD5 = false;
if ( method.getResponseHeader( "Content-MD5" ) != null && !method.getResponseHeader( "Content-MD5" ).equals( "" ) && !method.getResponseHeader( "Content-MD5" ).equals( "null" ) ) {
MD5 = method.getResponseHeader( "Content-MD5" ).getValue();
if ( !MD5.equals( "" ) ) {
hasMD5 = true;
}
}
if ( hasMD5 ) {
String dlMD5 = UpdateUtil.getMD5( updateFile );
logger.debug( Messages.getString( "UpdateAgent.debug.server.md5" ) + MD5 );
logger.debug( Messages.getString( "UpdateAgent.debug.file.md5" ) + dlMD5 );
if ( MD5 == null || MD5.length() == 0 || !dlMD5.equals( MD5 ) ) {
logger.fatal( Messages.getString( "UpdateAgent.error.md5.failed" ) );
throw new UpdateException( Messages.getString( "UpdateAgent.error.file.exists" ) + fileName, UpdateException.ERROR );
}
} else {
// file verified, let's use it
logger.info( updateFile.getName() + ": " + Messages.getString( "UpdateAgent.text.md5.verified" ) );
}
} else {
//Create the updates directory
if ( !updateFile.getParentFile().exists() ) {
updateFile.getParentFile().mkdirs();
}
// Download the update content, the update servlet will provide an url for the update file
String downloadUrl = method.getResponseHeader( "Download-Link" ).getValue();
download( downloadUrl, updateFile, method );
}
return updateFile;