users@jersey.java.net

RE: [Jersey] RE: Testing resource class + data in request

From: Rob - <skyscrapper666_at_hotmail.com>
Date: Tue, 10 Nov 2009 10:54:42 +1030

Interestingly, I changed

 

MyBean myBean = this.webResource.path("one/two").accept(MediaType.APPLICATION_JSON)
    .post(MyBean.class, new GenericEntity<List<ObjOne>>(objList){});

 

to be

 

MyBean myBean = this.webResource.path("one/two").type(MediaType.APPLICATION_JSON)
    .post(MyBean.class, new GenericEntity<List<ObjOne>>(objList){});

 

and it worked.

 

So I guess "accept" works on the server whereas "type" work on the actual request?
 


From: skyscrapper666_at_hotmail.com
To: users_at_jersey.dev.java.net
Date: Tue, 10 Nov 2009 10:16:49 +1030
Subject: [Jersey] RE: Testing resource class + data in request



 
I tried what you suggested:
 
MyBean myBean = this.webResource.path("one/two").accept(MediaType.APPLICATION_JSON)
    .post(MyBean.class, new GenericEntity<List<ObjOne>>(objList){});

 
and I got the following exception:
 
com.sun.jersey.api.client.UniformInterfaceException: POST http://localhost:9998/demo/myRoot/one/two returned a response status of 415
 at com.sun.jersey.api.client.WebResource.voidHandle(WebResource.java:582)
 at com.sun.jersey.api.client.WebResource.access$500(WebResource.java:69)
 at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:487)
 at au.com.sample.TestSample(SampleResource.java:83)
 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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
 at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
 at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
 at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
 at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
 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.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
 at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

 
Even doing
 
this.webResource.path("one/two").accept(MediaType.APPLICATION_JSON)
    .post(new GenericEntity<List<ObjOne>>(objList){});
 
throws the same http 415 error code...
 
Do I need to provide a JAXBContextResolver to handle object to json transformation when passing a generic type in?
 
 
Paul wrote:
-------------------------------------------------------------------
IIRC you want to preserve the generic type information for the list
instance you are sending as the request entity. Try:

MyBean myBean = this.webResource.path("one/
two").accept(MediaType.APPLICATION_JSON).post(
   MyBean.class, new GenericEntity<List<ObjOne>>(objList){});




Brought to you exclusively by Windows Live Download new and classic emoticon packs at Emoticon World
_________________________________________________________________
Looking for a date? View photos of singles in your area!
http://clk.atdmt.com/NMN/go/150855801/direct/01/