1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.ci.comm.hudson.command;
17
18 import java.io.IOException;
19
20 import org.apache.commons.httpclient.HttpException;
21 import org.apache.commons.httpclient.methods.PostMethod;
22 import org.apache.commons.httpclient.methods.StringRequestEntity;
23
24 import de.smartics.ci.comm.CiSystem;
25 import de.smartics.ci.comm.command.CommandException;
26 import de.smartics.ci.comm.command.InvalidRequestException;
27 import de.smartics.ci.comm.command.AbstractUpdateJobCommand;
28
29
30
31
32 public final class HudsonUpdateJobCommand extends
33 AbstractUpdateJobCommand<HudsonUpdateJobCommand>
34 {
35
36
37
38
39
40
41
42 private String configString;
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 public HudsonUpdateJobCommand(final String jobName, final String configString)
58 {
59 super(jobName);
60 this.configString = configString;
61 }
62
63
64
65
66 public HudsonUpdateJobCommand()
67 {
68 this(null, null);
69 }
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 public void setConfigString(final String configString)
86 {
87 this.configString = configString;
88 }
89
90
91
92 @Override
93 public void execute(final CiSystem target) throws CommandException
94 {
95 try
96 {
97 updateTheJob(target, jobName, configString);
98 }
99 catch (final Exception e)
100 {
101 throw new CommandException("Updating of job " + jobName + " failed.", e);
102 }
103 }
104
105 private void updateTheJob(final CiSystem target, final String jobName,
106 final String configString) throws HttpException, IOException,
107 InvalidRequestException, CommandException
108 {
109 final String apiUrl =
110 buildCiJobApiUrl(target.getUrl(), jobName, "config.xml");
111 final PostMethod method = new PostMethod(apiUrl);
112 final StringRequestEntity req =
113 new StringRequestEntity(configString, "text/plain", "UTF-8");
114 method.setRequestEntity(req);
115 addRequestHeaders(method);
116 final int statusCode = target.execute(method);
117 checkResult(statusCode);
118 }
119
120
121
122 }