I created rest web services.
I can pass String ,int to REST web services.
But when i go for passing custom object to services it throw "500 Exception".
I am not getting what is exact error.
can any on help me.
Thanks in Advance
Lester Burnham
Rancher
Joined: Oct 14, 2008
Posts: 1337
posted
0
One of the main points of web services is their cross-platform compatibility. While I'm not quite sure what you mean by "custom object", and you don't mention how you're trying to send that, is sounds like a serialized Java object, which throws away this major advantage.
Jim Akmer
Ranch Hand
Joined: Jul 06, 2010
Posts: 104
posted
0
@swapnil kachave; You mean when you send primitive types only it work ok? Can you post the exception from the server's log?
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
1
posted
0
How is the service which is supposed to receive this Object defined?
However, unless this is a totally in-house service in which both server and client are under your control, you will probably eventually regret not using a more general format.
Bill
Alok Bhandari
Greenhorn
Joined: Jun 11, 2008
Posts: 15
posted
0
Hello William thanks for reply.What I am confused about is if I can have servlet and pass to it a java object through objectOutputStream and ObjectInputSteam,then Shall I go with servlet or have a REST service for this?
Thanks
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
1
posted
0
IF you have a servlet that accepts a serialized object, you in fact have a start on a RESTful service - it is that simple, no toolkit required.
A servlet will be the entry point for any RESTful service since handling HTTP methods is what is required and thats what servlets are designed for.
Bill
Alok Bhandari
Greenhorn
Joined: Jun 11, 2008
Posts: 15
posted
0
Hello Bill,
thanks for the reply , what I understand from your reply is that I can use REST service instead of servlet in this scenario and it gives me the same bahaviour as I expect.I just have one small query can you tell me what MIME type should be specified in "consumes" tag for accepting the java object as an input.And if you have link to any good tutorial for this then please can you send its link to me.thanks for your time and reply.
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
1
posted
0
I'm assuming you are using a toolkit like jersey that uses Java annotations to map requests to methods. In order to route the request to the right method, the mime type should match the type you specify in the request headers.
A content type of "application/octet-stream" seems pretty general.
Bill
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: sending java Object to REST web services.