mehandih / grails-jaxrs

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

ConverterUtils.jsonToMap() not able to handle 'simple' JSON Object #72

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Send 'simple', one-dimensional JSON object via RestBuilder class (taken from 
Grails REST Client Builder Plugin 
[http://grails.org/plugin/rest-client-builder]). For example:

<code>
// create JSONObject
def jObj = new JSONObject()
jObj.put('id', 'theId')
jObj.put('name', 'yourNameHere')

// try to send it as parameter
</code>

2. Retrieve the following ERROR message:

3.

What is the expected output?
----------------------------
I expect the method to take the parameter(s) and process them correctly, as it 
will send a JSON Response and - sarcastically - the response IS a 
one-dimensional Array...

What do you see instead?
------------------------
ERROR container.ContainerResponse  - The RuntimeException could not be mapped 
to a response, re-throwing to the HTTP container
Message: Cannot cast object 'jsonRequestId' with class 'java.lang.String' to 
class 'java.util.Map'

... which leads to ConverterUtils.jsonToMap()

What version of the product are you using? 
------------------------------------------
Plugin Version:    0.6
Grails Version:    2.2.0

On what operating system?
-------------------------
Windows 7 64bit

Please provide any additional information below.
------------------------------------------------
It seems that it happens within the ConverterUtils.jsonToMap() function, 
precisely at line 100:
<code>
params.iterator().next().value
</code>

'params' is a valid GrailsParameterMap object which contains my two values 'id' 
and 'name' - as I've seen through debugging ...

----
However, it DOES WORK if I provide an at least two-dimensional structure. For 
example:

<code>
// create JSONObject
def jObj = new JSONObject()
jObj.put('id', 'theId')
jObj.put('name', 'yourNameHere')

// create a container JSONObject
def jContainer = new JSONObject()
jContainer.put('param', jObj)

//try to send it as parameter
</code>

this will result in a proper processing and I will retrieve the expected 
response message from the server ;)

Original issue reported on code.google.com by h.romi...@gmail.com on 13 Feb 2013 at 10:53

GoogleCodeExporter commented 8 years ago

Original comment by n...@10ne.org on 14 Feb 2013 at 6:19

GoogleCodeExporter commented 8 years ago
I've committed a fix at rev. cb818df843893bc6fd0ebbd9000ae120164902a9.
Care to try it out?

Original comment by n...@10ne.org on 17 Feb 2013 at 1:26

GoogleCodeExporter commented 8 years ago
thanks a lot - I'll definitely try it out! sadly, I can do this tomorrow at the 
earliest - but I'll try it out and return with my experiences as soon as 
possible! promised :)

Original comment by h.romi...@gmail.com on 18 Feb 2013 at 10:12

GoogleCodeExporter commented 8 years ago
hey,
I tried it out but I ran into several errors on startup. so, just to clarify my 
situation I will write down the steps I've tried so far:

1st approach:
-------------
# clone git repository
# open source with Intellij and create a valid Intellij project
# clean and compile the plugin ('grails clean' followed by 'grails compile')
# package the plugin ('grails package-plugin'), creates a grails-jaxrs-0.7.zip 
file
# create a new Intellij Grails project (with latest Grails version: 2.2.0)
# install plugin from file via ('grails install-plugin c:\path\to\file.zip')
# create a new resource ('grails create-resource my.package.MyResource')
# try to compile the new project with 'grails compile'

2nd approach: 
-------------
# create a new Intellij Grails project (with latest Grails version: 2.2.0)
# declare plugin in 'BuildConfig.groovy' file 
<code>
grails.project.dependency.resolution = {
  plugins {
    compile ':jaxrs:0.7'
  }
}
</code>
# clean the project with 'grails clean'
# compile the project with 'grails compile'

with both approaches I ran into an compilation error (more precisely 93 
errors). I attached the console output as a file below...

Original comment by h.romi...@gmail.com on 19 Feb 2013 at 9:29

Attachments:

GoogleCodeExporter commented 8 years ago
Have you tried running the 'refresh-dependencies' goal?

Original comment by n...@10ne.org on 19 Feb 2013 at 12:31

GoogleCodeExporter commented 8 years ago
yes, I did. forgot to mention it earlier but it gives me the same errors as in 
the log I attached to the previous message. tried it again just this very 
moment and it's the same result.

Original comment by h.romi...@gmail.com on 19 Feb 2013 at 12:47

GoogleCodeExporter commented 8 years ago
Curious, I can't reproduce it; I'll have to give it another go a little later

Original comment by n...@10ne.org on 19 Feb 2013 at 12:49

