List of usage examples for org.xml.sax InputSource setCharacterStream
public void setCharacterStream(Reader characterStream)
From source file:fi.csc.emrex.smp.ThymeController.java
@RequestMapping(value = "/onReturn", method = RequestMethod.POST) public String onReturnelmo(@ModelAttribute ElmoData request, Model model, @CookieValue(value = "elmoSessionId") String sessionIdCookie, @CookieValue(value = "chosenNCP") String chosenNCP, //@CookieValue(value = "chosenCert") String chosenCert, HttpServletRequest httpRequest) throws Exception { String sessionId = request.getSessionId(); String elmo = request.getElmo(); Person person = (Person) context.getSession().getAttribute("shibPerson"); if (person == null) { ShibbolethHeaderHandler headerHandler = new ShibbolethHeaderHandler(httpRequest); log.debug(headerHandler.stringifyHeader()); person = headerHandler.generatePerson(); context.getSession().setAttribute("shibPerson", person); }/*from w ww.j av a 2 s. c om*/ String source = "SMP"; String personalLogLine = generatePersonalLogLine(httpRequest, person, source); log.info(request.getReturnCode()); if (!"NCP_OK".equalsIgnoreCase(request.getReturnCode())) { log.error("NCP not OK"); if ("NCP_NO_RESULTS".equalsIgnoreCase(request.getReturnCode())) { model.addAttribute("message", "No courses found on NCP."); log.error("No courses found on NCP."); } if ("NCP_CANCEL".equalsIgnoreCase(request.getReturnCode())) { model.addAttribute("message", "User cancelled transfer on NCP."); log.error("User cancelled transfer on NCP."); } if ("NCP_ERROR".equalsIgnoreCase(request.getReturnCode())) { model.addAttribute("message", "Error on NCP."); log.error("Error on NCP."); } return abort(model); } log.info("NCP OK!"); if (elmo == null || elmo.isEmpty()) { PersonalLogger.log(personalLogLine + "\tfailed"); log.error("ELMO-xml empy or null."); return abort(model); } String ncpPubKey = this.getCertificate(chosenNCP); final String decodedXml; final boolean verifySignatureResult; try { final byte[] bytes = DatatypeConverter.parseBase64Binary(elmo); decodedXml = GzipUtil.gzipDecompress(bytes); verifySignatureResult = signatureVerifier.verifySignatureWithDecodedData(ncpPubKey, decodedXml, StandardCharsets.UTF_8); log.info("Verify signature result: {}", verifySignatureResult); log.info("providedSessionId: {}", sessionId); FiSmpApplication.verifySessionId(sessionId, sessionIdCookie); } catch (Exception e) { log.error("Session verification failed", e); model.addAttribute("error", "Session verification failed"); PersonalLogger.log(personalLogLine + "\tfailed"); return "error"; } try { if (!verifySignatureResult) { log.error("NCP signature check failed"); model.addAttribute("error", "NCP signature check failed"); PersonalLogger.log(personalLogLine + "\tfailed"); return "error"; } } catch (Exception e) { log.error("NCP verification failed", e); model.addAttribute("error", "NCP verification failed"); PersonalLogger.log(personalLogLine + "\tfailed"); return "error"; } log.info("Returned elmo XML " + decodedXml); context.getSession().setAttribute("elmoxmlstring", decodedXml); ElmoParser parser = ElmoParser.elmoParser(decodedXml); try { byte[] pdf = parser.getAttachedPDF(); context.getSession().setAttribute("pdf", pdf); } catch (Exception e) { log.error("EMREX transcript missing."); model.addAttribute("error", "EMREX transcript missing."); PersonalLogger.log(personalLogLine + "\tfailed"); return "error"; } model.addAttribute("elmoXml", decodedXml); Document document; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); //Get the DOM Builder DocumentBuilder builder; if (person != null) { List<VerifiedReport> results = new ArrayList<>(); try { builder = factory.newDocumentBuilder(); StringReader sr = new StringReader(decodedXml); final InputSource inputSource = new InputSource(); inputSource.setEncoding(StandardCharsets.UTF_8.name()); inputSource.setCharacterStream(sr); //person.setFirstName("test"); person.setLastName("user"); //person.setHomeOrganizationName("test institution"); //Load and Parse the XML document //document contains the complete XML as a Tree. document = builder.parse(inputSource); NodeList reports = document.getElementsByTagName("report"); for (int i = 0; i < reports.getLength(); i++) { VerifiedReport vr = new VerifiedReport(); Element report = (Element) reports.item(i); vr.setReport(nodeToString(report)); Person elmoPerson = getUserFromElmoReport((Element) report.getParentNode()); if (elmoPerson != null) { VerificationReply verification = VerificationReply.verify(person, elmoPerson, verificationThreshold); log.info("Verification messages: " + verification.getMessages()); log.info("VerScore: " + verification.getScore()); vr.setVerification(verification); } else { vr.addMessage("Elmo learner missing"); //TODO fix this } results.add(vr); } context.getSession().setAttribute("reports", results); model.addAttribute("reports", results); } catch (ParserConfigurationException | IOException | SAXException ex) { log.error("Error in report verification", ex); model.addAttribute("error", ex.getMessage()); PersonalLogger.log(personalLogLine + "\tfailed"); return "error"; } } else { model.addAttribute("error", "HAKA login missing"); PersonalLogger.log(personalLogLine + "\tfailed"); return "error"; } PersonalLogger.log(personalLogLine + "\tokay"); return "review"; }
From source file:org.dklisiaris.downtown.helper.XMLParser.java
public Document getDomElement(String xml) { Document doc = null;/* w w w . j av a 2 s . c o m*/ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); doc = db.parse(is); } catch (ParserConfigurationException e) { Log.e("Error: ", e.getMessage()); return null; } catch (SAXException e) { Log.e("Error: ", e.getMessage()); return null; } catch (IOException e) { Log.e("Error: ", e.getMessage()); return null; } // return DOM return doc; }
From source file:com.vkassin.mtrade.Common.java
public static String generalWebServiceCall(String urlStr, ContentHandler handler) { String errorMsg = ""; try {/*from w w w. j a v a 2 s . com*/ URL url = new URL(urlStr); HttpURLConnection urlc = (HttpURLConnection) url.openConnection(); urlc.setRequestProperty("User-Agent", "Android Application: aMTrade"); urlc.setRequestProperty("Connection", "close"); // urlc.setRequestProperty("Accept-Charset", "windows-1251"); // urlc.setRequestProperty("Accept-Charset", // "windows-1251,utf-8;q=0.7,*;q=0.7"); urlc.setRequestProperty("Accept-Charset", "utf-8"); urlc.setConnectTimeout(1000 * 5); // mTimeout is in seconds urlc.setDoInput(true); urlc.connect(); if (urlc.getResponseCode() == HttpURLConnection.HTTP_OK) { // Get a SAXParser from the SAXPArserFactory. SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); // Get the XMLReader of the SAXParser we created. XMLReader xr = sp.getXMLReader(); // Apply the handler to the XML-Reader xr.setContentHandler(handler); // Parse the XML-data from our URL. InputStream is = urlc.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(500); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } ByteArrayInputStream bais = new ByteArrayInputStream(baf.toByteArray()); // Reader isr = new InputStreamReader(bais, "windows-1251"); Reader isr = new InputStreamReader(bais, "utf-8"); InputSource ist = new InputSource(); // ist.setEncoding("UTF-8"); ist.setCharacterStream(isr); xr.parse(ist); // Parsing has finished. bis.close(); baf.clear(); bais.close(); is.close(); } urlc.disconnect(); } catch (SAXException e) { // All is OK :) } catch (MalformedURLException e) { Log.e(TAG, errorMsg = "MalformedURLException"); } catch (IOException e) { Log.e(TAG, errorMsg = "IOException"); } catch (ParserConfigurationException e) { Log.e(TAG, errorMsg = "ParserConfigurationException"); } catch (ArrayIndexOutOfBoundsException e) { Log.e(TAG, errorMsg = "ArrayIndexOutOfBoundsException"); } return errorMsg; }
From source file:com.andyasprou.webcrawler.Utilities.GenericSiteMapParser.java
/** * Parse the given XML content./*from w ww .ja v a 2 s. c om*/ * * @param sitemapUrl URL to sitemap file * @param xmlContent the byte[] backing the sitemapUrl * @return The site map * @throws UnknownFormatException if there is an error parsing the sitemap */ protected AbstractSiteMap processXml(URL sitemapUrl, byte[] xmlContent) throws UnknownFormatException { BOMInputStream bomIs = new BOMInputStream(new ByteArrayInputStream(xmlContent)); InputSource is = new InputSource(); try { is.setCharacterStream(new BufferedReader(new InputStreamReader(bomIs, "UTF-8"))); } catch (UnsupportedEncodingException e) { IOUtils.closeQuietly(bomIs); throw new RuntimeException("Impossible exception", e); } return processXml(sitemapUrl, is); }
From source file:com.fota.Link.sdpApi.java
public String GetBasicUserInfoAndMarketInfo2(String CTN) throws JDOMException { String resultStr = null;//from w ww .j av a2 s. co m try { String endPointUrl = PropUtil.getPropValue("sdp.oif516.url"); String strRequest = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' " + "xmlns:oas='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'" + " xmlns:sdp='http://kt.com/sdp'>" + " <soapenv:Header>" + " <oas:Security>" + " <oas:UsernameToken>" + " <oas:Username>" + PropUtil.getPropValue("sdp.id") + "</oas:Username>" + " <oas:Password>" + PropUtil.getPropValue("sdp.pw") + "</oas:Password>" + " </oas:UsernameToken>" + " </oas:Security>" + " </soapenv:Header>" + " <soapenv:Body>" + " <sdp:getBasicUserInfoAndMarketInfoRequest>" + " <!--You may enterthe following 6 items in any order-->" + " <sdp:CALL_CTN>" + CTN + "</sdp:CALL_CTN>" + " </sdp:getBasicUserInfoAndMarketInfoRequest>\n" + " </soapenv:Body>\n" + "</soapenv:Envelope>"; // connection URL url = new URL(endPointUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-type", "text/xml;charset=utf-8"); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setDoInput(true); connection.connect(); // output OutputStream os = connection.getOutputStream(); // os.write(strRequest.getBytes(), 0, strRequest.length()); os.write(strRequest.getBytes("utf-8")); os.flush(); os.close(); // input InputStream is = connection.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8")); String line = null; String resValue = null; String parseStr = null; while ((line = br.readLine()) != null) { System.out.println(line); parseStr = line; } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource temp = new InputSource(); temp.setCharacterStream(new StringReader(parseStr)); Document doc = builder.parse(temp); //xml? NodeList list = doc.getElementsByTagName("*"); int i = 0; Element element; String contents; while (list.item(i) != null) { element = (Element) list.item(i); // System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); // System.out.println(element.getNodeName()); if (element.hasChildNodes()) { contents = element.getFirstChild().getNodeValue(); // System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55"); // System.out.println(element.getNodeName()); // System.out.println(element.getFirstChild().getNodeName()); if (element.getNodeName().equals("sdp:CUSTOMER_LINK_NAME")) { resultStr = element.getFirstChild().getNodeValue(); } System.out.println(contents); } i++; } //resultStr = resValue; resultStr = java.net.URLDecoder.decode(resultStr, "euc-kr"); connection.disconnect(); } catch (Exception e) { e.printStackTrace(); } return resultStr; }
From source file:com.fota.Link.sdpApi.java
public String GetBasicUserInfoAndMarketInfo(String CTN) throws JDOMException { String resultStr = null;/*from w w w . ja v a 2 s . co m*/ StringBuffer logSb = new StringBuffer(); try { String endPointUrl = PropUtil.getPropValue("sdp.oif516.url"); String strRequest = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' " + "xmlns:oas='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'" + " xmlns:sdp='http://kt.com/sdp'>" + " <soapenv:Header>" + " <oas:Security>" + " <oas:UsernameToken>" + " <oas:Username>" + PropUtil.getPropValue("sdp.id") + "</oas:Username>" + " <oas:Password>" + PropUtil.getPropValue("sdp.pw") + "</oas:Password>" + " </oas:UsernameToken>" + " </oas:Security>" + " </soapenv:Header>" + " <soapenv:Body>" + " <sdp:getBasicUserInfoAndMarketInfoRequest>" + " <!--You may enterthe following 6 items in any order-->" + " <sdp:CALL_CTN>" + CTN + "</sdp:CALL_CTN>" + " </sdp:getBasicUserInfoAndMarketInfoRequest>\n" + " </soapenv:Body>\n" + "</soapenv:Envelope>"; logSb.append("\r\n---------- GetBasicUserInfoAndMarketInfo(" + CTN + ") ----------"); logSb.append("\r\nendPointUrl : " + endPointUrl); logSb.append("\r\nrequest msg : \r\n==============================\r\n" + strRequest + "\r\n===============================\r\n"); logger.info(logSb.toString()); logSb.setLength(0); // connection URL url = new URL(endPointUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-type", "text/xml;charset=utf-8"); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setDoInput(true); connection.connect(); // output OutputStream os = connection.getOutputStream(); // os.write(strRequest.getBytes(), 0, strRequest.length()); os.write(strRequest.getBytes("utf-8")); os.flush(); os.close(); // input InputStream is = connection.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8")); String line = null; String resValue = null; String parseStr = null; while ((line = br.readLine()) != null) { System.out.println(line); parseStr = line; } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource temp = new InputSource(); temp.setCharacterStream(new StringReader(parseStr)); Document doc = builder.parse(temp); //xml? NodeList list = doc.getElementsByTagName("*"); int i = 0; Element element; String contents; while (list.item(i) != null) { element = (Element) list.item(i); // System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); // System.out.println(element.getNodeName()); if (element.hasChildNodes()) { contents = element.getFirstChild().getNodeValue(); // System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55"); // System.out.println(element.getNodeName()); // System.out.println(element.getFirstChild().getNodeName()); if (element.getNodeName().equals("sdp:PREPAID")) { resultStr = contents; } System.out.println(contents); } i++; } //resultStr = resValue; connection.disconnect(); } catch (Exception e) { e.printStackTrace(); } return resultStr; }
From source file:com.fota.Link.sdpApi.java
public String CheckNumberPortabilityByPhoneNumber(String CTN) throws SAXException, IOException, ParserConfigurationException { String resultStr = null;/* ww w . ja v a 2 s . c o m*/ try { String endPointUrl = PropUtil.getPropValue("sdp.oif552.url"); String strRequest = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' " + "xmlns:oas='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'" + " xmlns:sdp='http://kt.com/sdp'>" + " <soapenv:Header>" + " <oas:Security>" + " <oas:UsernameToken>" + " <oas:Username>" + PropUtil.getPropValue("sdp.id") + "</oas:Username>" + " <oas:Password>" + PropUtil.getPropValue("sdp.pw") + "</oas:Password>" + " </oas:UsernameToken>" + " </oas:Security>" + " </soapenv:Header>" + " <soapenv:Body>" + " <sdp:checkNumberPortabilityByPhoneNumberRequest>" + " <!--You may enterthe following 6 items in any order-->" + " <sdp:CALL_CTN>" + CTN + "</sdp:CALL_CTN>" + " </sdp:checkNumberPortabilityByPhoneNumberRequest>\n" + " </soapenv:Body>\n" + "</soapenv:Envelope>"; // phone_number + telco_code + party_name + birth_date + [gender + // foreigner](?) // + auth_code + random_no + action_type // connection URL url = new URL(endPointUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-type", "text/xml;charset=utf-8"); // connection.setRequestProperty("Content-Length", // String.valueOf(strRequest.length())); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setDoInput(true); connection.connect(); // output OutputStream os = connection.getOutputStream(); // os.write(strRequest.getBytes(), 0, strRequest.length()); os.write(strRequest.getBytes("utf-8")); os.flush(); os.close(); // input InputStream is = connection.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8")); String line = null; String resValue = null; String parseStr = null; while ((line = br.readLine()) != null) { System.out.println(line); parseStr = line; //int nIndex = resultStr.indexOf("<sdp:ROUTING_DIGIT>"); //resValue = resultStr.substring(nIndex,nIndex+1); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource temp = new InputSource(); temp.setCharacterStream(new StringReader(parseStr)); Document doc = builder.parse(temp); //xml? NodeList list = doc.getElementsByTagName("*"); int i = 0; Element element; String contents; while (list.item(i) != null) { element = (Element) list.item(i); System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); System.out.println(element.getNodeName()); if (element.hasChildNodes()) { contents = element.getFirstChild().getNodeValue(); System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55"); System.out.println(element.getNodeName()); System.out.println(element.getFirstChild().getNodeName()); if (element.getNodeName().equals("sdp:ROUTING_DIGIT")) { //nero17 //resultStr = element.getFirstChild().getNodeName(); resultStr = contents; } System.out.println(contents); } i++; } connection.disconnect(); } catch (Exception e) { e.printStackTrace(); } if (resultStr.length() < 2) { resultStr = ""; } return resultStr; }
From source file:com.fota.Link.sdpApi.java
public SDPInfoVO getSpecificSubscpnInfo(String CTN) { //String resultStr = null; SDPInfoVO resVO = new SDPInfoVO(); String strIMEI = null;/*from w ww.ja v a 2 s.co m*/ String Model_Name = null; String return_cd = null; try { String endPointUrl = PropUtil.getPropValue("sdp.oif114.url"); String strRequest = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' " + "xmlns:oas='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'" + " xmlns:sdp='http://kt.com/sdp'>" + " <soapenv:Header>" + " <oas:Security>" + " <oas:UsernameToken>" + " <oas:Username>" + PropUtil.getPropValue("sdp.id") + "</oas:Username>" + " <oas:Password>" + PropUtil.getPropValue("sdp.pw") + "</oas:Password>" + " </oas:UsernameToken>" + " </oas:Security>" + " </soapenv:Header>" + " <soapenv:Body>" + " <sdp:getSpecificSubscpnInfoRequest>" + " <!--You may enterthe following 6 items in any order-->" // + " <sdp:Credt_Id></sdp:Credt_Id>" + " <sdp:User_Name>" + CTN + "</sdp:User_Name>" + "<sdp:Credt_Type_Cd>" + "05" + "</sdp:Credt_Type_Cd>" + " </sdp:getSpecificSubscpnInfoRequest>\n" + " </soapenv:Body>\n" + "</soapenv:Envelope>"; // connection URL url = new URL(endPointUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-type", "text/xml;charset=utf-8"); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setDoInput(true); connection.connect(); // output OutputStream os = connection.getOutputStream(); // os.write(strRequest.getBytes(), 0, strRequest.length()); os.write(strRequest.getBytes("utf-8")); os.flush(); os.close(); // input InputStream is = connection.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8")); String line = null; String parseStr = null; while ((line = br.readLine()) != null) { System.out.println(line); parseStr = line; } //resultStr = line; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource temp = new InputSource(); temp.setCharacterStream(new StringReader(parseStr)); Document doc = builder.parse(temp); //xml? NodeList list = doc.getElementsByTagName("*"); int i = 0; Element element; String contents; // sdp:returnCode while (list.item(i) != null) { element = (Element) list.item(i); //System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); //System.out.println(element.getNodeName()); if (element.hasChildNodes()) { contents = element.getFirstChild().getNodeValue(); //System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55"); //System.out.println(element.getNodeName()); //System.out.println(element.getFirstChild().getNodeName()); if (element.getNodeName().equals("n1:Resource_Unique_Id")) { if (element.getNextSibling().getFirstChild().getNodeValue().equals(("06"))) { //System.out.println("%%%%%%%%%%%%%%%%% FINDFIND!!! %%%%%%%%%%%%%%%%%%%%%%%%%%%55"); strIMEI = element.getFirstChild().getNodeValue(); //System.out.println("%%%%%%%%%%%%%%%%% FINDFIND!!! " + strIMEI + "%%%%%%%%%%%%%%%%%%%%%%%%%%%55"); } //resultStr = element.getFirstChild().getNodeName(); } if (element.getNodeName().equals("n1:Resource_Model_Name")) { Model_Name = element.getFirstChild().getNodeValue(); } if (element.getNodeName().equals("sdp:returnCode")) { return_cd = element.getFirstChild().getNodeValue(); } //n1:Resource_Model_Name System.out.println(contents); } i++; } connection.disconnect(); } catch (Exception e) { e.printStackTrace(); } resVO.setModem_model_nm(Model_Name); resVO.setImei(strIMEI); resVO.setReturn_cd(return_cd); return resVO; }
From source file:com.esri.geoevent.solutions.adapter.cot.CoTAdapter.java
private void parseUsingDocument(String xml, String channelId) { if (buffers.containsKey(channelId)) { String temp = buffers.remove(channelId); temp = temp + xml;/*from w w w . ja v a2 s.c o m*/ if (temp.length() > maxBufferSize) { log.error("The size of the incoming xml message exceeds the configured maximum buffer size of " + maxBufferSize + ". The buffer contents will be discarded to make room for incoming data."); temp = scanForEvent(temp); // Look for something that looks like a new message. if (temp == null) // If we didn't find something that looks like a new message, just start with the xml that was passed in (discarding the buffered data). temp = xml; } xml = temp; } try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource source = new InputSource(); source.setCharacterStream(new StringReader(xml)); Document doc = db.parse(source); NodeList nodeList = doc.getElementsByTagName("event"); if (nodeList != null) { for (int i = 0; i < nodeList.getLength(); i++) { GeoEvent msg = geoEventCreator.create(guid); Element e = (Element) nodeList.item(i); String version = e.getAttribute("version"); if (!version.isEmpty()) msg.setField(0, Double.valueOf(version)); msg.setField(1, e.getAttribute("uid")); String type = e.getAttribute("type"); msg.setField(2, type); msg.setField(3, CoTUtilities.getSymbolFromCot(type)); //System.out.println("2525b from type: "+ CoTUtilities.getSymbolFromCot(type)); //System.out.println("type: " + e.getAttribute("type") " -> " + convertType(e.getAttribute("type"))); msg.setField(4, convertType(e.getAttribute("type"))); //System.out.println("how: " + e.getAttribute("how") + " -> "+ convertHow(e.getAttribute("how"))); msg.setField(5, e.getAttribute("how")); msg.setField(6, convertHow(e.getAttribute("how"))); msg.setField(7, parseCoTDate(e.getAttribute("time"))); msg.setField(8, parseCoTDate(e.getAttribute("start"))); msg.setField(9, parseCoTDate(e.getAttribute("stale"))); msg.setField(10, e.getAttribute("access")); msg.setField(11, e.getAttribute("opex")); msg.setField(12, convertOpex(e.getAttribute("opex"))); //System.out.println("opex: " + e.getAttribute("opex" + " is a: " + convertOpex(e.getAttribute("opex"))); msg.setField(13, e.getAttribute("qos")); msg.setField(14, convertQos(e.getAttribute("qos"))); //System.out.println("qos: " + e.getAttribute("qos") + " -> " convertQos(e.getAttribute("qos"))); NodeList points = e.getElementsByTagName("point"); if (points.getLength() > 0) { Element pointElement = (Element) points.item(0); MapGeometry geom = createGeometry(pointElement); msg.setField(15, geom); //msg.setField( 15, geom.toJson() ); } GeoEventDefinition ged = msg.getGeoEventDefinition(); traverseBranch(findChildNodes(e, "detail").get(0), msg, ged.getFieldDefinition("detail")); geoEventListener.receive(msg); } } } catch (Exception e) { if (e.getMessage() != null && e.getMessage() .equals("XML document structures must start and end within the same entity.")) { if (xml != null) buffers.put(channelId, xml); return; } log.error("Error while parsing CoT message. For details, set log level to DEBUG.", e); log.debug("Error while parsing the message : " + xml); return; } }