Hi, I'm trying to make a simple example work JAXRS example work, as described below, but I do it using CXF-DOSGI. (on Equinox, using declarative services)
However, no matter how I configure my service, I always get a message: 12-sep-2012 15:27:42 org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor writeResponseErrorMessage WARNING: No message body writer has been found for response class ElectriciteitsMeterStand. (class ElectriciteitsMeterStand is a simple POJO that is returned by one of my methods, see code below) There must be something I'm overlooking, could you give any advice to help me solve this problem? Code: Service declaration in dOSGI: <?xml version="1.0" encoding="UTF-8"?> <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="false" name="EenvoudigeMeterOpname"> <implementation class="projectone.MeterOpnameImpl" /> <property name="service.exported.interfaces" value="*" /> <!-- property name="service.exported.configs" value="org.apache.cxf.ws" / --> <!-- property name="org.apache.cxf.ws.address" value="http://localhost:9090/ws/meteropname" / --> <property name="service.exported.configs" value="org.apache.cxf.rs" /> <property name="org.apache.cxf.rs.provider.expected" value="true" /> <property name="org.apache.cxf.rs.provider" value="org.apache.cxf.jaxrs.provider.JSONProvider" /> <!-- property name="service.exported.intents" value="HTTP" / --> <!-- property name="org.apache.cxf.rs.databinding" value="jaxb" / --> <service> <provide interface="projectone.MeterOpname"/> </service> </scr:component> Service interface: package projectone; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.xml.bind.annotation.XmlRootElement; @Path("/rs") @XmlRootElement public interface MeterOpname { /** * Returns the gas meter stand * * @return the gas meter stand */ @GET @Path("getgas") @Produces({"application/json", "text/xml"}) public String getGas(); /** * Returns the water meter stand * * @return the water meter stand */ @GET @Path("getwater") @Produces({"application/json", "text/xml"}) public String getWater(); /** * Returns the electriciteit meter stand * * @return the electriciteit meter stand */ @GET @Path("getelectriciteit") @Produces({"application/json", "text/xml"}) public ElectriciteitsMeterStand getElectriciteit(); } Service Implementation: package projectone; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.xml.bind.annotation.XmlRootElement; public class MeterOpnameImpl implements MeterOpname { public String getGas() { return toHtml(currentMethodName(), 10L); } public String getWater() { return toHtml(currentMethodName(), 100L); } public ElectriciteitsMeterStand getElectriciteit() { ElectriciteitsMeterStand result = new ElectriciteitsMeterStand(); result.setDalVerbruik(50L); result.setPiekVerbruik(150L); return result; } private String toHtml(String title, Long value) { return "<html><header></header><body><h1>" + title + "</h1><p>" + value + "</p></body></html>"; } private String currentMethodName() { StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace(); StackTraceElement e = stacktrace[2];//coz 0th will be getStackTrace so 1st return e.getMethodName(); } } Return POJO: package projectone; import javax.ws.rs.Produces; import javax.xml.bind.annotation.XmlRootElement; @Produces({"application/json", "text/xml"}) @XmlRootElement public class ElectriciteitsMeterStand { public ElectriciteitsMeterStand() { } private Long piekVerbruik; private Long dalVerbruik; public Long getPiekVerbruik() { return piekVerbruik; } public void setPiekVerbruik(Long piekVerbruik) { this.piekVerbruik = piekVerbruik; } public Long getDalVerbruik() { return dalVerbruik; } public void setDalVerbruik(Long dalVerbruik) { this.dalVerbruik = dalVerbruik; } } Thanks in advance! kind regards Koen Van Leuvenhaege
