|
1 | 1 | package org.hpccsystems.ws.client;
|
2 | 2 |
|
3 | 3 | import java.io.ByteArrayInputStream;
|
| 4 | +import java.io.IOException; |
4 | 5 | import java.net.MalformedURLException;
|
5 | 6 | import java.net.URL;
|
6 | 7 | import java.nio.charset.StandardCharsets;
|
@@ -159,24 +160,44 @@ private String getTargetHPCCBuildVersionString() throws Exception
|
159 | 160 | if (wsconn == null)
|
160 | 161 | throw new Exception("Cannot get target HPCC build version, client connection has not been initialized.");
|
161 | 162 |
|
162 |
| - String response = wsconn.sendGetRequest("WsSMC/Activity?rawxml_");//throws |
| 163 | + String response = wsconn.sendGetRequest("WsSMC/Activity?rawxml_");//throws IOException if http != ok |
163 | 164 |
|
164 | 165 | if (response == null || response.isEmpty())
|
165 | 166 | throw new Exception("Cannot get target HPCC build version, received empty " + wsconn.getBaseUrl() + " wssmc/activity response");
|
166 | 167 |
|
| 168 | + String header = response.substring(0, 100).trim(); //crude, but can prevent wasteful overhead |
| 169 | + if (header.startsWith("<html")) |
| 170 | + throw new Exception("Received invalid HTML response, expected XML HPCC build version: \"" + header + "\"..."); |
| 171 | + |
167 | 172 | setUpBuildVersionParser();
|
168 | 173 |
|
| 174 | + String versionString = null; |
169 | 175 | Document document = null;
|
170 |
| - synchronized(m_XMLParser) |
| 176 | + try |
171 | 177 | {
|
172 |
| - document = m_XMLParser.parse(new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8))); |
| 178 | + synchronized(m_XMLParser) |
| 179 | + { |
| 180 | + document = m_XMLParser.parse(new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8))); |
| 181 | + } |
| 182 | + } |
| 183 | + catch (Exception e) |
| 184 | + { |
| 185 | + throw new Exception("Could not parse XML HPCC Version response: \"" + response.substring(0, 100) + "\"...", e); |
173 | 186 | }
|
174 | 187 |
|
175 | 188 | if (document == null)
|
176 |
| - throw new Exception("Cannot parse HPCC build version response."); |
| 189 | + throw new Exception("Could not parse XML HPCC Version response: \"" + response.substring(0, 100) + "\"..."); |
177 | 190 |
|
178 |
| - return (String) m_buildVersionXpathExpression.evaluate(document,XPathConstants.STRING); |
| 191 | + try |
| 192 | + { |
| 193 | + versionString = (String) m_buildVersionXpathExpression.evaluate(document,XPathConstants.STRING); |
| 194 | + } |
| 195 | + catch (XPathExpressionException e) |
| 196 | + { |
| 197 | + throw new Exception("Could not extract build version from HPCC Build/Version response: \"" + response + "\""); |
| 198 | + } |
179 | 199 |
|
| 200 | + return versionString; |
180 | 201 | }
|
181 | 202 |
|
182 | 203 | public SpanBuilder getWsClientSpanBuilder(String spanName)
|
|
0 commit comments