| | |
| | | package com.ycl.api.HK; |
| | | |
| | | import com.ycl.platform.domain.result.OSDResult; |
| | | import com.ycl.utils.StringUtils; |
| | | import constant.ApiConstants; |
| | | import enumeration.DeviceType; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.auth.AuthScope; |
| | |
| | | if (OSDString == null) return null; |
| | | |
| | | //解析xml |
| | | parseXMl(OSDString, "TextOverlay", "displayText", osdResult, null,ip); |
| | | parseXMl(OSDString, "TextOverlay", "displayText", osdResult, null, ip); |
| | | //获取Time |
| | | String timeString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_TIME, userName, password); |
| | | if (timeString == null) return null; |
| | | |
| | | Date date = new Date(); |
| | | //解析xml |
| | | parseXMl(timeString, "Time", "localTime", osdResult, date,ip); |
| | | parseXMl(timeString, "Time", "localTime", osdResult, date, ip); |
| | | osdResult.setDeviceBrand(DeviceType.HK.getType()); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | return osdResult; |
| | | } |
| | | |
| | | private static void parseXMl(String OSDString, String tagName1, String tagName2, OSDResult osdResult, Date date,String ip) throws ParserConfigurationException, SAXException, IOException { |
| | | private static void parseXMl(String OSDString, String tagName1, String tagName2, OSDResult osdResult, Date date, String ip) throws ParserConfigurationException, SAXException, IOException { |
| | | |
| | | try { |
| | | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
| | |
| | | if (node.getNodeType() == Node.ELEMENT_NODE && "TextOverlay".equals(tagName1)) { |
| | | Element element = (Element) node; |
| | | String textContent = element.getElementsByTagName(tagName2).item(0).getTextContent(); |
| | | // log.info("TEXT : " + textContent); |
| | | // log.info("TEXT : " + textContent); |
| | | if (i == 0) { |
| | | osdResult.setOSD1(textContent); |
| | | } else if (i == 1) { |
| | |
| | | } else if (node.getNodeType() == Node.ELEMENT_NODE && "Time".equals(tagName1)) { |
| | | Element element = (Element) node; |
| | | String textContent = element.getElementsByTagName(tagName2).item(0).getTextContent(); |
| | | // log.info("TEXT : " + textContent); |
| | | // log.info("TEXT : " + textContent); |
| | | osdResult.setCheckTime(date); |
| | | OffsetDateTime dateTime = OffsetDateTime.parse(textContent); |
| | | // 将OffsetDateTime转换为Date对象 |
| | |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("ip:{}出现异常,{}",ip,e.getMessage()); |
| | | throw new RuntimeException(e.getMessage()); |
| | | log.error("ip:{}出现异常,{}", ip, e.getMessage()); |
| | | throw new RuntimeException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | // 设置请求配置 |
| | | RequestConfig requestConfig = RequestConfig.custom() |
| | | .setConnectTimeout(1000) |
| | | .setSocketTimeout(1000) |
| | | .setConnectTimeout(3000) |
| | | .setSocketTimeout(3000) |
| | | .build(); |
| | | httpGet.setConfig(requestConfig); |
| | | try (CloseableHttpResponse response = httpClient.execute(httpGet)) { |