Skip to content

Commit

Permalink
Fixes scriptfile dispatch to use POST for #228
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Jan 7, 2013
1 parent b03f742 commit 1c5eddb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.dtolabs.rundeck.core.cli.CLIUtils;
import com.dtolabs.rundeck.core.common.Framework;
import com.dtolabs.rundeck.core.dispatcher.*;
import com.dtolabs.rundeck.core.execution.ExecutionResult;
import com.dtolabs.rundeck.core.utils.NodeSet;
import com.dtolabs.utils.Streams;
import org.apache.commons.httpclient.URIException;
Expand Down Expand Up @@ -224,7 +223,7 @@ public QueuedItemResult queueDispatcherScript(final IDispatchedScript iDispatche
String scriptURL=null;
final boolean isExec;
final boolean isUrl;

File uploadFile=null;
try {

//write script to file
Expand All @@ -249,13 +248,7 @@ public QueuedItemResult queueDispatcherScript(final IDispatchedScript iDispatche
isUrl = false;
} else if (null != iDispatchedScript.getServerScriptFilePath()) {
//server-local script filepath

//read stream to string
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Streams.copyStream(new FileInputStream(new File(iDispatchedScript.getServerScriptFilePath())),
byteArrayOutputStream);
scriptString = new String(byteArrayOutputStream.toByteArray());

uploadFile = new File(iDispatchedScript.getServerScriptFilePath());
if (null != iDispatchedScript.getArgs() && iDispatchedScript.getArgs().length > 0) {
argString = CLIUtils.generateArgline(null, iDispatchedScript.getArgs());
} else {
Expand Down Expand Up @@ -297,17 +290,17 @@ public QueuedItemResult queueDispatcherScript(final IDispatchedScript iDispatche
params.put("exec", argString);
}else if (null != scriptURL) {
params.put("scriptURL", scriptURL);
} else {
params.put("scriptFile", scriptString);
}
if(null!=argString){
params.put("argString", argString);
}
addLoglevelParams(params, iDispatchedScript.getLoglevel());
addAPINodeSetParams(params, iDispatchedScript.getNodeSet(), iDispatchedScript.getNodeSet().isKeepgoing());

return submitRunRequest(null, params,
isExec ? RUNDECK_API_RUN_COMMAND : isUrl ? RUNDECK_API_RUN_URL : RUNDECK_API_RUN_SCRIPT);
return submitRunRequest(uploadFile,
params,
isExec ? RUNDECK_API_RUN_COMMAND : isUrl ? RUNDECK_API_RUN_URL : RUNDECK_API_RUN_SCRIPT,
"scriptFile");
}

/**
Expand All @@ -334,7 +327,7 @@ private QueuedItemResult submitExecutionRequest(final File tempxml, final HashMa

final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(requestPath, params, tempxml, null);
response = serverService.makeRundeckRequest(requestPath, params, tempxml, null, "xmlBatch");
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand All @@ -357,6 +350,7 @@ private QueuedItemResult submitExecutionRequest(final File tempxml, final HashMa
* Submit a request to the server which expects an execution id in response, and return a single
* QueuedItemResult parsed from the response.
*
* @param uploadFileParam name of file upload parameter
* @param tempxml xml temp file (or null)
* @param otherparams parameters for the request
* @param requestPath
Expand All @@ -366,8 +360,10 @@ private QueuedItemResult submitExecutionRequest(final File tempxml, final HashMa
* @throws com.dtolabs.rundeck.core.dispatcher.CentralDispatcherException
* if an error occurs
*/
private QueuedItemResult submitRunRequest(final File tempxml, final HashMap<String, String> otherparams,
final String requestPath) throws CentralDispatcherException {
private QueuedItemResult submitRunRequest(final File tempxml,
final HashMap<String, String> otherparams,
final String requestPath,
final String uploadFileParam) throws CentralDispatcherException {


final HashMap<String, String> params = new HashMap<String, String>();
Expand All @@ -377,7 +373,7 @@ private QueuedItemResult submitRunRequest(final File tempxml, final HashMap<Stri

final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(requestPath, params, tempxml, null);
response = serverService.makeRundeckRequest(requestPath, params, tempxml, null, null, null, uploadFileParam);
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand Down Expand Up @@ -430,7 +426,8 @@ public Collection<QueuedItem> listDispatcherQueue(final String project) throws C

final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(RUNDECK_API_LIST_EXECUTIONS_PATH, params, null, null);
response = serverService.makeRundeckRequest(RUNDECK_API_LIST_EXECUTIONS_PATH, params, null, null,
null);
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand Down Expand Up @@ -707,7 +704,7 @@ public DispatcherResult killDispatcherExecution(final String execId) throws Cent
//2. send request via ServerService
final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(rundeckApiKillJobPath, params, null, null);
response = serverService.makeRundeckRequest(rundeckApiKillJobPath, params, null, null, null);
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand Down Expand Up @@ -743,7 +740,7 @@ public ExecutionDetail getExecution(final String execId) throws CentralDispatche
//2. send request via ServerService
final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(rundeckApiKillJobPath, params, null, null);
response = serverService.makeRundeckRequest(rundeckApiKillJobPath, params, null, null, null);
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand Down Expand Up @@ -816,7 +813,7 @@ public ExecutionFollowResult followDispatcherExecution(final String execId, fina
//2. send request via ServerService
final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(rundeckApiExecOutputJobPath, params, null, null);
response = serverService.makeRundeckRequest(rundeckApiExecOutputJobPath, params, null, null, null);
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand Down Expand Up @@ -1044,7 +1041,7 @@ public Collection<IStoredJob> listStoredJobs(final IStoredJobsQuery iStoredJobsQ
final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(RUNDECK_API_JOBS_EXPORT_PATH, params, null, null,
expectedContentType);
expectedContentType, null);
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand Down Expand Up @@ -1244,7 +1241,7 @@ public Collection<IStoredJob> reallistStoredJobs(final IStoredJobsQuery iStoredJ
//2. send request via ServerService
final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(RUNDECK_API_JOBS_LIST_PATH, params, null, null);
response = serverService.makeRundeckRequest(RUNDECK_API_JOBS_LIST_PATH, params, null, null, null);
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand Down Expand Up @@ -1477,7 +1474,7 @@ public Collection<IStoredJobLoadResult> loadJobs(final ILoadJobsRequest iLoadJob
//2. send request via ServerService
final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(RUNDECK_API_JOBS_UPLOAD, params, input, null);
response = serverService.makeRundeckRequest(RUNDECK_API_JOBS_UPLOAD, params, input, null, "xmlBatch");
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void reportExecutionStatus(final String project, final String title, fina

final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(RUNDECK_API_EXECUTION_REPORT, params, null, null);
response = serverService.makeRundeckRequest(RUNDECK_API_EXECUTION_REPORT, params, null, null, "xmlBatch");
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand Down Expand Up @@ -207,7 +207,7 @@ private QueuedItemResult submitQueueRequest(final File tempxml, final HashMap<St

final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(requestPath, params, tempxml, null);
response = serverService.makeRundeckRequest(requestPath, params, tempxml, null, "xmlBatch");
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand Down Expand Up @@ -288,7 +288,7 @@ public Collection<QueuedItem> listDispatcherQueue(final String project) throws C

final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(RUNDECK_LIST_EXECUTIONS_PATH, params, null, null);
response = serverService.makeRundeckRequest(RUNDECK_LIST_EXECUTIONS_PATH, params, null, null, "xmlBatch");
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand Down Expand Up @@ -460,7 +460,7 @@ public DispatcherResult killDispatcherExecution(final String execId) throws Cent
//2. send request via ServerService
final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(RUNDECK_KILL_JOB_PATH, params, null, null);
response = serverService.makeRundeckRequest(RUNDECK_KILL_JOB_PATH, params, null, null, "xmlBatch");
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand Down Expand Up @@ -533,7 +533,7 @@ public Collection<IStoredJob> listStoredJobs(final IStoredJobsQuery iStoredJobsQ
//2. send request via ServerService
final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(RUNDECK_LIST_STORED_JOBS_PATH, params, null, null);
response = serverService.makeRundeckRequest(RUNDECK_LIST_STORED_JOBS_PATH, params, null, null, "xmlBatch");
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand Down Expand Up @@ -805,7 +805,7 @@ public Collection<IStoredJobLoadResult> loadJobs(final ILoadJobsRequest iLoadJob
//2. send request via ServerService
final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(RUNDECK_JOBS_UPLOAD, params, input, null);
response = serverService.makeRundeckRequest(RUNDECK_JOBS_UPLOAD, params, input, null, "xmlBatch");
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
Expand Down
34 changes: 24 additions & 10 deletions core/src/main/java/com/dtolabs/client/services/ServerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ public ServerService(final WebConnectionParameters connParams) {
* @param uploadFile a file to upload with the request.
* @param method HTTP connection method, e.g. "get","post","put","delete".
*
* @param uploadFileParam name of the uploaded file param
* @return parsed XML document, or null
*
* @throws com.dtolabs.rundeck.core.CoreException
* if an error occurs
* @throws java.net.MalformedURLException if connection URL or urlPath params are malformed.
*/
public WebserviceResponse makeRundeckRequest(final String urlPath, final Map queryParams, final File uploadFile,
final String method)
final String method, final String uploadFileParam)
throws CoreException, MalformedURLException {
return makeRundeckRequest(urlPath, queryParams, uploadFile, method, null);
return makeRundeckRequest(urlPath, queryParams, uploadFile, method, null, uploadFileParam);
}
/**
* Make the request to the ItNav workbench.
Expand All @@ -110,13 +111,16 @@ public WebserviceResponse makeRundeckRequest(final String urlPath, final Map que
* if an error occurs
* @throws java.net.MalformedURLException if connection URL or urlPath params are malformed.
*/
public WebserviceResponse makeRundeckRequest(final String urlPath, final Map queryParams, final Map<String,? extends Object> formData)
public WebserviceResponse makeRundeckRequest(final String urlPath,
final Map queryParams,
final Map<String, ? extends Object> formData)
throws CoreException, MalformedURLException {
return makeRundeckRequest(urlPath, queryParams, null, null, null, formData);
return makeRundeckRequest(urlPath, queryParams, null, null, null, formData, null);
}
/**
* Make the request to the ItNav workbench.
*
* @param uploadFileParam name of the uploaded file param
* @param urlPath the path for the request
* @param queryParams any query parameters
* @param uploadFile a file to upload with the request.
Expand All @@ -128,14 +132,19 @@ public WebserviceResponse makeRundeckRequest(final String urlPath, final Map que
* if an error occurs
* @throws java.net.MalformedURLException if connection URL or urlPath params are malformed.
*/
public WebserviceResponse makeRundeckRequest(final String urlPath, final Map queryParams, final File uploadFile,
final String method, final String expectedContentType)
public WebserviceResponse makeRundeckRequest(final String urlPath,
final Map queryParams,
final File uploadFile,
final String method,
final String expectedContentType,
final String uploadFileParam)
throws CoreException, MalformedURLException {
return makeRundeckRequest(urlPath, queryParams, uploadFile, method, expectedContentType, null);
return makeRundeckRequest(urlPath, queryParams, uploadFile, method, expectedContentType, null, uploadFileParam);
}
/**
* Make the request to the ItNav workbench.
*
* @param uploadFileParam name of the uploaded file param
* @param urlPath the path for the request
* @param queryParams any query parameters
* @param uploadFile a file to upload with the request.
Expand All @@ -147,8 +156,13 @@ public WebserviceResponse makeRundeckRequest(final String urlPath, final Map que
* if an error occurs
* @throws java.net.MalformedURLException if connection URL or urlPath params are malformed.
*/
public WebserviceResponse makeRundeckRequest(final String urlPath, final Map queryParams, final File uploadFile,
final String method, final String expectedContentType, final Map<String,? extends Object> formData)
public WebserviceResponse makeRundeckRequest(final String urlPath,
final Map queryParams,
final File uploadFile,
final String method,
final String expectedContentType,
final Map<String, ? extends Object> formData,
final String uploadFileParam)
throws CoreException, MalformedURLException {
if (null == connParams) {
throw new IllegalArgumentException("WebConnectionParameters must be specified");
Expand All @@ -165,7 +179,7 @@ public WebserviceResponse makeRundeckRequest(final String urlPath, final Map que
connParams.getPassword(),
queryParams,
uploadFile,
"xmlBatch",null,expectedContentType);
uploadFileParam,null,expectedContentType);
}else{
hc = WebserviceHttpClientFactory.getInstance().getWebserviceHttpClient(jcUrl
+ urlPath,
Expand Down

0 comments on commit 1c5eddb

Please sign in to comment.