Hi guys,
Ok I figured it out!
I was doing a couple of things wrong.
Firstly I shouldn't be using @QueryParam for receiving body requests. It
shouldn't have any annotations.
Secondly I had security setup in my conf/conf.d/cxf-rs.properties with (realm =
PropertiesLogin & auth = BASIC). Even though the rest methods weren't annotated
with @RolesAllowed, the post request still needed to login a user before it
redirected to the rest method.
So basically, the request was not being authenticated and just sent back
nothing.
So I needed to add a username and password to the curl request like so:
> curl -X POST -v -H "Accept: application/json" -H "Content-type:
> application/json" -d '{"param":"value"}'
> http://username:[email protected]:4204/testing-rest-0.0.1-SNAPSHOT/example/post
Surely the server should be logging this?? Something like 'No user credentials
found - binning request'?
Regards,
Chris Christo
---
Twitter: https://twitter.com/ChrisChristo7
Tumblr: http://chrischristo7.tumblr.com
LinkedIn: http://uk.linkedin.com/in/chrischristo
GitHub: https://github.com/ChrisChristo
On 4 Jun 2013, at 19:40, Chris.Christo <[email protected]> wrote:
> Hi,
>
> <testing-rest-0.0.1-SNAPSHOT.jar>
>
> (The following is run with the latest OpenEJB standalone 4.6.0-SNAPSHOT on a
> Mac and calling the openejb start command)
>
> (I have attached the app, its an ejb-jar which you need to just drop in to
> apps/ of a fresh OpenEJB standalone from the tomee/assembly/ folder in svn.
> The app has nothing other than this one simple rest class below).
>
> I'm having a problem with calling a POST or a PUT to the following class:
>
> --------------------------
> @Singleton
> @Path("/example")
> public class ExampleRest {
>
> @GET
> @Path(value = "/get")
> public String get() {
> System.out.println("get");
> return "get";
> }
>
> @POST
> @Path(value = "/post")
> public String post(@QueryParam("param") String param) {
> System.out.println("post(" + param + ")");
> return "post(" + param + ")";
> }
>
> @PUT
> @Path(value = "/put")
> public String put(@QueryParam("param") String param) {
> System.out.println("put(" + param + ")");
> return "put(" + param + ")";
> }
> }
> --------------------------
>
> The following GET request works;
>
> curl -X GET -v -H "Accept: application/json" -H "Content-type:
> application/json"
> http://127.0.0.1:4204/testing-rest-0.0.1-SNAPSHOT/example/get
>
> The server prints out 'get' and also I get a response 'get'.
>
> However with either PUT or POST nothing is printed on the server and nothing
> is returned, with the following curl commands:
>
> curl -X POST -v -H "Accept: application/json" -H "Content-type:
> application/json" -d '{"param":"value"}'
> http://127.0.0.1:4204/testing-rest-0.0.1-SNAPSHOT/example/post
>
> curl -X PUT -v -H "Accept: application/json" -H "Content-type:
> application/json" -d '{"param":"value"}'
> http://127.0.0.1:4204/testing-rest-0.0.1-SNAPSHOT/example/put
>
> When I do call either POST or PUT I get the following (generic) output:
>
> -----------------
> * About to connect() to 127.0.0.1 port 4204 (#0)
> * Trying 127.0.0.1...
> * connected
> * Connected to 127.0.0.1 (127.0.0.1) port 4204 (#0)
> > POST /testing-rest-0.0.1-SNAPSHOT/example/post HTTP/1.1
> > User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0
> > OpenSSL/0.9.8r zlib/1.2.5
> > Host: 127.0.0.1:4204
> > Accept: application/json
> > Content-type: application/json
> > Content-Length: 17
> >
> * upload completely sent off: 17 out of 17 bytes
> < HTTP/1.1 200 OK
> < Content-Length: 0
> < Set-Cookie: EJBSESSIONID=cc51246f-9095-4a11-9f0e-ff8bc030fa7b; Path=/
> < Content-Type: text/html
> < Connection: close
> < Server: OpenEJB/4.6.0-SNAPSHOT Mac OS X/10.8.3 (x86_64)
> <
> * Closing connection #0
> ---------------------
>
> So it looks like it connected with the server but its not routing the request
> to the associated method. The end points I'm using in the curl put and post
> requests are the same as the get (apart from the last word).
>
> Is there anything obvious I'm doing wrong?
>
> Chris Christo
>
> ---
> Twitter: https://twitter.com/ChrisChristo7
> Tumblr: http://chrischristo7.tumblr.com
> LinkedIn: http://uk.linkedin.com/in/chrischristo
> GitHub: https://github.com/ChrisChristo
>