Last active
November 15, 2017 18:15
-
-
Save pmedcraft/b81e2fa47219e6d11204f0e2dbd55725 to your computer and use it in GitHub Desktop.
Uploads customization package to WorldServer by posting to the "management_customization" servlet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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