groovy - 404 while trying to use a JIRA Scriptrunner custom REST endpoint -


i trying add custom jira rest endpoint script runner.

the rest endpoint needs set user properties: list of users provided, , each user list of user properties.

this script have cobbled far:

import com.atlassian.jira.component.componentaccessor import com.atlassian.jira.bc.user.search.usersearchservice import com.atlassian.sal.api.user.usermanager import com.onresolve.scriptrunner.runner.rest.common.customendpointdelegate  import groovy.json.jsonbuilder import groovy.json.jsonslurper import groovy.transform.basescript  import javax.servlet.http.httpservletrequest import javax.ws.rs.core.multivaluedmap import javax.ws.rs.core.response  @basescript customendpointdelegate delegate  setuserproperties(httpmethod: "post", groups: ["jira-administrators"]) { multivaluedmap queryparams, string body, httpservletrequest request ->    def userpropertymanager = componentaccessor.getuserpropertymanager()   def usermanager = componentaccessor.getusermanager()   def usersearchservice = componentaccessor.getcomponent(usersearchservice.class)    def json = new jsonslurper().parsetext(body)   def propertycount = 0   def customerlist = new arraylist<>()   json.each {     acustomer ->       def user = usermanager.getuserbyname(acustomer.name.tostring())       acustomer.properties.each {         aproperty ->           userpropertymanager.getpropertyset(user).setstring("jira.meta." + aproperty.key.tostring(), aproperty.value.tostring())           propertycount++       }       customerlist.add(user)   }    def response = new arraylist<>()   response.add( new jsonslurper().parsetext('{ "properties_changed": ' + propertycount + ' }') )   response.add( customerlist )    return response.ok( new jsonbuilder(response).toprettystring() ).build(); } 

the inline script editor complains line: def user = usermanager.getuserbyname(acustomer.name.tostring()), more precisely there wavy red line under acustomer.name , error is

[static type checking] - no such property: name class: java.lang.object  @ line 28, column 44. 

edit: according @glennv's answer, not important , can ignored.

a previous (working) iteration of script, running on server, used email addresses, see how user email in jira script runner. but, stated above, i'm not getting users email address username.

this userprops.json file use test:

[   {     "name": "felicity.smoak",     "email": "felicity.smoak@queenconsolidated.com",     "properties": {       "company": "queen consolidated",       "foo": "bar"     }   },   {     "name": "johnny.cash",     "email": "johnny.cash@nashville.com",     "properties": {       "company": "nashville",       "nickname": "the man in black"     }   } ] 

i test curl command:

curl -x post \     -i \     -h "x-atlassian-token: nocheck" \     -h "content-type: text/json" \     --data "@userprops.json" \     -u "$jira_user":"$jira_password" \     http://"$jira_server"/rest/scriptrunner/latest/custom/setuserproperties 

$jira_user, $jira_password , $jira_server placeholders use anonymize stack overflow. actual values correct.

this output:

http/1.1 404 not found server: nginx date: wed, 07 sep 2016 14:55:38 gmt content-type: application/json;charset=utf-8 content-length: 0 connection: keep-alive x-arequestid: 0123456789 x-asen: sen-123456789 set-cookie: jsessionid=1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f; path=/; secure; httponly x-seraph-loginreason: ok set-cookie: atlassian.xsrf.token=abcd-efgh-ijkl-mnop|abcdef0123456789abcdef0123456789abcdef0123456789|lin; path=/; secure x-asessionid: xyz123 x-ausername: amedee.vangasse cache-control: no-cache, no-store, no-transform x-content-type-options: nosniff 

so it's not finding rest endpoint should find according scriptrunner documentation.

if use url know wrong, expected "oops, you've found dead link." error page. correct url 404 + no other output.

also, when add dosomething sample , try that, 404 , content length of 0. doing on other wrong url gives me 404 , content length of few kib.

the -dplugin.script.roots= parameter not defined in setenv.sh, nor should be, because script inline. setting script roots required scripts on filesystem, , scripts outside of default scripts directory, described in scriptrunner documentation.

also asked on atlassian answers.

edit: moved customerlist.add(user) 1 line down suggested glenn, , got error in atlassian-jira.log:

