tomitribe / tomee-jaxrs-angular-starter-project

Apache License 2.0
7 stars 12 forks source link

JAXRS related TomEE 7+ bug #3

Open mtravnicek opened 5 years ago

mtravnicek commented 5 years ago

This app works wrong with current setup (TomEE 7.0.2, tried also 7.1.0) App works correctly with old TomEE 1.7.3 (Tomcat 7) - TomEE 7 is Tomcat 8.5! (confusing numbering) Tried to run it on CodeEnvy prepared TomEE workspace... Problem is with Phone entity which somehow doesnt get registered as root in JSON response. (as is mentioned in #2 - this is result). Probably its caused by Apache CXF or related or some classloading/deployment sequencing.

This is what it does when running on embedded server (mvn install tomee:run) Test PhoneServiceTest somehow passes, but when the server is launched, the JSON looks like [{"age":0,"carrier":"","id":"motorola... (missing "phone" in root) Strangely enough when I duplicate getPhones() and change only annotation to @Path("xml") @Produces(MediaType.APPLICATION_XML) this produces correct XML!

<phones>
<phone>
<age>0</age>
<carrier/>
<id>motorola-xoom-with-wi-fi</id>
<name>Motorola XOOM(tm) with Wi-Fi</name>...

@dblevins Then where is the snag? Regards

rmannibucau commented 5 years ago

@mtravnicek this is due to the switch from the legacy jettison serialization to the long requested standard JSON model (johnzon for tomee 7 then jsonb in tomee 8. Long story short it is uncommon to wrap the root object in json to not say it never happens so xml modelling does not fit well). The js must therefore be adapted - as in the currently open PR - or jettison must be added back in the tomee lib and configured to be used.

Hope it helps...

mtravnicek commented 5 years ago

Thanks that explains it, can the owner please fix it and close issue...

mtravnicek commented 5 years ago

But why is the test passing...

webClient.accept(MediaType.APPLICATION_JSON);
final Collection<? extends Phone> phones = webClient.path("phone/list").getCollection(Phone.class);

it pickups entity from JSON correctly I just got this JSON printed.... [Phone{age=0, carrier='', id='motorola So the Arqullian runs on different/own server version/setup so this must be fixed also, when test is false positive (not relevant)

rmannibucau commented 5 years ago

Test uses a client and server using the same mapper so this works. The bug is in the js.

cesarhernandezgt commented 5 years ago

or jettison must be added back in the tomee lib and configured to be used.

@mtravnicek for the above-quoted approach there is an example on TomEE project: https://github.com/apache/tomee/tree/master/examples/jaxrs-json-provider-jettison

mtravnicek commented 5 years ago

Yes but test uses "getCollection(Phone.class)" to pickup collection from JSON where page "phone/list/" produces JSON containing that root element "phone" as I mentioned.... app itself works differently and theres no "phone" in JSON ... and then controller.js fails... But this test should ALSO fail.

rmannibucau commented 5 years ago

@mtravnicek you didnt print json but toString ;)

mtravnicek commented 5 years ago

i see but how is test picking up the entity it is also aware that the root object is not wrapped? How to print what is exactly JSON in webClient? Tried code like this in test but it produces 404 Not found....

 Response response = webClient.path("phone/list").get();
rmannibucau commented 5 years ago

The test uses tomee embedded with default config so the client cxf bus inherits from the server one and therefore the right mapper.