Discussion:
[groovy-dev] Re: Making POST requests via groovy-wslite
jwagenleitner
2012-12-04 16:38:06 UTC
Permalink
In your closure, instead of using `text` try using `urlenc` instead.

... {
type: ContentType.URLENC
urlenc cs:'12345,23456,34567'
}
I'm trying to use groovy-wslite to do some queries via the Atlassian
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,
/rest-service-fe/search-v1/reviewsForChangesets/{repo}
http://docs.atlassian.com/fisheye-crucible/latest/wadl/fisheye.html#d2e385
@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' } }
Caused by: java.io.IOException: Server returned HTTP response code: 500
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?
--
View this message in context: http://groovy.329449.n5.nabble.com/Making-POST-requests-via-groovy-wslite-tp5712059p5712062.html
Sent from the groovy - dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
jwagenleitner
2012-12-04 16:39:40 UTC
Permalink
There was a typo in my reply, type should not be followed by a colon.
Example should be:

... {
type ContentType.URLENC
urlenc cs:'12345,23456,34567'
}
Post by jwagenleitner
In your closure, instead of using `text` try using `urlenc` instead.
... {
type: ContentType.URLENC
urlenc cs:'12345,23456,34567'
}
I'm trying to use groovy-wslite to do some queries via the Atlassian
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,
/rest-service-fe/search-v1/reviewsForChangesets/{repo}
http://docs.atlassian.com/fisheye-crucible/latest/wadl/fisheye.html#d2e385
@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' } }
Caused by: java.io.IOException: Server returned HTTP response code: 500
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?
--
View this message in context: http://groovy.329449.n5.nabble.com/Making-POST-requests-via-groovy-wslite-tp5712059p5712063.html
Sent from the groovy - dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
rserranon
2014-02-27 00:52:24 UTC
Permalink
wslite is a Great plugin!

I have the same question:

I am getting a wslite.rest.RESTClientException: 400 Bad Request, I haven't
figured out how to sen de JSON on the request.

The service is working since I have been able to create the record using
CocoaRestClient with the following:

URL: https://frutalia.myshopify.com/admin/customers.json
Headers:
Accept-Language: en-us
Content-Type: aplication/json
Accept: */*
Accept-Encoding: gzip, deflate

Here is what I have been attempting to test in Gralis console unsuccessfully
for a couple of days:

import wslite.http.auth.*
import wslite.rest.*
import groovy.json.*

def builder = new JsonBuilder()

def root = builder.customer {
first_name "Pedro"
mail "me-***@public.gmane.org"
}

println "root: "+ root

println "builder: " + builder

println "pretty: " + builder.toPrettyString()

def client = new RESTClient("https://frutalia.myshopify.com")
client.authorization = new HTTPBasicAuthorization("key", "passcode")
def response = client.post(path: "/admin/customers.json",
headers:["Accept-Language":"en-us",
"Content-Type":"application/json; charset=utf-8",
"Accept":"aplication/json; charset=utf-8",
"Accept-Encoding":"gzip, deflate"]) {
type "text/json"
builder.toPrettyString()
}

Can you provide an example on how to do this POST request and more detail on
how to send the JSON?

I would really would appreciate some help to help me move froward.

Thanks!

Roberto



--
View this message in context: http://groovy.329449.n5.nabble.com/Making-POST-requests-via-groovy-wslite-tp5712059p5718605.html
Sent from the groovy - dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Loading...