Skip to content

Commit f989a40

Browse files
authored
HPCC4J-631 Provide meaningful version error message (#741)
Signed-off-by: Rodrigo Pastrana <[email protected]>
1 parent 9162574 commit f989a40

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

wsclient/src/main/java/org/hpccsystems/ws/client/BaseHPCCWsClient.java

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.hpccsystems.ws.client;
22

33
import java.io.ByteArrayInputStream;
4+
import java.io.IOException;
45
import java.net.MalformedURLException;
56
import java.net.URL;
67
import java.nio.charset.StandardCharsets;
@@ -159,24 +160,44 @@ private String getTargetHPCCBuildVersionString() throws Exception
159160
if (wsconn == null)
160161
throw new Exception("Cannot get target HPCC build version, client connection has not been initialized.");
161162

162-
String response = wsconn.sendGetRequest("WsSMC/Activity?rawxml_");//throws
163+
String response = wsconn.sendGetRequest("WsSMC/Activity?rawxml_");//throws IOException if http != ok
163164

164165
if (response == null || response.isEmpty())
165166
throw new Exception("Cannot get target HPCC build version, received empty " + wsconn.getBaseUrl() + " wssmc/activity response");
166167

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+
167172
setUpBuildVersionParser();
168173

174+
String versionString = null;
169175
Document document = null;
170-
synchronized(m_XMLParser)
176+
try
171177
{
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);
173186
}
174187

175188
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) + "\"...");
177190

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+
}
179199

200+
return versionString;
180201
}
181202

182203
public SpanBuilder getWsClientSpanBuilder(String spanName)

0 commit comments

Comments
 (0)