Re: [Simpleweb-Support] Accessing Variables from within a handle
Brought to you by:
niallg
From: -=}\\*/{=- <rui...@gm...> - 2013-02-06 05:24:49
|
i did not understand the question... at all. ... what do you call "handle"? what "interfaces" are you talking about? maybe i'am too sleepy here (3 am), but this piece of code seams just fine to me... it actually compiles here, your bug, whatever may be, is probably somewhere else. ... appears to me that you should read something like: http://www.mindview.net/Books/TIJ/ []r. this compile just fine: import java.io.PrintStream; import java.net.InetSocketAddress; import java.net.SocketAddress; import org.simpleframework.http.Request; import org.simpleframework.http.Response; import org.simpleframework.http.core.Container; import org.simpleframework.http.core.ContainerServer; import org.simpleframework.transport.Server; import org.simpleframework.transport.connect.Connection; import org.simpleframework.transport.connect.SocketConnection; public class http_responder implements Container { private http_responder container; private Server server; private Connection connection; private SocketAddress address; private Object horsecounter; public void handle(Request request, Response response) { try { PrintStream body = response.getPrintStream(); long time = System.currentTimeMillis(); response.setValue("Content-Type", "text/plain"); response.setValue("Server", "HelloWorld/1.0 (Simple 5.0.4)"); response.setDate("Date", time); response.setDate("Last-Modified", time); body.println("Horses in Barn: " + horsecounter);//.GetNumberOfHorses()); body.close(); } catch(Exception e) { e.printStackTrace(); } } public void serveit(Object horsecounter) throws Exception { this.container = new http_responder(); this.server = new ContainerServer((Container) container); this.connection = new SocketConnection(server); this.address = new InetSocketAddress(8080); this.horsecounter = horsecounter; this.connection.connect(address); } } On 2 February 2013 03:43, Lisa Carver <car...@ym...> wrote: > I'm using the simpleframework for a little utility. > > Here's the scenario. > > In one thread I have a horse counter. It keeps track of how many horses > are in a barn. > > In the other thread I have the simple webserver. > > public class http_responder implements Container { > private http_responder container; > private Server server; > private Connection connection; > private SocketAddress address; > private HorseCounter horsecounter; > > public void handle(Request request, Response response) { > try { > PrintStream body = response.getPrintStream(); > long time = System.currentTimeMillis(); > > response.setValue("Content-Type", "text/plain"); > response.setValue("Server", "HelloWorld/1.0 (Simple 5.0.4)"); > response.setDate("Date", time); > response.setDate("Last-Modified", time); > body.println("Horses in Barn: " + > horsecounter.GetNumberOfHorses()); > body.close(); > } catch(Exception e) { > e.printStackTrace(); > } > } > > public void serveit(HorseCounter horsecounter) throws Exception { > this.container = new http_responder(); > this.server = new ContainerServer((Container) container); > this.connection = new SocketConnection(server); > this.address = new InetSocketAddress(8080); > this.horsecounter = horsecounter; > this.connection.connect(address); > > } > > } > My question is: How do I get my horsecounter passed into the handle? > > I tried passing it as a variable to the serveit method, but I just figured > out that interfaces can't hold variables. (I'm new to Java) It makes > sense to me why it didn't work, but I'm still in the dark as to how to > serve up dynamic content using variables in my running application. > > I've looked through the JavaDocs, but I got overwhelmed pretty quickly. > Would you mind pointing me in the right direction? > > > ------------------------------------------------------------------------------ > Everyone hates slow websites. So do we. > Make your web apps faster with AppDynamics > Download AppDynamics Lite for free today: > http://p.sf.net/sfu/appdyn_d2d_jan > _______________________________________________ > Simpleweb-Support mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simpleweb-support > > |