Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.