I'm trying to use groovy-wslite to do some queries via the FishEye REST API. I'm an experienced Java programmer but a newbie to Groovy and groovy-wslite.
I've got GET requests working fine. I'm trying to do my first POST, specifically with the following call:
/rest-service-fe/search-v1/reviewsForChangesets/{repo}
The call is documented like here:
http://docs.atlassian.com/fisheye-crucible/latest/wadl/fisheye.html#d2e385
Here is the code I'm trying to use:
@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='0.7.1') import wslite.rest.* def client = new RESTClient('http://server:port/context') def response = client.post(path:'/rest-service-fe/search-v1/reviewsForChangesets/repo?userName=user&password=password') { type: ContentType.URLENC text { cs:'12345,23456,34567' } }
Running this code throws a 500 error from the server:
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://crucible:8060/context/rest-service-fe/search-v1/reviewsForChangesets/BBNMS-JBBOS?userName=user&password=pass at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at groovy.lang.MetaClassImpl$GetBeanMethodMetaProperty.getProperty(MetaClassImpl.java:3481) at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:61) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227) at wslite.http.HTTPClient.execute(HTTPClient.groovy:55)
I think my problem is knowing the correct way to write the closure that represents the body of the POST.
Can anyone set me straight? I know this is more of a groovy-wslite question than a Fisheye, but you guys will have the right context to give me the best answer.
Community moderators have prevented the ability to post new answers.
BTW, if you mentioned what the problem it might help...
If it accepts a list it should probably be: ['12345','23456',' 34567']
Also I don't think userName and password is right, if anything will work I believe it's os_username and os_password (works for jira and confluence anyway).
I haven't used wslite, I use httpbuilder, for post a request looks like:
def xml = http.request(Method.POST, ContentType.XML) { uri.path = "/fisheye/rest-service/reviews-v1" requestContentType = ContentType.XML body = { createReview { reviewData { allowReviewersToJoin('true') author { userName('uadmin') } creator { userName('uadmin') } description("some description") jiraIssueKey(pkey + '-3') moderator { userName('uadmin') } projectKey('CR-' + pkey) type('REVIEW') } } } } def permaId = xml.permaId.id
For auth I do it like this:
http.client.addRequestInterceptor(new BasicAdminRequestInterceptor()) class BasicAdminRequestInterceptor implements HttpRequestInterceptor { void process(HttpRequest httpRequest, HttpContext httpContext) { httpRequest.addHeader('Authorization', 'Basic ' + "jamie:mypassword".bytes.encodeBase64().toString()) } }
hth
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.