Currently i'm searching for a working method to upload a file + a field in the following confiuguration of Hudson. The current problem is that Hudson always complains about a form which should be submitted..(see exception later in this post). But based on the docs i read it should be working like the following Java code snippet...
HttpPost httppost = new HttpPost(triggerJobUrl);
FileBody fileBody = new FileBody(releaseProperties);
StringBody stringBody = new StringBody(svnURL.toString());
MultipartEntity mentity = new MultipartEntity();
mentity.addPart("trunk/release.properties", fileBody);
mentity.addPart("SVNURL", stringBody);
httppost.setEntity(mentity);
HttpResponse response = null;
try {
response = httpClient.execute(httppost);
} catch (ClientProtocolException e) {
throw new HudsonException("http protocol error.", e);
} catch (IOException e) {
throw new HudsonException("connection aborted.", e);
}
if (response.getStatusLine().getStatusCode() != 200) {
throw new HudsonException("Unexpected status code received " + response.getStatusLine().getStatusCode());
}
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
try {
resEntity.consumeContent();
} catch (IOException e) {
throw new HudsonException(
"if an I/O error occurs. This indicates that connection keep-alive is not possible.", e);
}
}
My current Maven dependencies are as follows:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.0.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.0.3</version>
<type>jar</type>
<scope>compile</scope>
The exception is this:
java.lang.Error: This page expects a form submission
at org.kohsuke.stapler.RequestImpl.getSubmittedForm(RequestImpl.java:769)
at hudson.model.ParametersDefinitionProperty._doBuild(ParametersDefinit