Mercurial Hosting > luan
annotate src/goodjava/webserver/examples/Params.java @ 1431:f3a417074cea
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 01 Dec 2019 18:41:51 -0700 |
parents | 27efb1fcbcb5 |
children | fa066aaa068c |
rev | line source |
---|---|
1402
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
1 package goodjava.webserver.examples; |
1143
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 import java.io.Writer; |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 import java.io.OutputStreamWriter; |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 import java.io.IOException; |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 import java.util.Map; |
1402
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
7 import goodjava.webserver.Handler; |
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
8 import goodjava.webserver.Request; |
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
9 import goodjava.webserver.Response; |
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
10 import goodjava.webserver.ResponseOutputStream; |
1143
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 public final class Params implements Handler { |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
15 public Response handle(Request request) { |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
16 Response response = new Response(); |
1165
668f29bc52ea
clean up content-type
Franklin Schmidt <fschmidt@gmail.com>
parents:
1148
diff
changeset
|
17 response.headers.put( "content-type", "text/plain; charset=utf-8" ); |
1143
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
18 try { |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
19 Writer writer = new OutputStreamWriter( new ResponseOutputStream(response) ); |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
20 for( Map.Entry<String,Object> entry : request.parameters.entrySet() ) { |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 writer.write(entry.getKey()+" = "+entry.getValue()+"\n"); |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 } |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 writer.close(); |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 } catch(IOException e) { |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 throw new RuntimeException(e); |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 } |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 return response; |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 } |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 } |