|
1 |
| package org.jconfig.server; |
|
2 |
| |
|
3 |
| import java.io.IOException; |
|
4 |
| import java.io.InputStream; |
|
5 |
| import java.net.Socket; |
|
6 |
| |
|
7 |
| public class Request { |
|
8 |
| |
|
9 |
| private InputStream input; |
|
10 |
| private String uri; |
|
11 |
| private String hostAddress; |
|
12 |
| |
|
13 |
0
| public Request(InputStream input) {
|
|
14 |
0
| this.input = input;
|
|
15 |
| } |
|
16 |
| |
|
17 |
0
| public void parse(Socket socket) {
|
|
18 |
| |
|
19 |
0
| StringBuffer request = new StringBuffer(2048);
|
|
20 |
0
| int i;
|
|
21 |
0
| byte[] buffer = new byte[2048];
|
|
22 |
0
| try {
|
|
23 |
0
| i = input.read(buffer);
|
|
24 |
| } |
|
25 |
| catch (IOException e) { |
|
26 |
0
| e.printStackTrace();
|
|
27 |
0
| i = -1;
|
|
28 |
| } |
|
29 |
0
| for (int j=0; j<i; j++) {
|
|
30 |
0
| request.append((char) buffer[j]);
|
|
31 |
| } |
|
32 |
0
| hostAddress = socket.getInetAddress().getHostAddress();
|
|
33 |
0
| uri = parseUri(request.toString());
|
|
34 |
| } |
|
35 |
| |
|
36 |
0
| private String parseUri(String requestString) {
|
|
37 |
0
| int index1, index2;
|
|
38 |
0
| index1 = requestString.indexOf(' ');
|
|
39 |
0
| if (index1 != -1) {
|
|
40 |
0
| index2 = requestString.indexOf(' ', index1 + 1);
|
|
41 |
0
| if (index2 > index1)
|
|
42 |
0
| return requestString.substring(index1 + 1, index2);
|
|
43 |
| } |
|
44 |
0
| return null;
|
|
45 |
| } |
|
46 |
| |
|
47 |
0
| public String getUri() {
|
|
48 |
0
| return uri;
|
|
49 |
| } |
|
50 |
| |
|
51 |
0
| public String getHostAddress() {
|
|
52 |
0
| return hostAddress;
|
|
53 |
| } |
|
54 |
| |
|
55 |
| } |