java - A simple JaxWS Rest that accept JSON Object -


i'm trying develop in java rest webservice (i'm using resteasy) accept generic jsonobject (i'm using json simple 1.1.1).

what i've done far:

@path("/message") public class testrestservice {      @post     @path("/{param}")     @consumes("application/json")      public response printmessage(jsonobject inputjsonobj) {          string result = "restful example : " + inputjsonobj;      system.out.println(result);         return response.status(200).entity(result).build();      }  } 

and client:

  public static void main(string[] args) {      try {        url url = new url("http://localhost:8080/myproject/rest/message/");       httpurlconnection conn = (httpurlconnection) url.openconnection();       conn.setdooutput(true);       conn.setrequestmethod("post");       conn.setrequestproperty("content-type", "application/json");        string input = "{\"qty\":100,\"name\":\"ipad 4\"}";        outputstream os = conn.getoutputstream();       os.write(input.getbytes());       os.flush();        if (conn.getresponsecode() != httpurlconnection.http_created) {           throw new runtimeexception("failed : http error code : "               + conn.getresponsecode());       }        bufferedreader br = new bufferedreader(new inputstreamreader(               (conn.getinputstream())));        string output;       system.out.println("output server .... \n");       while ((output = br.readline()) != null) {           system.out.println(output);       }        conn.disconnect();        } catch (malformedurlexception e) { }        catch (ioexception e) { }  } 

unfortunately i'm getting 405 error, means path suppose doesn't exist...

can me?

thanks!

it seems missing /{param}-part of path. right have nothing following part /message webserver can not find method accepts pass /message. since not trying use /{param} in method suggest remove @path-annotation method. possible because framework try , use @path annotation on next level (here class-level , /message path) http-method annotated method. if /{param} should optional parameter suggest using @queryparameter annotation in method-head. further information on annotation should read docs javax.ws.rs framework.
kind regards


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -