Hi all! I'm a newbie with Restlet and I have a problem. I created a service that works perfectly but my client application does not. It fails when I invoke the DELETE method. GET, POST and PUT works fine.
This is the code from my client application: JSONObject object = new JSONObject(); object.put("name", "a name"); Request request = new Request(Method.DELETE, reference); request.setEntity(new JsonRepresentation(object.toString())); Client client = new Client(Protocol.HTTP); Response response = client.handle(request); String text = response.getEntity().getText(); The code from the ServerResource class: public class MyResource extends ServerResource { @Delete public Representation deleteUser(Representation entity) { try { String jsonString = (new JsonRepresentation(entity)).getJsonObject().toString(); Map map = (Map) (new JSONParser()).parse(jsonString); if(map.size() > 0) { String message = dbc.deleteUser(map.get("name").toString()); return new StringRepresentation(message, MediaType.TEXT_PLAIN); } else { return new StringRepresentation("Unable to delete user", MediaType.TEXT_PLAIN); } } catch (Exception ex) { return new StringRepresentation("ERROR: " + ex.getMessage(), MediaType.TEXT_PLAIN); } } ... } POST and PUT methods start with the same code. I tested each method using Advanced Rest Client in Chrome and all of them works perfectly. It only fails in my client application. This is the exception: java.lang.NullPointerException at java.io.StringReader.<init>(Unknown Source) at org.json.JSONTokener.<init>(JSONTokener.java:66) at org.json.JSONObject.<init>(JSONObject.java:402) at org.restlet.ext.json.JsonRepresentation.getJsonObject(JsonRepresentation.java:199) at service.MyResource.borrarUsuario(MyResource.java:95) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.restlet.resource.ServerResource.doHandle(ServerResource.java:503) at org.restlet.resource.ServerResource.delete(ServerResource.java:208) at org.restlet.resource.ServerResource.doHandle(ServerResource.java:594) at org.restlet.resource.ServerResource.doNegotiatedHandle(ServerResource.java:649) at org.restlet.resource.ServerResource.doConditionalHandle(ServerResource.java:348) at org.restlet.resource.ServerResource.handle(ServerResource.java:952) at org.restlet.resource.Finder.handle(Finder.java:246) at org.restlet.routing.Filter.doHandle(Filter.java:159) at org.restlet.routing.Filter.handle(Filter.java:206) at org.restlet.routing.Router.doHandle(Router.java:431) at org.restlet.routing.Router.handle(Router.java:648) at org.restlet.routing.Filter.doHandle(Filter.java:159) at org.restlet.routing.Filter.handle(Filter.java:206) at org.restlet.routing.Filter.doHandle(Filter.java:159) at org.restlet.routing.Filter.handle(Filter.java:206) at org.restlet.routing.Filter.doHandle(Filter.java:159) at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:155) at org.restlet.routing.Filter.handle(Filter.java:206) at org.restlet.routing.Filter.doHandle(Filter.java:159) at org.restlet.routing.Filter.handle(Filter.java:206) at org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:211) at org.restlet.engine.application.ApplicationHelper.handle(ApplicationHelper.java:84) at org.restlet.Application.handle(Application.java:381) at org.restlet.routing.Filter.doHandle(Filter.java:159) at org.restlet.routing.Filter.handle(Filter.java:206) at org.restlet.routing.Router.doHandle(Router.java:431) at org.restlet.routing.Router.handle(Router.java:648) at org.restlet.routing.Filter.doHandle(Filter.java:159) at org.restlet.routing.Filter.handle(Filter.java:206) at org.restlet.routing.Router.doHandle(Router.java:431) at org.restlet.routing.Router.handle(Router.java:648) at org.restlet.routing.Filter.doHandle(Filter.java:159) at org.restlet.routing.Filter.handle(Filter.java:206) at org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:211) at org.restlet.Component.handle(Component.java:392) at org.restlet.Server.handle(Server.java:516) at org.restlet.engine.ServerHelper.handle(ServerHelper.java:72) at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:152) at org.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:1089) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) may 22, 2013 3:10:58 PM org.restlet.engine.log.LogFilter afterHandle INFO: 2013-05-22 15:10:58 127.0.0.1 - 127.0.0.1 8181 DELETE /Restlet_Service/ - 200 11 17 20592 http://localhost:8181 Restlet-Framework/2.1.2 - The line 95 is "String jsonString = (new JsonRepresentation(entity)).getJsonObject().toString();". I'm stuck and need help with this. Thanks in advance. ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3056251