Наш код веб-службы пытается подключиться к службе Windows (возвращает XML-ответ), и мы все же иногда получаем недопустимые исключения XML-ответа.Ниже приведены исключения, которые мы видим в трассировке стека.
java.net.SocketTimeoutException: Тайм-аут чтения
SAXParseException: преждевременное завершение файла.
Здесьэто наш старый кодПомимо отсутствующего ВРЕМЕНИ СОЕДИНЕНИЯ РОЗЕТКИ в улове, есть и другие рекомендации.readtimeout = 275000
try {
URL u = new URL(targetURL);
HttpURLConnection connection = (HttpURLConnection)u.openConnection();
proertyName = Constant.READTIMEOUT;
Integer timeOut = Integer.parseInt(dynamicLookup
.lookup(Constant.READTIMEOUT));
connection.setReadTimeout(timeOut);
String str = "&Id=" + xID;
urlParameters += str;
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Length", Integer.valueOf(urlParameters.getBytes().length).toString());
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
inputStream = connection.getInputStream();
}
catch (MalformedURLException exception) {
log.error(ex.toString(), ex);
throw ex;
}
catch (IOException exception) {
log.error(ex.toString(), ex);
throw ex;
}
catch (NumberFormatException exception) {
log.error(ex);
throw ex;
}
Чтение входных потоков
outputXMLString = IOUtils.toString(inputStream);
inputStream = new ByteArrayInputStream(outputXMLString.getBytes());
return Handler.unMarshal(inputStream);//JAXB unmarshalling