"gatekeeperUrl", "Missing required property gatekeeperUrl");
/*
* Build Gatekeeper request.
*/
GatekeeperMessage gatekeeperMessage = new GatekeeperMessage();
gatekeeperMessage.addApplicationProperties(userInputProperties); // Add User inputs as application properties.
gatekeeperMessage.addApplicationProperties(parametersMap); // Add any Applet/Application parameters as application properties.
// Make the Uploader's identifier available to Gatekeeper for version compatibility checking (if necessary)
gatekeeperMessage.addApplicationProperty(
GatekeeperMessage.PROPERTY_CLIENT_VERSION_ID, UPLOADER_VERSION_ID);
// If a prior failure has occurred, add information about this failure.
if (priorFailureException != null) {
gatekeeperMessage.addApplicationProperty(GatekeeperMessage.PROPERTY_PRIOR_FAILURE_MESSAGE,
priorFailureException.getMessage());
// Now reset the prior failure variable.
priorFailureException = null;
}
// Add all S3 objects as candiates for PUT signing.
for (int i = 0; i < objects.length; i++) {
SignatureRequest signatureRequest = new SignatureRequest(
SignatureRequest.SIGNATURE_TYPE_PUT, objects[i].getKey());
signatureRequest.setObjectMetadata(objects[i].getMetadataMap());
gatekeeperMessage.addSignatureRequest(signatureRequest);
}
/*
* Build HttpClient POST message.
*/
// Add all properties/parameters to credentials POST request.
HttpPost postMethod = new HttpPost(gatekeeperUrl);
Properties properties = gatekeeperMessage.encodeToProperties();
Iterator<Map.Entry<Object, Object>> propsIter = properties.entrySet().iterator();
List<NameValuePair> parameters = new ArrayList<NameValuePair>(properties.size());
while (propsIter.hasNext()) {
Map.Entry<Object, Object> entry = propsIter.next();
String fieldName = (String) entry.getKey();
String fieldValue = (String) entry.getValue();
parameters.add(new BasicNameValuePair(fieldName, fieldValue));
}
postMethod.setEntity(new UrlEncodedFormEntity(parameters));
// Create Http Client if necessary, and include User Agent information.
if (httpClientGatekeeper == null) {
httpClientGatekeeper = initHttpConnection();
}
// Try to detect any necessary proxy configurations.
try {
HttpHost proxyHost = PluginProxyUtil.detectProxy(new URL(gatekeeperUrl));
if (proxyHost != null) {
httpClientGatekeeper.getParams().setParameter(
ConnRoutePNames.DEFAULT_PROXY,
proxyHost);
}
((DefaultHttpClient)httpClientGatekeeper).setCredentialsProvider(this);
} catch (Throwable t) {
log.debug("No proxy detected");
}
// Perform Gateway request.
log.debug("Contacting Gatekeeper at: " + gatekeeperUrl);
HttpResponse response = null;
try {
response = httpClientGatekeeper.execute(postMethod);
int responseCode = response.getStatusLine().getStatusCode();
String contentType = response.getFirstHeader("Content-Type").getValue();
if (responseCode == 200) {
InputStream responseInputStream = null;
Header encodingHeader = response.getFirstHeader("Content-Encoding");
if (encodingHeader != null && "gzip".equalsIgnoreCase(encodingHeader.getValue())) {
log.debug("Inflating gzip-encoded response");
responseInputStream = new GZIPInputStream(response.getEntity().getContent());
} else {
responseInputStream = response.getEntity().getContent();
}
if (responseInputStream == null) {
throw new IOException("No response input stream available from Gatekeeper");
}
Properties responseProperties = new Properties();
try {
responseProperties.load(responseInputStream);
} finally {
responseInputStream.close();
}
GatekeeperMessage gatekeeperResponseMessage =
GatekeeperMessage.decodeFromProperties(responseProperties);
// Check for Gatekeeper Error Code in response.
String gatekeeperErrorCode = gatekeeperResponseMessage.getApplicationProperties()
.getProperty(GatekeeperMessage.APP_PROPERTY_GATEKEEPER_ERROR_CODE);
if (gatekeeperErrorCode != null) {
log.warn("Received Gatekeeper error code: " + gatekeeperErrorCode);
failWithFatalError(gatekeeperErrorCode);
return null;
}
if (gatekeeperResponseMessage.getSignatureRequests().length != objects.length) {
throw new Exception("The Gatekeeper service did not provide the necessary "
+ objects.length + " response items");
}
return gatekeeperResponseMessage;