use of org.netxms.ui.eclipse.serverconfig.dialogs.RepositorySelectionDialog in project netxms by netxms.
the class ExportFileBuilder method publishStage2.
/**
* Publish configuration - stage 2
*
* @param repositories
*/
private void publishStage2(List<Repository> repositories) {
RepositorySelectionDialog dlg = new RepositorySelectionDialog(getSite().getShell(), repositories);
if (dlg.open() != Window.OK)
return;
final Repository repository = dlg.getSelection();
doExport(new ExportCompletionHandler() {
@Override
public void exportCompleted(final String xml) {
new ConsoleJob("Publish configuration", ExportFileBuilder.this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
URL url = new URL(repository.getUrl() + "/rest-api/push-export?accessToken=" + repository.getAuthToken());
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection)) {
throw new Exception("Unsupported URL type");
}
((HttpURLConnection) conn).setRequestMethod("POST");
((HttpURLConnection) conn).setRequestProperty("User-Agent", "NetXMS Console/" + NXCommon.VERSION);
((HttpURLConnection) conn).setRequestProperty("Content-Type", "application/xml; charset=utf-8");
((HttpURLConnection) conn).setDoOutput(true);
((HttpURLConnection) conn).setAllowUserInteraction(false);
((HttpURLConnection) conn).setUseCaches(false);
OutputStream out = conn.getOutputStream();
try {
out.write(xml.getBytes("UTF-8"));
out.flush();
int responseCode = ((HttpURLConnection) conn).getResponseCode();
Activator.logInfo("Publish config: url=" + url.toString() + " response=" + responseCode);
if (responseCode != 200) {
throw new Exception(String.format("HTTP error %d", responseCode));
}
} finally {
out.close();
}
}
@Override
protected String getErrorMessage() {
return "Cannot publish configuration to repository";
}
}.start();
}
});
}
Aggregations