summaryrefslogtreecommitdiff
path: root/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqGlobalConfig.java
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2014-05-04 23:34:16 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2014-05-04 23:34:16 +0200
commit5c762750101f12abd51621355a871e42fd9c7a33 (patch)
treea7dfd74f16199db618994a10cb33ac05b1a6ac17 /src/main/java/org/jenkinsci/plugins/activemq/ActiveMqGlobalConfig.java
parent345c0d8f7738aab20d2b45fd6c5ebf911b75e2fa (diff)
downloadactivemq-plugin-5c762750101f12abd51621355a871e42fd9c7a33.tar.gz
activemq-plugin-5c762750101f12abd51621355a871e42fd9c7a33.tar.bz2
activemq-plugin-5c762750101f12abd51621355a871e42fd9c7a33.tar.xz
activemq-plugin-5c762750101f12abd51621355a871e42fd9c7a33.zip
o Getting the web configuration to work.
Diffstat (limited to 'src/main/java/org/jenkinsci/plugins/activemq/ActiveMqGlobalConfig.java')
-rw-r--r--src/main/java/org/jenkinsci/plugins/activemq/ActiveMqGlobalConfig.java124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqGlobalConfig.java b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqGlobalConfig.java
new file mode 100644
index 0000000..4bc8066
--- /dev/null
+++ b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqGlobalConfig.java
@@ -0,0 +1,124 @@
+package org.jenkinsci.plugins.activemq;
+
+import hudson.Extension;
+import hudson.util.FormValidation;
+import jenkins.model.GlobalConfiguration;
+import jenkins.model.Jenkins;
+import net.sf.json.JSONObject;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.kohsuke.stapler.QueryParameter;
+import org.kohsuke.stapler.StaplerRequest;
+import org.slf4j.Logger;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+@Extension
+public class ActiveMqGlobalConfig extends GlobalConfiguration {
+ private static final Logger log = getLogger(ActiveMqPlugin.class);
+
+ private String brokerUrl;
+ private boolean enable;
+
+ public ActiveMqGlobalConfig() {
+ log.info("ActiveMqGlobalConfig.ActiveMqGlobalConfig");
+ load();
+ log.info("this = " + this);
+ }
+
+ public String getUrl() {
+ log.info("ActiveMqGlobalConfig.getUrl");
+ return brokerUrl;
+ }
+
+ public void setUrl(String url) {
+ log.info("ActiveMqGlobalConfig.setUrl");
+ log.info("url = " + url);
+ this.brokerUrl = url;
+ }
+
+ public FormValidation doCheckUrl(@QueryParameter String value) {
+ log.info("ActiveMqGlobalConfig.doCheckUrl");
+ return doCheckBrokerUrl(value);
+ }
+
+ public String getBrokerUrl() {
+ log.info("ActiveMqGlobalConfig.getBrokerUrl");
+ return brokerUrl;
+ }
+
+ public void setBrokerUrl(String brokerUrl) {
+ log.info("ActiveMqGlobalConfig.setBrokerUrl");
+ this.brokerUrl = brokerUrl;
+ save();
+ }
+
+ public FormValidation doCheckBrokerUrl(@QueryParameter String value) {
+ log.info("ActiveMqPlugin.doCheckUrl");
+ log.info("value = " + value);
+
+ value = value.trim();
+
+ if (value.isEmpty()) {
+ return FormValidation.ok();
+ }
+
+ ActiveMQConnectionFactory connectionFactory;
+
+ try {
+ URI uri = new URI(value);
+ connectionFactory = new ActiveMQConnectionFactory(uri);
+ } catch (URISyntaxException e) {
+ return FormValidation.error("Invalid URI: " + e.getMessage());
+ }
+
+ Connection connection;
+ try {
+ connection = connectionFactory.createConnection();
+ } catch (JMSException e) {
+ return FormValidation.warning("Unable to connect to broker");
+ }
+
+ try {
+ connection.close();
+ } catch (JMSException ignore) {
+ }
+
+ return FormValidation.ok("Successfully connected to broker");
+ }
+
+ public boolean isEnable() {
+ log.info("ActiveMqGlobalConfig.isEnable");
+ return enable;
+ }
+
+ public void setEnable(boolean enable) {
+ log.info("ActiveMqGlobalConfig.setEnable");
+ this.enable = enable;
+ save();
+ }
+
+ @Override
+ public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
+ log.info("ActiveMqGlobalConfig.configure");
+ req.bindJSON(this, json);
+
+ ActiveMqPlugin plugin = Jenkins.getInstance().getPlugin(ActiveMqPlugin.class);
+
+ plugin.reconfigure();
+
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "ActiveMqGlobalConfig{" +
+ ", brokerUrl='" + brokerUrl + '\'' +
+ ", enable=" + enable +
+ "} " + super.toString();
+ }
+}