tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris.Christo" <chris.chri...@mail.com>
Subject Trouble with POST & PUT with Rest
Date Tue, 04 Jun 2013 18:40:20 GMT
Hi,



(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


Mime
View raw message