GoogleCodeExporter commented 8 years ago
Really strange... hmmm... here's my BuildConfig.groovy file if it's any help 
for you...

Original comment by h.romi...@gmail.com on 19 Feb 2013 at 12:59

Attachments:

GoogleCodeExporter commented 8 years ago
Does it make any difference if you install the plugin via code?
That is, instead of re-packing and installing, add the reference of the 
checkout directory to the build config file :

grails.plugin.location.'jaxrs' = '../grails-jaxrs'

Original comment by n...@10ne.org on 21 Feb 2013 at 12:18

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
sorry for not responding for a while, but I was very busy doing other work here 
at office as well. I tried it as you suggested and added a reference to my 
BuildConfig.groovy file for the jaxrs plugin but it didn't make any difference 
(I tried this on a clean project).

so, I moved on and just wrapped all my JSON objects I send to the RESTful Web 
API within a JSON container object. this runs fine if I run the app via 'grails 
run-app'. however, if I run the app via 'grails run-war', or if I deploy the 
generated WAR I see the a lot of errors, resulting in these lines as last 
listed cause:
<code>
Caused by: java.lang.NoClassDefFoundError: 
org/grails/jaxrs/support/RequestStreamAdapter
    at org.grails.jaxrs.support.ConverterUtils.jsonToMap(ConverterUtils.groovy:94) ~[ConverterUtils.class:na]
</code>

am I missing something? I guess it's not a matter of missing libraries as it is 
running like a charm when started via 'grails run-app' ...

Original comment by h.romi...@gmail.com on 14 Mar 2013 at 7:55

GoogleCodeExporter commented 8 years ago
I'll try to reproduce it again, but it seems fine.
Perhaps someone else can chime in and try it out.

Original comment by n...@10ne.org on 19 Mar 2013 at 10:59

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi,

I am also facing this problem. I've passed all the steps described above, and 
the only compilation error that I'm getting is:

jaxrs-0.7\src\groovy\org\grails\jaxrs\itest\IntegrationTestSpec.groovy: 5: 
unable to resolve class spock.lang.Shared
 @ line 5, column 1.
   import spock.lang.Shared
   ^

jaxrs-0.7\src\groovy\org\grails\jaxrs\itest\IntegrationTestSpec.groovy: 3: 
unable to resolve class grails.plugin.spock.IntegrationSpec
 @ line 3, column 1.
   import grails.plugin.spock.IntegrationSpec
   ^

