|
9 | 9 | import extension.helpers.HttpUtil; |
10 | 10 | import extension.helpers.HttpUtil.DummyOutputStream; |
11 | 11 | import extension.helpers.StringUtil; |
| 12 | +import java.lang.UnsupportedOperationException; |
12 | 13 | import java.awt.event.ActionEvent; |
13 | 14 | import java.io.BufferedInputStream; |
14 | 15 | import java.io.ByteArrayOutputStream; |
@@ -78,7 +79,7 @@ protected void sendToServer(IHttpRequestResponse messageInfo) { |
78 | 79 | Properties prop = getExtendProperty(); |
79 | 80 | String useProxy = prop.getProperty("useProxy", SendToExtend.USE_CUSTOM_PROXY); |
80 | 81 | if (SendToExtend.USE_CUSTOM_PROXY.equals(useProxy)) { |
81 | | - sendToServerUseJDKClient(messageInfo); |
| 82 | + sendToServerUseHttpClient(messageInfo); |
82 | 83 | } else { |
83 | 84 | sendToServerUseBurpClient(messageInfo); |
84 | 85 | } |
@@ -131,124 +132,125 @@ public void run() { |
131 | 132 | } |
132 | 133 |
|
133 | 134 | protected void sendToServerUseJDKClient(IHttpRequestResponse messageInfo) { |
134 | | - Runnable sendTo = new Runnable() { |
135 | | - @Override |
136 | | - public void run() { |
137 | | - String boundary = HttpUtil.generateBoundary(); |
138 | | - HttpURLConnection conn = null; |
139 | | - try { |
140 | | - DummyOutputStream dummy = new DummyOutputStream(); |
141 | | - outMultipart(boundary, dummy, messageInfo); |
142 | | - int contentLength = dummy.getSize(); |
143 | | - |
144 | | - URL url = new URL(getTarget()); // 送信先 |
145 | | - // 拡張オプションを取得 |
146 | | - Properties prop = getExtendProperty(); |
147 | | - String proxyProtocol = prop.getProperty("proxyProtocol", Proxy.Type.DIRECT.name()); |
148 | | - Proxy proxy = Proxy.NO_PROXY; |
149 | | - if (!Proxy.Type.DIRECT.name().equals(proxyProtocol)) { |
150 | | - String proxyHost = prop.getProperty("proxyHost", ""); |
151 | | - if (Proxy.Type.HTTP.name().equals(proxyProtocol)) { |
152 | | - int proxyPort = ConvertUtil.parseIntDefault(prop.getProperty("proxyPort", "8080"), 8080); |
153 | | - SocketAddress addr = new InetSocketAddress(proxyHost, proxyPort); |
154 | | - proxy = new Proxy(Proxy.Type.HTTP, addr); |
155 | | - } |
156 | | - else if (Proxy.Type.SOCKS.name().equals(proxyProtocol)) { |
157 | | - int proxyPort = ConvertUtil.parseIntDefault(prop.getProperty("proxyPort", "1080"), 1080); |
158 | | - SocketAddress addr = new InetSocketAddress(proxyHost, proxyPort); |
159 | | - proxy = new Proxy(Proxy.Type.SOCKS, addr); |
160 | | - } |
161 | | - } |
162 | | - String proxyUser = prop.getProperty("proxyUser", ""); |
163 | | - String proxyPasswd = prop.getProperty("proxyPasswd", ""); |
164 | | - Authenticator authenticator = new Authenticator() { |
165 | | - @Override |
166 | | - protected PasswordAuthentication getPasswordAuthentication() { |
167 | | - return new PasswordAuthentication(proxyUser, proxyPasswd.toCharArray()); |
168 | | - } |
169 | | - }; |
170 | | -// if (!proxyUser.isEmpty()) { |
171 | | - Authenticator.setDefault(authenticator); |
| 135 | + throw new UnsupportedOperationException(); |
| 136 | +// Runnable sendTo = new Runnable() { |
| 137 | +// @Override |
| 138 | +// public void run() { |
| 139 | +// String boundary = HttpUtil.generateBoundary(); |
| 140 | +// HttpURLConnection conn = null; |
| 141 | +// try { |
| 142 | +// DummyOutputStream dummy = new DummyOutputStream(); |
| 143 | +// outMultipart(boundary, dummy, messageInfo); |
| 144 | +// int contentLength = dummy.getSize(); |
| 145 | +// |
| 146 | +// URL url = new URL(getTarget()); // 送信先 |
| 147 | +// // 拡張オプションを取得 |
| 148 | +// Properties prop = getExtendProperty(); |
| 149 | +// String proxyProtocol = prop.getProperty("proxyProtocol", Proxy.Type.DIRECT.name()); |
| 150 | +// Proxy proxy = Proxy.NO_PROXY; |
| 151 | +// if (!Proxy.Type.DIRECT.name().equals(proxyProtocol)) { |
| 152 | +// String proxyHost = prop.getProperty("proxyHost", ""); |
| 153 | +// if (Proxy.Type.HTTP.name().equals(proxyProtocol)) { |
| 154 | +// int proxyPort = ConvertUtil.parseIntDefault(prop.getProperty("proxyPort", "8080"), 8080); |
| 155 | +// SocketAddress addr = new InetSocketAddress(proxyHost, proxyPort); |
| 156 | +// proxy = new Proxy(Proxy.Type.HTTP, addr); |
| 157 | +// } |
| 158 | +// else if (Proxy.Type.SOCKS.name().equals(proxyProtocol)) { |
| 159 | +// int proxyPort = ConvertUtil.parseIntDefault(prop.getProperty("proxyPort", "1080"), 1080); |
| 160 | +// SocketAddress addr = new InetSocketAddress(proxyHost, proxyPort); |
| 161 | +// proxy = new Proxy(Proxy.Type.SOCKS, addr); |
| 162 | +// } |
| 163 | +// } |
| 164 | +// String proxyUser = prop.getProperty("proxyUser", ""); |
| 165 | +// String proxyPasswd = prop.getProperty("proxyPasswd", ""); |
| 166 | +// Authenticator authenticator = new Authenticator() { |
| 167 | +// @Override |
| 168 | +// protected PasswordAuthentication getPasswordAuthentication() { |
| 169 | +// return new PasswordAuthentication(proxyUser, proxyPasswd.toCharArray()); |
| 170 | +// } |
| 171 | +// }; |
| 172 | +//// if (!proxyUser.isEmpty()) { |
| 173 | +// Authenticator.setDefault(authenticator); |
| 174 | +//// } |
| 175 | +//// else { |
| 176 | +//// Authenticator.setDefault(null); |
| 177 | +//// } |
| 178 | +// |
| 179 | +//// boolean ignoreValidateCertification = ConvertUtil.parseBooleanDefault(prop.getProperty("ignoreValidateCertification", Boolean.TRUE.toString()), false); |
| 180 | +//// if (ignoreValidateCertification) { |
| 181 | +// HttpUtil.ignoreSocketFactory(); |
| 182 | +//// } |
| 183 | +// |
| 184 | +// conn = (HttpURLConnection) url.openConnection(proxy); |
| 185 | +// conn.setFixedLengthStreamingMode(contentLength); |
| 186 | +// conn.setRequestMethod("POST"); |
| 187 | +// conn.setDoOutput(true); |
| 188 | +// if (!proxyUser.isEmpty() && Proxy.Type.HTTP.name().equals(proxyProtocol)) { |
| 189 | +// byte [] basicAuth = Base64.getEncoder().encode(StringUtil.getBytesRaw(String.format("%s:%s", new Object [] {proxyUser, proxyPasswd}))); |
| 190 | +// conn.setRequestProperty("Authorization", "Basic " + StringUtil.getStringRaw(basicAuth)); |
172 | 191 | // } |
173 | | -// else { |
174 | | -// Authenticator.setDefault(null); |
| 192 | +// conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); |
| 193 | +// conn.connect(); |
| 194 | +// OutputStream ostm = null; |
| 195 | +// try { |
| 196 | +// ostm = conn.getOutputStream(); |
| 197 | +// outMultipart(boundary, ostm, messageInfo); |
| 198 | +// } catch (IOException e) { |
| 199 | +// fireSendToErrorEvent(new SendToEvent(this, e.getMessage())); |
| 200 | +// } catch (Exception e) { |
| 201 | +// fireSendToErrorEvent(new SendToEvent(this, e.getMessage())); |
| 202 | +// } finally { |
| 203 | +// if (ostm != null) { |
| 204 | +// ostm.close(); |
| 205 | +// } |
175 | 206 | // } |
176 | | - |
177 | | -// boolean ignoreValidateCertification = ConvertUtil.parseBooleanDefault(prop.getProperty("ignoreValidateCertification", Boolean.TRUE.toString()), false); |
178 | | -// if (ignoreValidateCertification) { |
179 | | - HttpUtil.ignoreSocketFactory(); |
| 207 | +// |
| 208 | +// InputStream istm = conn.getInputStream(); |
| 209 | +// ByteArrayOutputStream bostm = new ByteArrayOutputStream(); |
| 210 | +// try { |
| 211 | +// BufferedInputStream bistm = new BufferedInputStream(istm); |
| 212 | +// String decodeMessage; |
| 213 | +// byte buf[] = new byte[4096]; |
| 214 | +// int len; |
| 215 | +// while ((len = bistm.read(buf)) != -1) { |
| 216 | +// bostm.write(buf, 0, len); |
| 217 | +// } |
| 218 | +// int statusCode = conn.getResponseCode(); |
| 219 | +// decodeMessage = StringUtil.getBytesRawString(bostm.toByteArray()); |
| 220 | +// if (statusCode == HttpURLConnection.HTTP_OK) { |
| 221 | +// if (decodeMessage.length() == 0) { |
| 222 | +// fireSendToCompleteEvent(new SendToEvent(this, "Success[" + statusCode + "]")); |
| 223 | +// } else { |
| 224 | +// fireSendToWarningEvent(new SendToEvent(this, "Warning[" + statusCode + "]:" + decodeMessage)); |
| 225 | +// } |
| 226 | +// } else { |
| 227 | +// // 200以外 |
| 228 | +// fireSendToErrorEvent(new SendToEvent(this, "Error[" + statusCode + "]:" + decodeMessage)); |
| 229 | +// } |
| 230 | +// |
| 231 | +// } catch (IOException e) { |
| 232 | +// fireSendToErrorEvent(new SendToEvent(this, "Error[" + e.getClass().getName() + "]:" + e.getMessage())); |
| 233 | +// } finally { |
| 234 | +// if (istm != null) { |
| 235 | +// istm.close(); |
| 236 | +// } |
| 237 | +// if (bostm != null) { |
| 238 | +// bostm.close(); |
| 239 | +// } |
180 | 240 | // } |
181 | | - |
182 | | - conn = (HttpURLConnection) url.openConnection(proxy); |
183 | | - conn.setFixedLengthStreamingMode(contentLength); |
184 | | - conn.setRequestMethod("POST"); |
185 | | - conn.setDoOutput(true); |
186 | | - if (!proxyUser.isEmpty() && Proxy.Type.HTTP.name().equals(proxyProtocol)) { |
187 | | - byte [] basicAuth = Base64.getEncoder().encode(StringUtil.getBytesRaw(String.format("%s:%s", new Object [] {proxyUser, proxyPasswd}))); |
188 | | - conn.setRequestProperty("Authorization", "Basic " + StringUtil.getStringRaw(basicAuth)); |
189 | | - } |
190 | | - conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); |
191 | | - conn.connect(); |
192 | | - OutputStream ostm = null; |
193 | | - try { |
194 | | - ostm = conn.getOutputStream(); |
195 | | - outMultipart(boundary, ostm, messageInfo); |
196 | | - } catch (IOException e) { |
197 | | - fireSendToErrorEvent(new SendToEvent(this, e.getMessage())); |
198 | | - } catch (Exception e) { |
199 | | - fireSendToErrorEvent(new SendToEvent(this, e.getMessage())); |
200 | | - } finally { |
201 | | - if (ostm != null) { |
202 | | - ostm.close(); |
203 | | - } |
204 | | - } |
205 | | - |
206 | | - InputStream istm = conn.getInputStream(); |
207 | | - ByteArrayOutputStream bostm = new ByteArrayOutputStream(); |
208 | | - try { |
209 | | - BufferedInputStream bistm = new BufferedInputStream(istm); |
210 | | - String decodeMessage; |
211 | | - byte buf[] = new byte[4096]; |
212 | | - int len; |
213 | | - while ((len = bistm.read(buf)) != -1) { |
214 | | - bostm.write(buf, 0, len); |
215 | | - } |
216 | | - int statusCode = conn.getResponseCode(); |
217 | | - decodeMessage = StringUtil.getBytesRawString(bostm.toByteArray()); |
218 | | - if (statusCode == HttpURLConnection.HTTP_OK) { |
219 | | - if (decodeMessage.length() == 0) { |
220 | | - fireSendToCompleteEvent(new SendToEvent(this, "Success[" + statusCode + "]")); |
221 | | - } else { |
222 | | - fireSendToWarningEvent(new SendToEvent(this, "Warning[" + statusCode + "]:" + decodeMessage)); |
223 | | - } |
224 | | - } else { |
225 | | - // 200以外 |
226 | | - fireSendToErrorEvent(new SendToEvent(this, "Error[" + statusCode + "]:" + decodeMessage)); |
227 | | - } |
228 | | - |
229 | | - } catch (IOException e) { |
230 | | - fireSendToErrorEvent(new SendToEvent(this, "Error[" + e.getClass().getName() + "]:" + e.getMessage())); |
231 | | - } finally { |
232 | | - if (istm != null) { |
233 | | - istm.close(); |
234 | | - } |
235 | | - if (bostm != null) { |
236 | | - bostm.close(); |
237 | | - } |
238 | | - } |
239 | | - } catch (IOException ex) { |
240 | | - fireSendToErrorEvent(new SendToEvent(this, "Error[" + ex.getClass().getName() + "]:" + ex.getMessage())); |
241 | | - } catch (Exception ex) { |
242 | | - fireSendToErrorEvent(new SendToEvent(this, "Error[" + ex.getClass().getName() + "]:" + ex.getMessage())); |
243 | | - } finally { |
244 | | - if (conn != null) { |
245 | | - conn.disconnect(); |
246 | | - } |
247 | | - } |
248 | | - } |
249 | | - |
250 | | - }; |
251 | | - this.threadExecutor.submit(sendTo); |
| 241 | +// } catch (IOException ex) { |
| 242 | +// fireSendToErrorEvent(new SendToEvent(this, "Error[" + ex.getClass().getName() + "]:" + ex.getMessage())); |
| 243 | +// } catch (Exception ex) { |
| 244 | +// fireSendToErrorEvent(new SendToEvent(this, "Error[" + ex.getClass().getName() + "]:" + ex.getMessage())); |
| 245 | +// } finally { |
| 246 | +// if (conn != null) { |
| 247 | +// conn.disconnect(); |
| 248 | +// } |
| 249 | +// } |
| 250 | +// } |
| 251 | +// |
| 252 | +// }; |
| 253 | +// this.threadExecutor.submit(sendTo); |
252 | 254 | } |
253 | 255 |
|
254 | 256 | protected void sendToServerUseHttpClient(IHttpRequestResponse messageInfo) { |
|
0 commit comments