|
5 | 5 | import java.io.BufferedReader;
|
6 | 6 | import java.io.IOException;
|
7 | 7 | import java.io.InputStreamReader;
|
| 8 | +import java.net.HttpURLConnection; |
8 | 9 | import java.net.MalformedURLException;
|
9 | 10 | import java.net.URL;
|
10 | 11 | import java.net.URLConnection;
|
@@ -107,38 +108,63 @@ public void runTest() {
|
107 | 108 | try {
|
108 | 109 | final String context = "/mayaa-" + versions[i];
|
109 | 110 | URL url = new URL("http", "localhost", 8080, context + path);
|
110 |
| - URLConnection connection = url.openConnection(); |
111 |
| - |
112 |
| - InputStreamReader reader = new InputStreamReader(connection.getInputStream()); |
113 |
| - BufferedReader br = new BufferedReader(reader); |
| 111 | + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
114 | 112 |
|
115 | 113 | StringBuilder buf = new StringBuilder();
|
116 |
| - // PathAdjusterが動作した部分を吸収 |
117 |
| - br.lines() |
118 |
| - .map(e -> e.replace(context, "/MAYAA")) |
119 |
| - .forEach(e -> buf.append(e)); |
120 | 114 |
|
121 |
| - String content = buf.toString(); |
| 115 | + // ステータスコードを取得 |
| 116 | + int statusCode = connection.getResponseCode(); |
| 117 | + |
| 118 | + // ステータスコードが200以外の場合もエラーストリームを取得 |
| 119 | + if (statusCode >= 200 && statusCode < 300) { |
| 120 | + try (InputStreamReader r = new InputStreamReader(connection.getInputStream()); |
| 121 | + BufferedReader br = new BufferedReader(r)) { |
122 | 122 |
|
123 |
| - // 1.1系でのXML宣言直後の連続する改行コードを1つに補正 |
124 |
| - content = content.replace("?>\n\n", "?>\n"); |
| 123 | + // PathAdjusterが動作した部分を吸収 |
| 124 | + br.lines() |
| 125 | + .map(e -> e.replace(context, "/MAYAA")) |
| 126 | + .forEach(e -> buf.append(e)); |
125 | 127 |
|
126 |
| - // /tests/customtag/replace_injection_attribute.html のみv1.1.34にてなぜか閉じタグ</html> が </xml:html> となっているのを吸収 |
127 |
| - content = content.replace("</xml:html>", "</html>"); |
128 | 128 |
|
129 |
| - results.add(Arrays.asList(content.split("\n"))); |
| 129 | + String content = buf.toString(); |
| 130 | + // 1.1系でのXML宣言直後の連続する改行コードを1つに補正 |
| 131 | + content = content.replace("?>\n\n", "?>\n"); |
| 132 | + |
| 133 | + // /tests/customtag/replace_injection_attribute.html のみv1.1.34にてなぜか閉じタグ</html> が </xml:html> となっているのを吸収 |
| 134 | + content = content.replace("</xml:html>", "</html>"); |
| 135 | + |
| 136 | + results.add(Arrays.asList(content.split("\n"))); |
| 137 | + } catch (IOException e) { |
| 138 | + System.err.println("IOException:" + path); |
| 139 | + } |
| 140 | + } else { |
| 141 | + try (InputStreamReader r = new InputStreamReader(connection.getErrorStream()); |
| 142 | + BufferedReader br = new BufferedReader(r)) { |
130 | 143 |
|
| 144 | + // エラーメッセージの行だけを取得する |
| 145 | + br.lines() |
| 146 | + .filter(e -> e.contains("id=\"exception-message\"")) |
| 147 | + .forEach(e -> buf.append(e)); |
| 148 | + |
| 149 | + String content = buf.toString(); |
| 150 | + results.add(Arrays.asList(content.split("\n"))); |
| 151 | + } catch (IOException e) { |
| 152 | + System.err.println("IOException:" + path); |
| 153 | + } |
| 154 | + } |
| 155 | + if (results.size() == 2) { |
| 156 | + assertArrayEquals(results.get(0).toArray(), results.get(1).toArray(), path); |
| 157 | + System.err.println("OK:" + path); |
| 158 | + } |
| 159 | + |
131 | 160 | } catch (MalformedURLException e) {
|
132 |
| - System.err.println(path); |
| 161 | + System.err.println("MalformedURLException:" + path); |
133 | 162 | } catch (IOException e) {
|
134 |
| - System.err.println(path); |
| 163 | + System.err.println("IOException:" + path); |
135 | 164 | } finally {
|
136 | 165 | //
|
137 | 166 | }
|
138 | 167 | }
|
139 |
| - if (results.size() == 2) { |
140 |
| - assertArrayEquals(results.get(0).toArray(), results.get(1).toArray(), path); |
141 |
| - } |
142 | 168 | }
|
143 | 169 | }
|
144 | 170 | }
|
0 commit comments