Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

can object send through HTTP protocol?

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a client API that will send user object to server using HTTP protocol. A Listener Daemon program will listen to port 80 and base on different incoming type of object, it will determine the next step to do.
Is this workable, allow ???
 
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by cb poo:
I have a client API that will send user object to server using HTTP protocol. A Listener Daemon program will listen to port 80 and base on different incoming type of object, it will determine the next step to do.
Is this workable, allow ???



HTTP is a text based protocol, so to send objects you will need to serialize them into text. There are tools that will serialize java objects to XML.
 
cb poo
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then for my server program, how detect different type of object after serialize?
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by cb poo:
Then for my server program, how detect different type of object after serialize?


It really just depends on how you decide to implement it. Say you want to pass in a Car object with a capacity and color, you could have the client send the following XML as a String:


When the server receives this, it can parse it using JDOM (or whatever suits) and extract all the relevant information easily, including object type. You could write the code to do all this conversion yourself, or use any of the standard APIs, whichever you're more comfortable with.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can serialize a Java object across HTTP using java.net.URLConnection. Get the URLConnection's output stream and wrap it with a java.io.ObjectOutputStream. As for determining what object you have on the server side, it isn't the best design or most efficient method, but you could always use the instanceof operator.
 
cb poo
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
looks like XML is a better and flexible approach. Then I will take this. Thanks guys.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic