On Thu, 2010-12-09 at 23:57 -0800, Karl Heinz Marbaise wrote: > Hi to all, > > I have the following http://imagebin.ca/view/vt_QBTQ6.html form which i > like to post data to...and i have the following code: > > DefaultHttpClient httpClient = new DefaultHttpClient(); > String triggerJobUrl = getHudsonURL() + "/job/" + jobName + > "/build"; > > HttpPost httppost = new HttpPost(triggerJobUrl); > > FileBody fileBody = new FileBody(releaseProperties, > "application/octet-stream"); > StringBody stringBody = new StringBody(svnURL.toString()); > > MultipartEntity mentity = new > MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); > mentity.addPart("file0", 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); > } > } > > I'm using the following dependencies in my project: > <dependency> > <groupId>org.apache.httpcomponents</groupId> > <artifactId>httpclient</artifactId> > <version>4.0.1</version> > </dependency> > <dependency> > <groupId>org.apache.httpcomponents</groupId> > <artifactId>httpcore</artifactId> > <version>4.0.1</version> > </dependency> > <dependency> > <groupId>org.apache.httpcomponents</groupId> > <artifactId>httpmime</artifactId> > <version>4.0.1</version> > </dependency> > > > The problem with the above code is that i always get the following message > from the Server (Hudson): > SEVERE: Servlet.service() for servlet Stapler threw exception > java.lang.Error: This page expects a form submission > at > org.kohsuke.stapler.RequestImpl.getSubmittedForm(RequestImpl.java:769) > at > hudson.model.ParametersDefinitionProperty._doBuild(ParametersDefinitionProperty.java:116) > at hudson.model.AbstractProject.doBuild(AbstractProject.java:1479) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:597) > at > org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:282) > at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:149) > at > org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:88) > at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:102) > at > org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53) > at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:562) > at org.kohsuke.stapler.Stapler.invoke(Stapler.java:640) > at org.kohsuke.stapler.MetaClass$7.doDispatch(MetaClass.java:242) > at > org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53) > at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:562) > at org.kohsuke.stapler.Stapler.invoke(Stapler.java:640) > at org.kohsuke.stapler.Stapler.invoke(Stapler.java:478) > at org.kohsuke.stapler.Stapler.service(Stapler.java:160) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) > at > hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:94) > at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:86) > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) > at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:47) > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) > at > hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:84) > at > hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:76) > at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:164) > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) > at > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) > at > org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) > at > org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470) > at > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) > at > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) > at > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) > at > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) > at > org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) > at > org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) > at > org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) > at java.lang.Thread.run(Thread.java:662) > > The point is that i have a running example via command line (CURL) which > works perfectly: > curl -i [email protected] -Fjson='{"parameter": [{"name": > "trunk/release.properties", "file": "file0"}, {"name" : "SVNURL" , "value" > :"http://xxx.yyy.zzz.aaaa/svn/test/xxxx"}]}' -FSubmit=Build > 'http://aaa.bbb.ccc.ddd:8080/job/maven-changes-checker-parameter/build' > > May be someone can give me hint or a suggestion about that problem? > > Many thanks in advance > Kind regards > Karl Heinz Marbaisea
Turn on wire logging [1] to capture the HTTP message generated by HttpClient and use wire shark or similar tool to capture that generated by CURL. Compare and adjust your HttpClient configuration. [1] http://hc.apache.org/httpcomponents-client-ga/logging.html --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
