• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sending java Object to REST web services.

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@swapnil kachave; You mean when you send primitive types only it work ok? Can you post the exception from the server's log?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is the service which is supposed to receive this Object defined?

Which RESTful service toolkit are you using?

Bill
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello , I am also facing the same problem that how can I send a BitSet or rather any other java object as parameter to a REST service.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since BitSet is Serializable, you can serialize it to a byte[] and send that. See java.io.ObjectOutputStream.

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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
reply
    Bookmark Topic Watch Topic
  • New Topic