This does not work? LicenseList list = response.readEntity(LicenseList.class);
You could also try this: LicenseList list = response.readEntity(new GenericType<JAXBElement<LicenseList>>() {}).getValue(); javax.ws.rs.core.GenericType On 11/26/2013 4:00 PM, Gabriella Turek 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.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") >>> JAXBElement<LicenseList> element= (JAXBElement<LicenseList>) >>> 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[] { >>> "yyyy-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-name>riskscapelic_rest</display-name> >>> <listener> >>> <listener-class> >>> org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap >>> </listener-class> >>> </listener> >>> <servlet> >>> <servlet-name>Resteasy</servlet-name> >>> >>> <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispa >>> tcher</servlet-class> >>> </servlet> >>> <servlet-mapping> >>> <servlet-name>Resteasy</servlet-name> >>> <url-pattern>/*</url-pattern> >>> </servlet-mapping> >>> <context-param> >>> <param-name>resteasy.scan</param-name> >>> <param-value>true</param-value> >>> </context-param> >>> <context-param> >>> <param-name>resteasy.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 List<License> 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 <CODE>set</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 List<License> getLicenses() { >>> if (licenses== null) { >>> licenses= new ArrayList<License>(); >>> } >>> 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 before they affect your business. Most IT >>> organizations don't have a clear picture of how application performance >>> affects their revenue. With AppDynamics, you get 100% visibility into >>> your >>> Java,.NET, & PHP application. Start your 15-day FREE TRIAL of >>> AppDynamics Pro! >>> >>> http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clkt >>> rk >>> >>> >>> >>> _______________________________________________ >>> Resteasy-users mailing list >>> Resteasy-users@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/resteasy-users >>> >> >> -- >> Bill Burke >> JBoss, a division of Red Hat >> http://bill.burkecentral.com >> >> >> >> ------------------------------ >> >> -------------------------------------------------------------------------- >> ---- >> Rapidly troubleshoot problems before they affect your business. Most IT >> organizations don't have a clear picture of how application performance >> affects their revenue. With AppDynamics, you get 100% visibility into >> your >> Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics >> Pro! >> http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktr >> k >> >> ------------------------------ >> >> _______________________________________________ >> Resteasy-users mailing list >> Resteasy-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/resteasy-users >> >> >> End of Resteasy-users Digest, Vol 42, Issue 4 >> ********************************************* > > -- > 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 before they affect your business. Most IT > organizations don't have a clear picture of how application performance > affects their revenue. With AppDynamics, you get 100% visibility into your > Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! > http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk > _______________________________________________ > Resteasy-users mailing list > Resteasy-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/resteasy-users > -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com ------------------------------------------------------------------------------ Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk _______________________________________________ Resteasy-users mailing list Resteasy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/resteasy-users