jaxrs-0.7\src\groovy\org\grails\jaxrs\itest\IntegrationTestSpec.groovy: 12: 
unable to resolve class grails.plugin.spock.IntegrationSpec 
 @ line 12, column 1.
   abstract class IntegrationTestSpec extends IntegrationSpec implements JaxRsIntegrationTest {
   ^

jaxrs-0.7\src\groovy\org\grails\jaxrs\itest\IntegrationTestSpec.groovy: 16: 
unable to resolve class spock.lang.Shared ,  unable to find class for annotation
 @ line 16, column 5.
       @Shared
       ^

jaxrs-0.7\src\groovy\org\grails\jaxrs\itest\IntegrationTestSpec.groovy: 19: 
unable to resolve class spock.lang.Shared ,  unable to find class for annotation
 @ line 19, column 5.
       @Shared
       ^

In spock-0.7 grails plugin page it is said, that if using Grails 2.2, then the 
following lines should be added:

grails.project.dependency.resolution = {
  repositories {
    grailsCentral()
    mavenCentral()
  }
  dependencies {
    test "org.spockframework:spock-grails-support:0.7-groovy-2.0" //<-- this one
  }
  plugins {
    test(":spock:0.7") {
      exclude "spock-grails-support"  // <---- this one
    }
  }
}

I've added these lines to my application's BuildConfig.groovy and after 
packaging the new version of plugin and adding it to app, app is deployed 
properly, as well as the one dimensional Array JSON is recognized and processed 
properly.

Hope my feedback will help.

Regards,
Anna.

Original comment by anna.mnkyn@gmail.com on 22 Mar 2013 at 5:42

GoogleCodeExporter commented 8 years ago
OK, I've been able to reproduce h.romirer's error with a fresh 2.2.0 project, 
and it looks as though it doesn't occur with 2.1.x.

@Anna - Thanks for the feedback; are you experiencing these errors using a self 
compiled version, or the 0.7 version that's distributed through the plugin 
portal?

Original comment by n...@10ne.org on 24 Mar 2013 at 8:25

GoogleCodeExporter commented 8 years ago
I'm using Grails version: 2.2.1, JDK 7, and getting the following error while 
using the test resource described on the guide:

mdesales@mdesales-desktop-vm:~/dev/tap-grails$ grails run-app
| Running Grails application
| Error 2013-04-23 09:26:15,593 [localhost-startStop-1] ERROR 
application.RootResourceUriRules  - The ResourceConfig instance does not 
contain any root resource classes.
| Error 2013-04-23 09:26:15,597 [localhost-startStop-1] ERROR 
servlet.SpringServlet  - Exception occurred when intialization
Message: The ResourceConfig instance does not contain any root resource classes.
    Line | Method
->>   99 | <init>             in 
com.sun.jersey.server.impl.application.RootResourceUriRules
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1300 | _initiate          in 
com.sun.jersey.server.impl.application.WebApplicationImpl
|    163 | access$700 . . . . in     ''
|    769 | f                  in 
com.sun.jersey.server.impl.application.WebApplicationImpl$13
|    765 | f . . . . . . . .  in     ''
|    193 | processWithErrors  in com.sun.jersey.spi.inject.Errors
|    765 | initiate . . . . . in 
com.sun.jersey.server.impl.application.WebApplicationImpl
|    117 | initiate           in 
com.sun.jersey.spi.spring.container.servlet.SpringServlet
|    319 | initiate . . . . . in 
com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent
|    609 | load               in 
com.sun.jersey.spi.container.servlet.WebComponent
|    210 | init . . . . . . . in     ''
|    374 | init               in 
com.sun.jersey.spi.container.servlet.ServletContainer
|    557 | init . . . . . . . in     ''
|     51 | init               in org.grails.jaxrs.web.JerseyServlet
|    174 | init . . . . . . . in org.grails.jaxrs.web.JaxrsContext
|    164 | init               in     ''
|     45 | contextInitialized in org.grails.jaxrs.web.JaxrsListener
|    334 | innerRun           in java.util.concurrent.FutureTask$Sync
|    166 | run . . . . . . .  in java.util.concurrent.FutureTask
|   1145 | runWorker          in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run                in java.lang.Thread
| Error 2013-04-23 09:26:15,635 [localhost-startStop-1] ERROR 
[localhost].[/tap-grails]  - Exception sending context initialized event to 
listener instance of class org.grails.jaxrs.web.JaxrsListener
Message: The ResourceConfig instance does not contain any root resource classes.
    Line | Method
->>   99 | <init>             in 
com.sun.jersey.server.impl.application.RootResourceUriRules
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1300 | _initiate          in 
com.sun.jersey.server.impl.application.WebApplicationImpl
|    163 | access$700 . . . . in     ''
|    769 | f                  in 
com.sun.jersey.server.impl.application.WebApplicationImpl$13
|    765 | f . . . . . . . .  in     ''
|    193 | processWithErrors  in com.sun.jersey.spi.inject.Errors
|    765 | initiate . . . . . in 
com.sun.jersey.server.impl.application.WebApplicationImpl
|    117 | initiate           in 
com.sun.jersey.spi.spring.container.servlet.SpringServlet
|    319 | initiate . . . . . in 
com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent
|    609 | load               in 
com.sun.jersey.spi.container.servlet.WebComponent
|    210 | init . . . . . . . in     ''
|    374 | init               in 
com.sun.jersey.spi.container.servlet.ServletContainer
|    557 | init . . . . . . . in     ''
|     51 | init               in org.grails.jaxrs.web.JerseyServlet
|    174 | init . . . . . . . in org.grails.jaxrs.web.JaxrsContext
|    164 | init               in     ''
|     45 | contextInitialized in org.grails.jaxrs.web.JaxrsListener
|    334 | innerRun           in java.util.concurrent.FutureTask$Sync
|    166 | run . . . . . . .  in java.util.concurrent.FutureTask
|   1145 | runWorker          in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run                in java.lang.Thread
| Error 2013-04-23 09:26:15,640 [localhost-startStop-1] ERROR 
core.StandardContext  - Error listenerStart
| Error 2013-04-23 09:26:15,646 [localhost-startStop-1] ERROR 
core.StandardContext  - Context [/tap-grails] startup failed due to previous 
errors
| Server running. Browse to http://localhost:8080/tap-grails

Please help!

Original comment by marcellodesales on 23 Apr 2013 at 4:29

GoogleCodeExporter commented 8 years ago
Have you applied the fix described in comment #14?

Original comment by n...@10ne.org on 23 Apr 2013 at 6:30

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I actually got it running by running "grails clean" after installing the 
plugin! Thanks a lot!

Original comment by marcellodesales on 24 Apr 2013 at 1:51

GoogleCodeExporter commented 8 years ago

Original comment by n...@10ne.org on 25 Apr 2013 at 7:10