Some queries regarding JSON support in cxf-2.2.4
Hi, I have been evaluating cxf-2.2.4.jar and I need some help for the following issues. Issue 1 : Is there any support for getting JSON in Badgerfish and Jettison-Mapped notations in cxf-2.2.4? If yes, please tell me the configuration to get JSON any one of these notations. If no, by when do you plan to suport these notations. Issue 2 : Marshalling and unmarshalling of a list containing objects of a subclass of the Type of the list. In this example Client is a subclass of Customer. @Path("/customerservice/") public class CustomerService { @GET @Produces("application/json") @Path("/myobject/") public MyObject getCustomerList() { List list = new ArrayList(); Client client = new Client(); client.setName("firstClient"); client.setId(1000); client.setClientId("999"); Customer c = new Customer(); c.setName("aaa"); c.setId(111); list.add(c); list.add(client); MyObject m = new MyObject(); m.setList(list); return m; } } The JSON for the list given by cxf is : {"myObject":{"list":[{"id":111,"name":"aaa"},{"id":1000,"name":"firstClient"}]}} where as the JSON given by jersey-bundle-1.0.2.jar is : {"myObject":{"list":[{"id":"111","name":"aaa"},{"@type":"client","id":"1000","name":"firstClient","clientId":"999"}]}} The JSON given by jersey-bundle-1.0.2.jar is more helpful in some cases. Can you please provide similar support in cxf too. Java classes for the above example @XmlRootElement public class MyObject { List list = new ArrayList(); public List getList() { return list; } public void setList(List list) { this.list = list; } } @XmlRootElement public class Customer { private long id; private String name; public Customer() {} public Customer(String name, long id) { this.name = name; this.id = id; } public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } @XmlRootElement public class Client extends Customer { private String clientId; public String getClientId() { return clientId; } public void setClientId(String clientId) { this.clientId = clientId; } } Thank you. Chaithanya.
Re: Some queries regarding JSON support in cxf-2.2.4
Hi, Issue1. There's a custom BadgerFish provider available in the system test area : http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BadgerFishProvider.java So please feel free to copy the source and use it as a custom provider in your own project. (I'm still hoping someone who provided that patch awhile back will get back with few more patches and become a committer :-)). Jettison-Mapped notations Isn't it what the default JSONProvider we ship supports ? I thought it did...Or am I wrong ? Issue2. I'm not sure how Jersey JSON detects that subclasses have to be handled in some cases, but by adding @XmlSeeAlso(Client.class) to Customer.class (perhaps adding @XmlElements(Client.class, Customer.class) to the List field would have the same result) produces : {"myObject":{"list":[{"id":111,"name":"aaa"},{"@xsi.type":"client","id":1000,"name":"firstClient","clientId":999}]}} Note "@xsi.type, I think it's actually better than @type because using @type would interfere with attributes called 'type' (in cases when classes have been generated from schema types containing attributes such as 'type') but which have nothing to do with class hierarchies, but have some domina-specific meaning cheers, Sergey - Original Message - From: "Chaitanya" To: "cxf_dev" Sent: Thursday, October 29, 2009 8:39 AM Subject: Some queries regarding JSON support in cxf-2.2.4 Hi, I have been evaluating cxf-2.2.4.jar and I need some help for the following issues. Issue 1 : Is there any support for getting JSON in Badgerfish and Jettison-Mapped notations in cxf-2.2.4? If yes, please tell me the configuration to get JSON any one of these notations. If no, by when do you plan to suport these notations. Issue 2 : Marshalling and unmarshalling of a list containing objects of a subclass of the Type of the list. In this example Client is a subclass of Customer. @Path("/customerservice/") public class CustomerService { @GET @Produces("application/json") @Path("/myobject/") public MyObject getCustomerList() { List list = new ArrayList(); Client client = new Client(); client.setName("firstClient"); client.setId(1000); client.setClientId("999"); Customer c = new Customer(); c.setName("aaa"); c.setId(111); list.add(c); list.add(client); MyObject m = new MyObject(); m.setList(list); return m; } } The JSON for the list given by cxf is : {"myObject":{"list":[{"id":111,"name":"aaa"},{"id":1000,"name":"firstClient"}]}} where as the JSON given by jersey-bundle-1.0.2.jar is : {"myObject":{"list":[{"id":"111","name":"aaa"},{"@type":"client","id":"1000","name":"firstClient","clientId":"999"}]}} The JSON given by jersey-bundle-1.0.2.jar is more helpful in some cases. Can you please provide similar support in cxf too. Java classes for the above example @XmlRootElement public class MyObject { List list = new ArrayList(); public List getList() { return list; } public void setList(List list) { this.list = list; } } @XmlRootElement public class Customer { private long id; private String name; public Customer() {} public Customer(String name, long id) { this.name = name; this.id = id; } public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } @XmlRootElement public class Client extends Customer { private String clientId; public String getClientId() { return clientId; } public void setClientId(String clientId) { this.clientId = clientId; } } Thank you. Chaithanya.
Re: Some queries regarding JSON support in cxf-2.2.4
Hi, Thank you for the prompt reply. Jettison-Mapped notations Isn't it what the default JSONProvider we ship supports ? I thought it did...Or am I wrong ? default JSONProvider supports Mapped notation which is slightly different from Jettison-Mapped notation. Thank you. Chaithanya. - Original Message - From: "Sergey Beryozkin" To: Sent: Thursday, October 29, 2009 3:37 PM Subject: Re: Some queries regarding JSON support in cxf-2.2.4 Hi, Issue1. There's a custom BadgerFish provider available in the system test area : http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BadgerFishProvider.java So please feel free to copy the source and use it as a custom provider in your own project. (I'm still hoping someone who provided that patch awhile back will get back with few more patches and become a committer :-)). Jettison-Mapped notations Isn't it what the default JSONProvider we ship supports ? I thought it did...Or am I wrong ? Issue2. I'm not sure how Jersey JSON detects that subclasses have to be handled in some cases, but by adding @XmlSeeAlso(Client.class) to Customer.class (perhaps adding @XmlElements(Client.class, Customer.class) to the List field would have the same result) produces : {"myObject":{"list":[{"id":111,"name":"aaa"},{"@xsi.type":"client","id":1000,"name":"firstClient","clientId":999}]}} Note "@xsi.type, I think it's actually better than @type because using @type would interfere with attributes called 'type' (in cases when classes have been generated from schema types containing attributes such as 'type') but which have nothing to do with class hierarchies, but have some domina-specific meaning cheers, Sergey - Original Message - From: "Chaitanya" To: "cxf_dev" Sent: Thursday, October 29, 2009 8:39 AM Subject: Some queries regarding JSON support in cxf-2.2.4 Hi, I have been evaluating cxf-2.2.4.jar and I need some help for the following issues. Issue 1 : Is there any support for getting JSON in Badgerfish and Jettison-Mapped notations in cxf-2.2.4? If yes, please tell me the configuration to get JSON any one of these notations. If no, by when do you plan to suport these notations. Issue 2 : Marshalling and unmarshalling of a list containing objects of a subclass of the Type of the list. In this example Client is a subclass of Customer. @Path("/customerservice/") public class CustomerService { @GET @Produces("application/json") @Path("/myobject/") public MyObject getCustomerList() { List list = new ArrayList(); Client client = new Client(); client.setName("firstClient"); client.setId(1000); client.setClientId("999"); Customer c = new Customer(); c.setName("aaa"); c.setId(111); list.add(c); list.add(client); MyObject m = new MyObject(); m.setList(list); return m; } } The JSON for the list given by cxf is : {"myObject":{"list":[{"id":111,"name":"aaa"},{"id":1000,"name":"firstClient"}]}} where as the JSON given by jersey-bundle-1.0.2.jar is : {"myObject":{"list":[{"id":"111","name":"aaa"},{"@type":"client","id":"1000","name":"firstClient","clientId":"999"}]}} The JSON given by jersey-bundle-1.0.2.jar is more helpful in some cases. Can you please provide similar support in cxf too. Java classes for the above example @XmlRootElement public class MyObject { List list = new ArrayList(); public List getList() { return list; } public void setList(List list) { this.list = list; } } @XmlRootElement public class Customer { private long id; private String name; public Customer() {} public Customer(String name, long id) { this.name = name; this.id = id; } public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } @XmlRootElement public class Client extends Customer { private String clientId; public String getClientId() { return clientId; } public void setClientId(String clientId) { this.clientId = clientId; } } Thank you. Chaithanya.
Re: Some queries regarding JSON support in cxf-2.2.4
Hi Hi, Thank you for the prompt reply. Jettison-Mapped notations Isn't it what the default JSONProvider we ship supports ? I thought it did...Or am I wrong ? default JSONProvider supports Mapped notation which is slightly different from Jettison-Mapped notation. I chatted with Dejan and he was not aware of a 'Jettison-Mapped' convention, perhaps some other library which sits on top of Jettison offers it ? as far as BudgerFish is concerned : I'll do a quick update to JSONProvider to support it too in time for 2.1.5; Jettison 1.1 also supports type converters so JSONProviders will allow injecting them too Also, as far as that Client/Consumer issue is concerned : you can probably just use jaxb.index (starting from 2.2.4) instead of @XmlSeeAlso and friends thanks, Sergey Thank you. Chaithanya. - Original Message - From: "Sergey Beryozkin" To: Sent: Thursday, October 29, 2009 3:37 PM Subject: Re: Some queries regarding JSON support in cxf-2.2.4 Hi, Issue1. There's a custom BadgerFish provider available in the system test area : http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BadgerFishProvider.java So please feel free to copy the source and use it as a custom provider in your own project. (I'm still hoping someone who provided that patch awhile back will get back with few more patches and become a committer :-)). Jettison-Mapped notations Isn't it what the default JSONProvider we ship supports ? I thought it did...Or am I wrong ? Issue2. I'm not sure how Jersey JSON detects that subclasses have to be handled in some cases, but by adding @XmlSeeAlso(Client.class) to Customer.class (perhaps adding @XmlElements(Client.class, Customer.class) to the List field would have the same result) produces : {"myObject":{"list":[{"id":111,"name":"aaa"},{"@xsi.type":"client","id":1000,"name":"firstClient","clientId":999}]}} Note "@xsi.type, I think it's actually better than @type because using @type would interfere with attributes called 'type' (in cases when classes have been generated from schema types containing attributes such as 'type') but which have nothing to do with class hierarchies, but have some domina-specific meaning cheers, Sergey - Original Message - From: "Chaitanya" To: "cxf_dev" Sent: Thursday, October 29, 2009 8:39 AM Subject: Some queries regarding JSON support in cxf-2.2.4 Hi, I have been evaluating cxf-2.2.4.jar and I need some help for the following issues. Issue 1 : Is there any support for getting JSON in Badgerfish and Jettison-Mapped notations in cxf-2.2.4? If yes, please tell me the configuration to get JSON any one of these notations. If no, by when do you plan to suport these notations. Issue 2 : Marshalling and unmarshalling of a list containing objects of a subclass of the Type of the list. In this example Client is a subclass of Customer. @Path("/customerservice/") public class CustomerService { @GET @Produces("application/json") @Path("/myobject/") public MyObject getCustomerList() { List list = new ArrayList(); Client client = new Client(); client.setName("firstClient"); client.setId(1000); client.setClientId("999"); Customer c = new Customer(); c.setName("aaa"); c.setId(111); list.add(c); list.add(client); MyObject m = new MyObject(); m.setList(list); return m; } } The JSON for the list given by cxf is : {"myObject":{"list":[{"id":111,"name":"aaa"},{"id":1000,"name":"firstClient"}]}} where as the JSON given by jersey-bundle-1.0.2.jar is : {"myObject":{"list":[{"id":"111","name":"aaa"},{"@type":"client","id":"1000","name":"firstClient","clientId":"999"}]}} The JSON given by jersey-bundle-1.0.2.jar is more helpful in some cases. Can you please provide similar support in cxf too. Java classes for the above example @XmlRootElement public class MyObject { List list = new ArrayList(); public List getList() { return list; } public void setList(List list) { this.list = list; } } @XmlRootElement public class Customer { private long id; private String name; public Customer() {} public Customer(String name, long id) { this.name = name; this.id = id; } public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } @XmlRootElement public class Client extends Customer { private String clientId; public String getClientId() { return clientId; } public void setClientId(String clientId) { this.clientId = clientId; } } Thank you. Chaithanya.
xerces versus classpath versus webapps
This isn't CXF-specific, but I bet one of you has been here before. I have a webapp. It has a JAX-RS CXF service. That service takes an XML file and parses it using standard JAXP APIs. It sets up XML Schema validation. xerces is listed as a dependency, no scope specified. Run as a unit test. Deployed with mvn tomcat:run, the validation rejects the input with a bogus complaint. Backtrace shows that we're using the Sun repackaged JAXP, not xerces. I feel as if I must be missing something simple, but what?
Beware of jetty 7.0
I just accidentally tried to run a CXF service under Jetty 7.0 by running mvn jetty:run without a dependency in my pom to constrain to jetty 6. There seems to be a standards feud between Spring and jetty; jetty proceeded to complain that some of Spring's PostConstruct annotations were invalid, and then the stack traces came thick and fast.
Re: D-OSGi and REST
Hi Sergey, did you ever try deploying servlets (to serve calls to RESTful services) on Felix or did you only work on the CXF JAX-RS implementation? I am curious as to whether the OSGi HTTP server can handle servlets for this purpose. I have a feeling that it may not support a web.xml. I want to compare some performance metrics between such different implementations - any ideas will be greatly welcomed. Many regards Demetris Sergey Beryozkin wrote: Hi Yes, we do, it is the CXF JAXRS implementation which is embedded inside the DOSGI RI but given that the RI is based on CXF it's probably can be expected. But DOSGi is an open spec. Can I conceivably run this particular REST GreeterService and its client on any OSGi Web Server (how about Knopflerfish) with the JAX-RS libraries. You should have no problems publishing (RESTful) services on Knopflerfish as the DOSGI RI DSW component relies on the OSGI ServiceListener. It won't be possible to run the (REST GreeterService) client on Knopflerfish though untill it implements the relevant OSGI spec (RFC 119 ?), but it should not be too difficult to do. In meantime the only option on the client side is to load the bundles containing code explicitly consuming a remote service (using proxy-based or http-centric api)... cheers, Sergey Demetris-2 wrote: In other words, without trying to make this too convoluted, my question is do you guys use your own implementation of JAX-RS (instead of Jersey etc.). Thanks again Demetris wrote: Hi Sergey, I followed up on your info below in the distribution baseline - thanks, things are making a bit more sense now. Can I conceivably run this particular REST GreeterService and its client on any OSGi Web Server (how about Knopflerfish) with the JAX-RS libraries. I do see you are using Felix and Equinox in your examples so I am assuming the answer is yes. What do you guys add to such a service with the cxf-dosgi-ri-singlebundle-distribution_1.0.0? The reason I am asking is because I want to connect the REST service with its client by over p2p instead of over HTTP. Thanks Sergey Beryozkin wrote: Hi Have a look please at http://svn.apache.org/repos/asf/cxf/dosgi/trunk/samples/greeter_rest/ it is indeed virtually identical to a soap based greeter demo but the difference is here : http://svn.apache.org/repos/asf/cxf/dosgi/trunk/samples/greeter_rest/int erface/src/main/java/org/apache/cxf/dosgi/samples/greeter/rest/GreeterSe rvice.java (note JAXRS annotations) and here : http://svn.apache.org/repos/asf/cxf/dosgi/trunk/samples/greeter_rest/int erface/src/main/java/org/apache/cxf/dosgi/samples/greeter/rest/GreeterSe rvice2.java (has no annotations at all) but GreeterService2 uses this model : http://svn.apache.org/repos/asf/cxf/dosgi/trunk/samples/greeter_rest/int erface/src/main/resources/OSGI-INF/cxf/jaxrs/GreeterService2-model.xml some more info is here : http://cxf.apache.org/distributed-osgi-reference.html#DistributedOSGiRef erence-ServiceProviderpropertiesForConfiguringRESTfulJAXRSbasedendpoints andconsumers hope it helps Sergey -Original Message- From: Demetris [mailto:demet...@ece.neu.edu] Sent: 23 September 2009 08:13 To: dev@cxf.apache.org Subject: D-OSGi and REST Hi Sergey, you mentioned in the blog that users can now expose bundles/beans as SOAP and REST services. I looked over the example listed on the D-OSGi web site but both Greeter examples are the same for SOAP and REST - unless I am missing something. Do you have any examples of RESTful bundles? Thanks