mehandih / grails-jaxrs

Automatically exported from code.google.com/p/grails-jaxrs
0 stars 0 forks source link

POST methode doesn't work #45

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.
create two domains:

package grest01
class Person {
  String firstName
  String lastName
  Book book
  static constraints = {
  }
  String toString() {
    lastName
  }
}

and 

package grest01
class Book {
  String title
  String year
  static constraints = {
  }
  String toString() {
    title
  }
}

2.
grails generate-resources grest01.Book
grails generate-resources grest01.Person
grails run-app

3.
create some entries in Book.

4.
Send POST methode to http://localhost:8080/grest01/api/person
with this message:

<person>
<book id="1"/>
<firstName>Lion</firstName>
<lastName>King</lastName>
</person>

What is the expected output? What do you see instead?

Expected is the above xml string as http response, 
and a new entry is created in the table person.

But this POST methode produce following error messages:

Error 500: Executing action [handle] of controller [JaxrsController] in plugin 
[jaxrs] caused exception: Cannot get property 'id' on null object
Servlet: grails
URI: /grest01/grails/jaxrs.dispatch
Exception Message: Cannot get property 'id' on null object
Caused by: Cannot get property 'id' on null object
Class: JaxrsController
At Line: [38]
Code Snippet:

And the stacktrace:
java.lang.NullPointerException: Cannot get property 'id' on null object

    at org.grails.jaxrs.response.Responses.created(Responses.groovy:47)

    at org.grails.jaxrs.response.Responses$created.callStatic(Unknown Source)

    at org.grails.jaxrs.response.Responses$created.callStatic(Unknown Source)

    at grest01.PersonCollectionResource.create(PersonCollectionResource.groovy:20)

    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:172)

    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)

    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:265)

    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)

    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)

    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:71)

    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:996)

    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:947)

    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:938)

    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:399)

    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:478)

    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:663)

    at org.grails.jaxrs.web.JaxrsContext$JaxrsServiceImpl.process(JaxrsContext.java:150)

    at org.grails.jaxrs.web.JaxrsService$process.call(Unknown Source)

    at JaxrsController$_closure1.doCall(JaxrsController.groovy:38)

    at JaxrsController$_closure1.doCall(JaxrsController.groovy)

    at org.grails.jaxrs.web.JaxrsFilter.doFilterInternal(JaxrsFilter.java:46)

    at java.lang.Thread.run(Thread.java:619)

What version of the product are you using? On what operating system?
grails 1.3.7, jaxrs plugin version 0.4, windows/mac os, jdk 1.6

Please provide any additional information below.

Original issue reported on code.google.com by cahya.wi...@gmail.com on 15 Aug 2011 at 4:23

GoogleCodeExporter commented 8 years ago
I'll try to reproduce when I'm back from vacation (in about 10 days). Can you 
also please try to use version 0.5-m1 and/or the latest development version. 
Thanks, Martin

Original comment by krass...@googlemail.com on 16 Aug 2011 at 7:37

GoogleCodeExporter commented 8 years ago
Hi Martin,
Thanks for the response from your vacation :) 
I have also tested the version 0.5 (I have cloned it from git), but it has 
the same problem. 
So, have a nice holiday.
Cahya.

Original comment by cahya.wi...@gmail.com on 16 Aug 2011 at 8:02

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I just remember about an old problem in grails/hibernate and its workaround.
I changed the generated @POST code in PersonCollectionResource.groovy from

    @POST
    Response create(Person dto) {
        created dto.save()
    }

to

    @POST
    Response create(Person dto) {
        dto.merge()
        created dto.save()
    }

and it works :).

Original comment by cahya.wi...@gmail.com on 16 Aug 2011 at 9:02

GoogleCodeExporter commented 8 years ago
I updated http://jira.grails.org/browse/GRAILS-6459 because it is the cause for 
this issue. I'll also evaluate your workaround in context of other reprorted 
issues and in context of deep xml/json to domain-object binding. 

Original comment by krass...@googlemail.com on 27 Aug 2011 at 10:19

GoogleCodeExporter commented 8 years ago

Original comment by krass...@googlemail.com on 28 Aug 2011 at 6:31

GoogleCodeExporter commented 8 years ago

Original comment by krass...@googlemail.com on 28 Aug 2011 at 9:33

GoogleCodeExporter commented 8 years ago
Fix now in master 
(https://github.com/krasserm/grails-jaxrs/commit/955c77be0ba17fd2ba5e75028e9a0be
6f63a265b). This is a (temporary) workaround for 
http://jira.grails.org/browse/GRAILS-6459. 

Original comment by krass...@googlemail.com on 30 Aug 2011 at 9:17