alvarosanchez / restful-grails-springsecurity-greach2014

Companion code for my talk "Creating RESTful API’s with Grails and Spring Security"
http://greach.es/speakers/alvaro-sanchez-mariscal-creating-restful-apis-with-grails-and-spring-security/
12 stars 11 forks source link

Problems running this example #1

Open thomashoelzl opened 9 years ago

thomashoelzl commented 9 years ago

Hi Alvarao!

I wanted to try your example from greach2014. I downloaded it. Started it with STS without any problems. I was hoping to be able to authenticate with curl:

C:\Users\atw1t1r5>curl -i -H "Content-Type: application/json" -X POST -d '{"username":"jimi","password":"jimispassword"}' http://localhost:8080/restful-grails-springsecurity-greach2014/api/login HTTP/1.1 400 Bad Request Server: Apache-Coyote/1.1 Content-Length: 0 Date: Sat, 16 May 2015 18:51:40 GMT

But I got a 400 Bad Request. I didn't change anything. Did I use the curl command wrong. I would be great if you could give me a hint.

Thanks a lot.

Thomas

alvarosanchez commented 9 years ago

I have just typed the same curl request and it works:

$ curl -i -H "Content-Type: application/json" -X POST -d '{"username":"jimi","password":"jimispassword"}' http://localhost:8080/restful-grails-springsecurity-greach2014/api/login
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Cache-Control: no-store
Pragma: no-cache
Set-Cookie: JSESSIONID=4E9C303A2B037C7AE098E7975C4ABD08; Path=/restful-grails-springsecurity-greach2014/; HttpOnly
Content-Type: application/json;charset=UTF-8
Content-Length: 126
Date: Tue, 19 May 2015 08:29:37 GMT

{"username":"jimi","roles":["ROLE_ADMIN","ROLE_USER"],"token_type":"Bearer","access_token":"ds7kbdr4bn0nrtnpntc397rjegcv71rp"}
norricorp commented 8 years ago

yes, using curl works fine. I downloaded the code and run ex02 and that does work in a browser so I will look for differences in the code and report back.

norricorp commented 8 years ago

I did find some differences in the code - dumb typos on my part. But I am left with an error from the server ERROR org.grails.web.errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [GET] /todos Stacktrace follows: java.lang.reflect.InvocationTargetException: null at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: grails.views.ViewRenderException: Error rendering view: BUG! exception in phase 'instruction selection' in source unit 'todo_todo__todo_gson' unexpected NullpointerException

Looking at views/todo/_todo.gson I have the same as your example code. So no idea what is happening.

norricorp commented 8 years ago

and having restarted app again, it now works. I did change logging but that would not have made a difference. So issue closed.