Java: Json in a Heroku project -


i'm exploring simple way: creating simple server:

public class simpleserver { public static void main(string args[]) {     serversocket s = null;     printwriter writer = null;     bufferedreader reader = null;     try {         s = new serversocket(9999);         system.out.println("server started, listen on "         + "port 9999");     } catch (ioexception e) {         e.printstacktrace();     }     while (true) {         try {             socket s1 = s.accept();              outputstream s1out = s1.getoutputstream();             bufferedwriter bw = new bufferedwriter             (new outputstreamwriter(s1out));             bw.write("hi client, server!");             system.out.println("messagge sent " +             s1.getinetaddress()+"--"+             s1.getinputstream()+"--"            );               bw.close();             s1.close();         } catch (ioexception e) {             e.printstacktrace();         }     } } 

}

but don't know how read header/body information! consider have receive http-post request, , need read info (they in json format)

i have web-based software pushes json file url (post). in heroku (dev in java), need to:

  • specify url
  • receive json
  • write content on postgresql

i pretty new java , heroku, i'm studying night , day need little help!

thanks!

if heroku provides full java ee 6 runtime:

receive json jax-rs - create pojo methods model rest-like service, annotate them jax-rs annotations @path, , set required environment ensure jax-rs loaded , enabled.

in jax-rs handler class, have environment inject entitymanager jpa2 provider hibernate, eclipselink, etc - whatever heroku offers on java appserver.

create instance of entity model class. populate json data received argument jax-rs method, either raw string, or decoded object using jersey's json support.

persist new instance of entity model class using entity manager, flush, , commit entity manager session.

the details of quite dependent on specifics of application server , runtime environment provided heroku. java ee 6 "standard" in same way railroad tracks "standard" .... standard want, you've got 7 choose from.

if heroku provides servlet container:

you can byo tools.

you won't have sort of injection, can plug in own tools guice, or portable cdi implementation weld.

you quite happily use jersy (for jax-rs) , hibernate. or use pgjdbc directly via servlet container's connection pool.

you can write own web service call methods directly servlets, way lies madness.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -