Skip to content

Instantly share code, notes, and snippets.

@pmedcraft
Last active November 15, 2017 18:15
Show Gist options
  • Save pmedcraft/b81e2fa47219e6d11204f0e2dbd55725 to your computer and use it in GitHub Desktop.
Save pmedcraft/b81e2fa47219e6d11204f0e2dbd55725 to your computer and use it in GitHub Desktop.
Uploads customization package to WorldServer by posting to the "management_customization" servlet
/**
* Uploads customization package to WorldServer by posting to the "management_customization" servlet.
*
* @param wsBaseUrl
* @param token
* @param customizationFile
* @throws IOException
*/
private void uploadCustomization(String wsBaseUrl, String token, File customizationFile) throws IOException {
String postActionUrl = wsBaseUrl + "/ws-legacy/management_customization?action=add&token=" + token;
log.info("POST URL [" + postActionUrl + "]");
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPostRequest = new HttpPost(postActionUrl);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addBinaryBody("file", customizationFile, ContentType.DEFAULT_BINARY, customizationFile.getName());
builder.addTextBody("comp_type", "9"); // Corresponds to the "Servlet" option in the drop-down in WorldServer
builder.addTextBody("submittedBy", "ok"); // Standard value defined by the Servlet in WorldServer
HttpEntity entity = builder.build();
httpPostRequest.setEntity(entity);
HttpResponse response = httpClient.execute(httpPostRequest);
if (response.getStatusLine().getStatusCode() != 200)
throw new IOException("Error processing customization file [" + customizationFile.getName() + "]");
log.info("Finished processing customization entry [" + customizationFile.getName() + "]");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment