"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.
PostMethod postMethod = new PostMethod(gatekeeperUrl);
Properties properties = gatekeeperMessage.encodeToProperties();
Iterator propsIter = properties.entrySet().iterator();
while (propsIter.hasNext()) {
Map.Entry entry = (Map.Entry) propsIter.next();
String fieldName = (String) entry.getKey();
String fieldValue = (String) entry.getValue();
postMethod.setParameter(fieldName, fieldValue);
}
// Create Http Client if necessary, and include User Agent information.
if (httpClientGatekeeper == null) {
httpClientGatekeeper = initHttpConnection();
}
// Try to detect any necessary proxy configurations.
try {
ProxyHost proxyHost = PluginProxyUtil.detectProxy(new URL(gatekeeperUrl));
if (proxyHost != null) {
HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setProxyHost(proxyHost);
httpClientGatekeeper.setHostConfiguration(hostConfig);
httpClientGatekeeper.getParams().setAuthenticationPreemptive(true);
httpClientGatekeeper.getParams().setParameter(CredentialsProvider.PROVIDER, this);
}
} catch (Throwable t) {
log.debug("No proxy detected");
}
// Perform Gateway request.
log.debug("Contacting Gatekeeper at: " + gatekeeperUrl);
try {
int responseCode = httpClientGatekeeper.executeMethod(postMethod);
String contentType = postMethod.getResponseHeader("Content-Type").getValue();
if (responseCode == 200) {
InputStream responseInputStream = null;
Header encodingHeader = postMethod.getResponseHeader("Content-Encoding");
if (encodingHeader != null && "gzip".equalsIgnoreCase(encodingHeader.getValue())) {
log.debug("Inflating gzip-encoded response");
responseInputStream = new GZIPInputStream(postMethod.getResponseBodyAsStream());
} else {
responseInputStream = postMethod.getResponseBodyAsStream();
}
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;