configure method - JSONObject element not found

35 views
Skip to first unread message

Jimmy Ray

unread,
Sep 22, 2016, 5:35:37 PM9/22/16
to Jenkins Developers
I am trying to add global settings for my plugin.  I think I have the form jelly correct, as the form loads.  When I fill out data in the global settings and try to save, I get the following error:

javax.servlet.ServletException: net.sf.json.JSONException: JSONObject["consulHostUrl"] not found.

The configure method is here:

        @Override
        public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
            LOGGER.warning(formData.toString());

            consulHostUrl = formData.getString("consulHostUrl");  //errors here

            req.bindJSON(this, formData);
            save();
            return super.configure(req, formData);
        }


And, before the error, I log the formData object, and I see:

{"consul-kv-builder":{"consulHostUrl":"http://localhost:8500","consulAclToken":"","consulApiUri":"","consulTimeoutConnection":"","consulTimeoutResponse":"","consulTestUri":"","consulTestResponseCode":""}}

The global.jelly is:

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:section title="Global Consul Settings" name="consul-kv-builder">
    <f:entry title="Host URL" help="help-hostUrl.html">
        <f:textbox field="consulHostUrl" name="consulHostUrl" />
    </f:entry>
    <f:entry title="ACL Token" help="help-token.html">
        <f:textbox field="consulAclToken" name="consulAclToken" value="" />
    </f:entry>
    <f:entry title="API URI (/v1/kv/)" help="help-urlOverride.html">
        <f:textbox field="consulApiUri" name="consulApiUri" />
    </f:entry>
    <f:entry title="Connection Timeout (10000)" help="help-timeoutConnection.html">
        <f:textbox field="consulTimeoutConnection" name="consulTimeoutConnection" />
    </f:entry>
    <f:entry title="Response Timeout (30000)" help="help-timeoutResponse.html">
        <f:textbox field="consulTimeoutResponse" name="consulTimeoutResponse" />
    </f:entry>
    <f:entry title="Test URI (/status/leader)" help="help-testUri.html">
        <f:textbox field="consulTestUri" name="consulTestUri" />
    </f:entry>
    <f:entry title="Test Response Code (200)" help="help-testResponseCode.html">
        <f:textbox field="consulTestResponseCode" name="consulTestResponseCode" />
    </f:entry>
    <f:validateButton
        title="${%Test Connection}" progress="${%Testing...}"
        method="testConnection" with="consulHostUrl,consulTestUri,consulTestResponseCode" />
  </f:section>
</j:jelly>

And the Test Connection works as well.

I know I am doing something stupid, but I just haven't stumbled on it yet.

Gavin Mogan

unread,
Sep 23, 2016, 2:54:13 AM9/23/16
to Jenkins Developers
Looks like it's a sub object of consul-kv-builder

Try getObject("consul-kv-builder").getString

Note I'm on my phone so the get object call could be something else.

Robert Sandell

unread,
Sep 23, 2016, 5:09:46 AM9/23/16
to jenkin...@googlegroups.com
global.jelly is a bit cumbersome to use with the standard form binding, and is somewhat considered deprecated imho.
Look into using GlobalConfiguration instead.

/B


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/aa85faaa-fa10-4ac2-9fd3-1d22a4f57cde%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Robert Sandell
Software Engineer
CloudBees Inc.

Jimmy Ray

unread,
Sep 23, 2016, 11:20:44 AM9/23/16
to Jenkins Developers
Yep, that was it.

Thanks!

Jimmy Ray

unread,
Sep 23, 2016, 11:21:08 AM9/23/16
to Jenkins Developers
Yep, I am now gonna look into that approach.

Thanks!

Jimmy Ray

unread,
Sep 27, 2016, 3:38:01 PM9/27/16
to Jenkins Developers
Is there a published Event Model for job configuration changes.  I am trying to see when the configure() method is called in the Builder Descriptor.

-Jimmy
Reply all
Reply to author
Forward
0 new messages