1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.metricshub.wbem.sblim.cimclient.internal.http;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 import java.io.IOException;
48 import java.io.InputStream;
49 import java.net.HttpURLConnection;
50 import org.metricshub.wbem.sblim.cimclient.internal.http.io.ASCIIPrintStream;
51
52
53
54
55
56 public class HttpServerMethod extends HttpMethod {
57 private String iMethodName;
58
59 private String iFile;
60
61 private String iProtocol;
62
63 private int iMinor, iMajor;
64
65 private int iStatus;
66
67 private String iReason;
68
69
70
71
72
73
74
75
76
77
78
79
80
81 public HttpServerMethod(int pMajor, int pMinor, int pStatus, String pReason) {
82 this.iMinor = pMinor;
83 this.iMajor = pMajor;
84 this.iStatus = pStatus;
85 this.iReason = pReason;
86 }
87
88
89
90
91
92
93
94
95
96 public HttpServerMethod(InputStream pReader) throws IOException, HttpException {
97 String line;
98
99 do {
100 line = HttpMethod.readLine(pReader);
101 } while (line == null || line.length() == 0);
102 int next = line.indexOf(' ');
103 int prev = 0;
104 if (next > -1) {
105 this.iMethodName = line.substring(0, next).toUpperCase();
106 if (this.iMethodName.equals("GET") && (line.indexOf(' ', next + 1) == -1)) {
107
108 this.iFile = line.substring(next + 1);
109 } else {
110 prev = next + 1;
111 next = line.indexOf(' ', prev);
112 this.iFile = line.substring(prev, next);
113
114 prev = next + 1;
115 this.iProtocol = line.substring(prev).toUpperCase();
116
117 prev = this.iProtocol.indexOf('/');
118 next = this.iProtocol.indexOf('.', prev + 1);
119 try {
120 this.iMajor = Integer.parseInt(this.iProtocol.substring(prev + 1, next));
121 this.iMinor = Integer.parseInt(this.iProtocol.substring(next + 1));
122 } catch (Exception e) {
123 throw new HttpException(HttpURLConnection.HTTP_BAD_METHOD, "Bad method");
124 }
125 }
126 } else throw new HttpException(HttpURLConnection.HTTP_BAD_METHOD, "Bad method");
127 }
128
129
130
131
132
133
134 public int getMajorVersion() {
135 return this.iMajor;
136 }
137
138
139
140
141
142
143 public int getMinorVersion() {
144 return this.iMinor;
145 }
146
147
148
149
150
151
152 public String getMethodName() {
153 return this.iMethodName;
154 }
155
156
157
158
159
160
161 public String getFile() {
162 return this.iFile;
163 }
164
165
166
167
168
169
170
171 public void write(ASCIIPrintStream pStream) {
172 pStream.print("HTTP/" + this.iMajor + "." + this.iMinor + " " + this.iStatus + " " + this.iReason + "\r\n");
173 }
174 }