[Simpleweb-Support] Tutorial Update
Brought to you by:
niallg
From: Bngfnvn N. <tes...@ya...> - 2016-01-06 13:10:19
|
Hi everyone, while updating I too noticed the few name changes and was not immediately able to follow. Anyway since the tutorial has not yet been updated I just want to post an updated version here: 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.ContainerSocketProcessor;import org.simpleframework.transport.SocketProcessor;import org.simpleframework.transport.connect.Connection;import org.simpleframework.transport.connect.SocketConnection; public class HelloWorld implements Container { 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 6.0.1)"); response.setDate("Date", time); response.setDate("Last-Modified", time); body.println("Hello World"); body.close(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] list) throws Exception { Container container = new HelloWorld(); SocketProcessor server = new ContainerSocketProcessor(container); Connection connection = new SocketConnection(server); SocketAddress address = new InetSocketAddress(8080); connection.connect(address); }} The only things that has changed are:Lines8+9from:import org.simpleframework.http.core.ContainerServer;import org.simpleframework.transport.Server;to:import org.simpleframework.http.core.ContainerSocketProcessor;import org.simpleframework.transport.SocketProcessor; and Line34from:Server server = new ContainerServer(container);to:SocketProcessor server = new ContainerSocketProcessor(container); also for the completionistsLine21from:response.setValue("Server", "HelloWorld/1.0 (Simple 4.0)");to:response.setValue("Server", "HelloWorld/1.0 (Simple 6.0.1)"); ;) The same changes apply to the "Asynchronous services" example at the end. And one other minor error:int length = request.getContentLength();should be a long because getContentLength() returns a long. On a side note. I of course found my way to the tutorial through Google but could it be that there ist no link from the homepage to the tutorial? Enough nagging from me.Thanks for this awesome framework! Best regards. |