|
|
Re: Hudson remote api usage [message #1059541 is a reply to message #1058749] |
Mon, 20 May 2013 11:36 |
hariprasadh balasubramanian Messages: 18 Registered: April 2013 |
Junior Member |
|
|
Hi All,
Running Hudson as the service in 8080 port.Iam have wrote sample java code to create job in hudson and trigger it from the remote windows machine.The config.xml is taken from the jobs folder of another job:
But it is throwing 500 error(Response status code: 500
package createJob;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
public class CreateJob {
public static void main(String[] args) throws FileNotFoundException {
String strURL = "htt://XXXX:8080/createItem?name=findsresume123";
File input = new File("C:\\Users\\XXXX\\Desktop\\config.xml");
PostMethod post = new PostMethod(strURL);
post.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(input), input.length()));
post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
HttpClient httpclient = new HttpClient();
try {
int result = httpclient.executeMethod(post);
System.out.println("Response status code: " + result);
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());
}
catch (Exception e) {
// Release current connection to the connection pool
// once you are done
post.releaseConnection();
}
// TODO Auto-generated method stub
}
}
Response body:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 500 Unable to read /var/lib/hudson/jobs/yyyy/config.xml</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /createItem. Reason:
<pre> Unable to read /var/lib/hudson/jobs/yyyy/config.xml</pre></p><h3>Caused by:</h3><pre>hudson.util.IOException2: Unable to read /var/lib/hudson/jobs/yyyy/config.xml
at hudson.XmlFile.read(XmlFile.java:119)
at hudson.model.Items.load(Items.java:113)
at hudson.model.ItemGroupMixIn.createProjectFrom
at hudson.model.ItemGroupMixIn.createTopLevelItem(ItemGroupMixIn.java:161)
at hudson.model.Hudson.doCreateItem(Hudson.java:2676)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:274)
at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:141)
at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:80)
at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:95)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:45)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:565)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:650)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:481)
at org.kohsuke.stapler.Stapler.service(Stapler.java:152)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:648)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1336)
at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:86)
at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:78)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:81)
at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:73)
at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:157)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:70)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:534)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:365)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:679)
Caused by: com.thoughtworks.xstream.converters.ConversionException: : no more data available - expected end tag </project> to close start tag <project> from line 2, parser stopped on END_TAG seen ...<builders/>\r\n... @205:1 : : no more data available - expected end tag </project> to close start tag <project> from line 2, parser stopped on END_TAG seen ...<builders/>\r\n... @205:1
---- Debugging information ----
...............
I have not turn on authentication.
version-hudson-3.0.1.If i need turn on authentication please explain the steps too.
Please help me out in resolving this
[Updated on: Tue, 21 May 2013 12:12] Report message to a moderator
|
|
|
|
Re: Hudson remote api usage [message #1059743 is a reply to message #1059626] |
Tue, 21 May 2013 13:24 |
hariprasadh balasubramanian Messages: 18 Registered: April 2013 |
Junior Member |
|
|
Hi,
I have configured security and enabled it as mentioned in the url:
http://wiki.hudson-ci.org/display/HUDSON/Standard+Security+Setup
I have created users and give all permissions to create job
I have modified the code as accessing the url with username and password which i created now.
Create Job
I have created the job as mentioned below in the site.
To create a new job, POST config.xml to http://your_server/createItem (copy url) with query parameter name=JOBNAME.
You'll get 200 status code if the creation is successful, or 4xx/5xx code if it fails. config.xml is the format Hudson uses to store the job in the file system, so you can see examples of them in /var/lib/hudson.
I have tried the code as mentioned in the site:"http://wiki.hudson-ci.org/display/HUDSON/Authenticating+scripted+clients"
There also they have used the createItem directly.
Can you please explain briefly,so that it can be useful for me.
Thanks.
[Updated on: Tue, 21 May 2013 13:25] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04661 seconds