2016-09-09 11:01:43,683 http-nio-8086-exec-23 error amedee.vangasse 661x42160x1 qq01uq 213.224.9.178,127.0.0.1 /rest/scriptrunner/latest/custom/customadmin/com.onresolve.scriptrunner.canned.common.rest.customrestendpoint [c.a.p.r.c.error.jersey.throwableexceptionmapper] uncaught exception thrown rest service: cannot property 'name' on null object java.lang.nullpointerexception: cannot property 'name' on null object         @ org.codehaus.groovy.runtime.nullobject.getproperty(nullobject.java:60)         @ org.codehaus.groovy.runtime.invokerhelper.getproperty(invokerhelper.java:172)         @ org.codehaus.groovy.runtime.callsite.nullcallsite.getproperty(nullcallsite.java:47)         @ org.codehaus.groovy.runtime.callsite.abstractcallsite.callgetproperty(abstractcallsite.java:296)         @ com.onresolve.scriptrunner.runner.restendpointmanager$_onfullsystemstart_closure5.docall(restendpointmanager.groovy:141)         ... 3 filtered         @ java.lang.reflect.method.invoke(method.java:497)         @ org.codehaus.groovy.reflection.cachedmethod.invoke(cachedmethod.java:93)         @ groovy.lang.metamethod.domethodinvoke(metamethod.java:325)         @ org.codehaus.groovy.runtime.metaclass.closuremetaclass.invokemethod(closuremetaclass.java:294)         @ groovy.lang.metaclassimpl.invokemethod(metaclassimpl.java:1021)         @ groovy.lang.closure.call(closure.java:426)         @ groovy.lang.closure.call(closure.java:442)         @ org.codehaus.groovy.runtime.defaultgroovymethods.each(defaultgroovymethods.java:2030)         @ org.codehaus.groovy.runtime.defaultgroovymethods.each(defaultgroovymethods.java:2015)         @ org.codehaus.groovy.runtime.defaultgroovymethods.each(defaultgroovymethods.java:2056)         @ org.codehaus.groovy.runtime.dgm$162.invoke(unknown source)         @ org.codehaus.groovy.runtime.callsite.pojometamethodsite$pojometamethodsitenounwrapnocoerce.invoke(pojometamethodsite.java:274)         @ org.codehaus.groovy.runtime.callsite.pojometamethodsite.call(pojometamethodsite.java:56)         @ org.codehaus.groovy.runtime.callsite.callsitearray.defaultcall(callsitearray.java:48)         @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:113)         @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:125)         @ com.onresolve.scriptrunner.runner.restendpointmanager.onfullsystemstart(restendpointmanager.groovy:131)         @ com.onresolve.scriptrunner.runner.rest.common.usercustomscriptendpoint.refresh(usercustomscriptendpoint.groovy:364)         @ com.onresolve.scriptrunner.runner.rest.common.usercustomscriptendpoint.saveconfigureditems(usercustomscriptendpoint.groovy:359)         @ com.onresolve.scriptrunner.runner.rest.common.usercustomscriptendpoint.addlistener(usercustomscriptendpoint.groovy:127)         ... 3 filtered         @ java.lang.reflect.method.invoke(method.java:497)         @ com.sun.jersey.spi.container.javamethodinvokerfactory$1.invoke(javamethodinvokerfactory.java:60)         ... 13 filtered         @ com.atlassian.plugins.rest.module.restdelegatingservletfilter$jerseyosgiservletcontainer.dofilter(restdelegatingservletfilter.java:154)         ... 1 filtered         @ com.atlassian.plugins.rest.module.restdelegatingservletfilter.dofilter(restdelegatingservletfilter.java:68)         ... 86 filtered         @ com.atlassian.jira.security.jirasecurityfilter.dofilter(jirasecurityfilter.java:70)         ... 16 filtered         @ com.atlassian.plugins.rest.module.servlet.restseraphfilter.dofilter(restseraphfilter.java:37)         ... 73 filtered         @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142)         @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617)         @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61)         @ java.lang.thread.run(thread.java:745) 

it's not problem nginx proxy either, because when ssh server , curl on localhost, same 404.

script runner uses groovy's compilestatic provide hints compilation errors. works fine when sufficient type information available.

in code above however, json instance not contain type info elements contains, groovy (at compilation time) not know acustomer instance has name field, warns it. there nothing wrong code though, if send request rest resource, should work fine.

if request returns status code other 2xx, there else goes wrong.

regarding 404. means not found, either there's mistake in url send request to, or rest script not available script runner. check value of $jira_server first. if paste in browser, should load jira. if ok, i'd check if script runner aware of path needs scripts. -dplugin.script.roots= parameter defined in setenv.sh (or setenv.bat) ? more details available here.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -