目前我正在寻找一种工作方法,在
Hudson的以下配置中上传文件一个字段.目前的问题是Hudson总是抱怨应该提交的表格..(参见本文稍后的例外).但根据我阅读的文档,它应该像下面的Java代码片段一样工作…
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);
}
}
我目前的Maven依赖关系如下:
org.apache.httpcomponents
httpclient
4.0.3
org.apache.httpcomponents
httpcore
4.0.1
jar
compile
org.apache.httpcomponents
httpmime
4.0.3
jar
compile
例外是这样的:
java.lang.Error: This page expects a form submission
at org.kohsuke.stapler.RequestImpl.getSubmittedForm(RequestImpl.java:769)
at hudson.model.ParametersDefinitionProperty._doBuild(ParametersDefinit