Re: [Resteasy-users] Replacing ProxyFactory with RestEasyWebTarget does not work
This is a Resteasy Client - JAX-RS 2.0 mismatch migration problem. Replace: response.getEntity() with: response.readEntity(String.class); replace String.class to whatever class you want to marshal to. getEntity() returns null if you haven't unmarshalled anything with readEntity(). On 11/26/2013 2:59 PM, Gabriella Turek wrote: After upgrading from Resteasy 2.4 to 3.0.5, none of my client calls work anymore. The entity which I am expecting (as simple as a String) is always null. In debug mode I can see it being set in the Response object on the server side, but on the client side the entity in the Response is null. Here is an example call: The interface: | /** * @return all expired licenses */ @GET @ClientResponseType(entityType= LicenseList.class) @Path(/expired) @Produces(MediaType.APPLICATION_XML) public Response getExpiredLicenses();| The implementation: | /** * @return all expired licenses */ @Override public Response getExpiredLicenses() { try { LicenseList list= LicensesDBUtil.getExpiredLicenses(); Response resp= Response.ok().entity(list).build(); return resp; } catch (SQLException e) { LOG.error(Error getting expired licenses : + e.getMessage()); return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).type(MediaType.TEXT_PLAIN).build(); }| The test call : | @Test public void testGetExpiredLicenses() throws Exception { ResteasyClientBuilder rsb= new ResteasyClientBuilder(); ResteasyClient rsc= rsb.build(); ResteasyWebTarget target= rsc.target(BASEURL); return target.proxy(RiskScapeLicenseService.class); Response response= client.getExpiredLicenses(); assertTrue(HttpResponseCodes.SC_OK== response.getStatus()); @SuppressWarnings(unchecked) JAXBElementLicenseList element= (JAXBElementLicenseList) response.getEntity(); LicenseList list= element.getValue(); assertEquals(4, list.getLicenses().size()); for (License lic: list.getLicenses()) { assertTrue((new Date()).after(DateUtils.parseDate(lic.getValidTo(), new String[] { -MM-dd }))); } }| My web.xml file: |?xml version=1.0 encoding=UTF-8? web-app xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; xmlns=http://java.sun.com/xml/ns/javaee; xmlns:web=http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd; xsi:schemaLocation=http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd; version=2.5 display-nameriskscapelic_rest/display-name listener listener-class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap /listener-class /listener servlet servlet-nameResteasy/servlet-name servlet-classorg.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher/servlet-class /servlet servlet-mapping servlet-nameResteasy/servlet-name url-pattern/*/url-pattern /servlet-mapping context-param param-nameresteasy.scan/param-name param-valuetrue/param-value /context-param context-param param-nameresteasy.servlet.mapping.prefix/param-name param-value//param-value /context-param /web-app| The LicenseList class: |@XmlRootElement(name= LicenseList) @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name= licenseList, propOrder= { licenses }) public class LicenseList { @XmlElement(name= Licenses, required= true) protected ListLicense licenses; /** * Gets the value of the licenses property. * * p * This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a CODEset/CODE method for the licenses property. * * p * For example, to add a new item, do as follows: * pre *getLicenses().add(newItem); * /pre * * * p * Objects of the following type(s) are allowed in the list * {@link License } * * */ public ListLicense getLicenses() { if (licenses== null) { licenses= new ArrayListLicense(); } return this.licenses; } }| I am using JDK 1.7, Tomcat 7.0.47 -- Dr Gabriella Turek Sr. Software Engineer, Systems Development Team NIWA Auckland, New Zealand Tel: +64 9 3754645 www.niwa.co.nz NIWA - Enhancing the benefit of New Zealand’s natural resources. -- Please consider the environment before printing this email. NIWA is the trading name of the National Institute of Water Atmospheric Research Ltd. -- Rapidly troubleshoot problems
Re: [Resteasy-users] Replacing ProxyFactory with RestEasyWebTarget does not work
No, I've tried that, it does not work. I get the following error: java.lang.ClassCastException: javax.xml.bind.JAXBElement cannot be cast to nz.org.riskscape.license.rest.domain.LicenseList at nz.org.riskscape.license.rest.RiskScapeLicenseServiceTest.testGetExpiredLic enses(RiskScapeLicenseServiceTest.java:102) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:5 7) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp l.java:43) at java.lang.reflect.Method.invoke(Method.java:606) -- Dr Gabriella Turek Sr. Software Engineer, Systems Development Team NIWA Auckland, New Zealand Tel: +64 9 3754645 www.niwa.co.nz NIWA - Enhancing the benefit of New Zealand¹s natural resources. Date: Tue, 26 Nov 2013 15:51:56 -0500 From: Bill Burke bbu...@redhat.com Subject: Re: [Resteasy-users] Replacing ProxyFactory with RestEasyWebTarget does not work To: resteasy-users@lists.sourceforge.net Message-ID: 529509ec.3000...@redhat.com Content-Type: text/plain; charset=windows-1252; format=flowed This is a Resteasy Client - JAX-RS 2.0 mismatch migration problem. Replace: response.getEntity() with: response.readEntity(String.class); replace String.class to whatever class you want to marshal to. getEntity() returns null if you haven't unmarshalled anything with readEntity(). On 11/26/2013 2:59 PM, Gabriella Turek wrote: After upgrading from Resteasy 2.4 to 3.0.5, none of my client calls work anymore. The entity which I am expecting (as simple as a String) is always null. In debug mode I can see it being set in the Response object on the server side, but on the client side the entity in the Response is null. Here is an example call: The interface: | /** * @return all expired licenses */ @GET @ClientResponseType(entityType= LicenseList.class) @Path(/expired) @Produces(MediaType.APPLICATION_XML) public Response getExpiredLicenses();| The implementation: | /** * @return all expired licenses */ @Override public Response getExpiredLicenses() { try { LicenseList list= LicensesDBUtil.getExpiredLicenses(); Response resp= Response.ok().entity(list).build(); return resp; } catch (SQLException e) { LOG.error(Error getting expired licenses : + e.getMessage()); return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).type (MediaType.TEXT_PLAIN).build(); }| The test call : | @Test public void testGetExpiredLicenses() throws Exception { ResteasyClientBuilder rsb= new ResteasyClientBuilder(); ResteasyClient rsc= rsb.build(); ResteasyWebTarget target= rsc.target(BASEURL); return target.proxy(RiskScapeLicenseService.class); Response response= client.getExpiredLicenses(); assertTrue(HttpResponseCodes.SC_OK== response.getStatus()); @SuppressWarnings(unchecked) JAXBElementLicenseList element= (JAXBElementLicenseList) response.getEntity(); LicenseList list= element.getValue(); assertEquals(4, list.getLicenses().size()); for (License lic: list.getLicenses()) { assertTrue((new Date()).after(DateUtils.parseDate(lic.getValidTo(), new String[] { -MM-dd }))); } }| My web.xml file: |?xml version=1.0 encoding=UTF-8? web-app xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; xmlns=http://java.sun.com/xml/ns/javaee; xmlns:web=http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd; xsi:schemaLocation=http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd; version=2.5 display-nameriskscapelic_rest/display-name listener listener-class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap /listener-class /listener servlet servlet-nameResteasy/servlet-name servlet-classorg.jboss.resteasy.plugins.server.servlet.HttpServletDispa tcher/servlet-class /servlet servlet-mapping servlet-nameResteasy/servlet-name url-pattern/*/url-pattern /servlet-mapping context-param param-nameresteasy.scan/param-name param-valuetrue/param-value /context-param context-param param-nameresteasy.servlet.mapping.prefix/param-name param-value//param-value /context-param /web-app| The LicenseList class: |@XmlRootElement(name= LicenseList) @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name= licenseList, propOrder= { licenses }) public class LicenseList { @XmlElement(name= Licenses, required= true) protected ListLicense licenses; /** * Gets the value of the licenses property. * * p * This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make
Re: [Resteasy-users] Replacing ProxyFactory with RestEasyWebTarget does not work
So, I've resolved my issue by updating my schema with jaxb:version=2.0 and regenerating the jaxb classes. The tip off was Bill's mention of there being a Resteasy Client - JAX-RS 2.0 mismatch migration problem Cheers! Gaby On 27/11/13 10:00 AM, Gabriella Turek gabriella.tu...@niwa.co.nz wrote: No, I've tried that, it does not work. I get the following error: java.lang.ClassCastException: javax.xml.bind.JAXBElement cannot be cast to nz.org.riskscape.license.rest.domain.LicenseList at nz.org.riskscape.license.rest.RiskScapeLicenseServiceTest.testGetExpiredL i c enses(RiskScapeLicenseServiceTest.java:102) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java : 5 7) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI m p l.java:43) at java.lang.reflect.Method.invoke(Method.java:606) -- Dr Gabriella Turek Sr. Software Engineer, Systems Development Team NIWA Auckland, New Zealand Tel: +64 9 3754645 www.niwa.co.nz NIWA - Enhancing the benefit of New Zealand¹s natural resources. Date: Tue, 26 Nov 2013 15:51:56 -0500 From: Bill Burke bbu...@redhat.com Subject: Re: [Resteasy-users] Replacing ProxyFactory with RestEasyWebTarget does not work To: resteasy-users@lists.sourceforge.net Message-ID: 529509ec.3000...@redhat.com Content-Type: text/plain; charset=windows-1252; format=flowed This is a Resteasy Client - JAX-RS 2.0 mismatch migration problem. Replace: response.getEntity() with: response.readEntity(String.class); replace String.class to whatever class you want to marshal to. getEntity() returns null if you haven't unmarshalled anything with readEntity(). On 11/26/2013 2:59 PM, Gabriella Turek wrote: After upgrading from Resteasy 2.4 to 3.0.5, none of my client calls work anymore. The entity which I am expecting (as simple as a String) is always null. In debug mode I can see it being set in the Response object on the server side, but on the client side the entity in the Response is null. Here is an example call: The interface: | /** * @return all expired licenses */ @GET @ClientResponseType(entityType= LicenseList.class) @Path(/expired) @Produces(MediaType.APPLICATION_XML) public Response getExpiredLicenses();| The implementation: | /** * @return all expired licenses */ @Override public Response getExpiredLicenses() { try { LicenseList list= LicensesDBUtil.getExpiredLicenses(); Response resp= Response.ok().entity(list).build(); return resp; } catch (SQLException e) { LOG.error(Error getting expired licenses : + e.getMessage()); return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).ty p e (MediaType.TEXT_PLAIN).build(); }| The test call : | @Test public void testGetExpiredLicenses() throws Exception { ResteasyClientBuilder rsb= new ResteasyClientBuilder(); ResteasyClient rsc= rsb.build(); ResteasyWebTarget target= rsc.target(BASEURL); return target.proxy(RiskScapeLicenseService.class); Response response= client.getExpiredLicenses(); assertTrue(HttpResponseCodes.SC_OK== response.getStatus()); @SuppressWarnings(unchecked) JAXBElementLicenseList element= (JAXBElementLicenseList) response.getEntity(); LicenseList list= element.getValue(); assertEquals(4, list.getLicenses().size()); for (License lic: list.getLicenses()) { assertTrue((new Date()).after(DateUtils.parseDate(lic.getValidTo(), new String[] { -MM-dd }))); } }| My web.xml file: |?xml version=1.0 encoding=UTF-8? web-app xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; xmlns=http://java.sun.com/xml/ns/javaee; xmlns:web=http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd; xsi:schemaLocation=http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd; version=2.5 display-nameriskscapelic_rest/display-name listener listener-class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap /listener-class /listener servlet servlet-nameResteasy/servlet-name servlet-classorg.jboss.resteasy.plugins.server.servlet.HttpServletDis p a tcher/servlet-class /servlet servlet-mapping servlet-nameResteasy/servlet-name url-pattern/*/url-pattern /servlet-mapping context-param param-nameresteasy.scan/param-name param-valuetrue/param-value /context-param context-param param-nameresteasy.servlet.mapping.prefix/param-name param-value//param-value /context-param /web-app| The LicenseList class: |@XmlRootElement(name= LicenseList) @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name= licenseList, propOrder= { licenses }) public class LicenseList { @XmlElement(name= Licenses