@Test public void should_parse_notification() throws Exception { final Notification notification = new RrdpParser().notification(fileIS("rrdp/notification1.xml")); assertEquals("9df4b597-af9e-4dca-bdda-719cce2c4e28", notification.sessionId); assertEquals("http: assertEquals("EEEA7F7AD96D85BBD1F7274FA7DA0025984A2AF3D5A0538F77BEC732ECB1B068", notification.snapshotHash); assertEquals(BigInteger.ONE, notification.serial); assertEquals(0, notification.deltas.size()); }
public Notification notification(final InputStream inputStream) { try { final XMLInputFactory factory = XMLInputFactory.newInstance(); final XMLEventReader eventReader = factory.createXMLEventReader(inputStream); String sessionId = null; BigInteger serial = null; String snapshotUri = null; String snapshotHash = null; final List<DeltaInfo> deltas = new ArrayList<>(); while (eventReader.hasNext()) { final XMLEvent event = eventReader.nextEvent(); if (event.getEventType() == XMLStreamConstants.START_ELEMENT) { final StartElement startElement = event.asStartElement(); final String qName = startElement.getName().getLocalPart(); switch (qName) { case "notification": serial = new BigInteger(getAttr(startElement, "serial", "Notification serial is not present")); sessionId = getAttr(startElement, "session_id", "Session id is not present"); break; case "snapshot": snapshotUri = getAttr(startElement, "uri", "Snapshot URI is not present"); snapshotHash = getAttr(startElement, "hash", "Snapshot hash is not present"); break; case "delta": final String deltaUri = getAttr(startElement, "uri", "Delta URI is not present"); final String deltaHash = getAttr(startElement, "hash", "Delta hash is not present"); final String deltaSerial = getAttr(startElement, "serial", "Delta serial is not present"); deltas.add(new DeltaInfo(deltaUri, deltaHash, new BigInteger(deltaSerial))); break; } } } return new Notification(sessionId, serial, snapshotUri, snapshotHash, deltas); } catch (XMLStreamException e) { throw new RrdpException("Couldn't parse notification: ", e); } }
RrdpParser { public Notification notification(final InputStream inputStream) { try { final XMLInputFactory factory = XMLInputFactory.newInstance(); final XMLEventReader eventReader = factory.createXMLEventReader(inputStream); String sessionId = null; BigInteger serial = null; String snapshotUri = null; String snapshotHash = null; final List<DeltaInfo> deltas = new ArrayList<>(); while (eventReader.hasNext()) { final XMLEvent event = eventReader.nextEvent(); if (event.getEventType() == XMLStreamConstants.START_ELEMENT) { final StartElement startElement = event.asStartElement(); final String qName = startElement.getName().getLocalPart(); switch (qName) { case "notification": serial = new BigInteger(getAttr(startElement, "serial", "Notification serial is not present")); sessionId = getAttr(startElement, "session_id", "Session id is not present"); break; case "snapshot": snapshotUri = getAttr(startElement, "uri", "Snapshot URI is not present"); snapshotHash = getAttr(startElement, "hash", "Snapshot hash is not present"); break; case "delta": final String deltaUri = getAttr(startElement, "uri", "Delta URI is not present"); final String deltaHash = getAttr(startElement, "hash", "Delta hash is not present"); final String deltaSerial = getAttr(startElement, "serial", "Delta serial is not present"); deltas.add(new DeltaInfo(deltaUri, deltaHash, new BigInteger(deltaSerial))); break; } } } return new Notification(sessionId, serial, snapshotUri, snapshotHash, deltas); } catch (XMLStreamException e) { throw new RrdpException("Couldn't parse notification: ", e); } } }
RrdpParser { public Notification notification(final InputStream inputStream) { try { final XMLInputFactory factory = XMLInputFactory.newInstance(); final XMLEventReader eventReader = factory.createXMLEventReader(inputStream); String sessionId = null; BigInteger serial = null; String snapshotUri = null; String snapshotHash = null; final List<DeltaInfo> deltas = new ArrayList<>(); while (eventReader.hasNext()) { final XMLEvent event = eventReader.nextEvent(); if (event.getEventType() == XMLStreamConstants.START_ELEMENT) { final StartElement startElement = event.asStartElement(); final String qName = startElement.getName().getLocalPart(); switch (qName) { case "notification": serial = new BigInteger(getAttr(startElement, "serial", "Notification serial is not present")); sessionId = getAttr(startElement, "session_id", "Session id is not present"); break; case "snapshot": snapshotUri = getAttr(startElement, "uri", "Snapshot URI is not present"); snapshotHash = getAttr(startElement, "hash", "Snapshot hash is not present"); break; case "delta": final String deltaUri = getAttr(startElement, "uri", "Delta URI is not present"); final String deltaHash = getAttr(startElement, "hash", "Delta hash is not present"); final String deltaSerial = getAttr(startElement, "serial", "Delta serial is not present"); deltas.add(new DeltaInfo(deltaUri, deltaHash, new BigInteger(deltaSerial))); break; } } } return new Notification(sessionId, serial, snapshotUri, snapshotHash, deltas); } catch (XMLStreamException e) { throw new RrdpException("Couldn't parse notification: ", e); } }  }
RrdpParser { public Notification notification(final InputStream inputStream) { try { final XMLInputFactory factory = XMLInputFactory.newInstance(); final XMLEventReader eventReader = factory.createXMLEventReader(inputStream); String sessionId = null; BigInteger serial = null; String snapshotUri = null; String snapshotHash = null; final List<DeltaInfo> deltas = new ArrayList<>(); while (eventReader.hasNext()) { final XMLEvent event = eventReader.nextEvent(); if (event.getEventType() == XMLStreamConstants.START_ELEMENT) { final StartElement startElement = event.asStartElement(); final String qName = startElement.getName().getLocalPart(); switch (qName) { case "notification": serial = new BigInteger(getAttr(startElement, "serial", "Notification serial is not present")); sessionId = getAttr(startElement, "session_id", "Session id is not present"); break; case "snapshot": snapshotUri = getAttr(startElement, "uri", "Snapshot URI is not present"); snapshotHash = getAttr(startElement, "hash", "Snapshot hash is not present"); break; case "delta": final String deltaUri = getAttr(startElement, "uri", "Delta URI is not present"); final String deltaHash = getAttr(startElement, "hash", "Delta hash is not present"); final String deltaSerial = getAttr(startElement, "serial", "Delta serial is not present"); deltas.add(new DeltaInfo(deltaUri, deltaHash, new BigInteger(deltaSerial))); break; } } } return new Notification(sessionId, serial, snapshotUri, snapshotHash, deltas); } catch (XMLStreamException e) { throw new RrdpException("Couldn't parse notification: ", e); } }  void parseSnapshot(InputStream inputStream, Consumer<SnapshotHeader> processSnapshotHeader, Consumer<SnapshotObject> processSnapshotObject); void parseDelta(InputStream inputStream, Consumer<DeltaHeader> processDeltaHeader, Consumer<DeltaElement> processDeltaElement); Notification notification(final InputStream inputStream); }
RrdpParser { public Notification notification(final InputStream inputStream) { try { final XMLInputFactory factory = XMLInputFactory.newInstance(); final XMLEventReader eventReader = factory.createXMLEventReader(inputStream); String sessionId = null; BigInteger serial = null; String snapshotUri = null; String snapshotHash = null; final List<DeltaInfo> deltas = new ArrayList<>(); while (eventReader.hasNext()) { final XMLEvent event = eventReader.nextEvent(); if (event.getEventType() == XMLStreamConstants.START_ELEMENT) { final StartElement startElement = event.asStartElement(); final String qName = startElement.getName().getLocalPart(); switch (qName) { case "notification": serial = new BigInteger(getAttr(startElement, "serial", "Notification serial is not present")); sessionId = getAttr(startElement, "session_id", "Session id is not present"); break; case "snapshot": snapshotUri = getAttr(startElement, "uri", "Snapshot URI is not present"); snapshotHash = getAttr(startElement, "hash", "Snapshot hash is not present"); break; case "delta": final String deltaUri = getAttr(startElement, "uri", "Delta URI is not present"); final String deltaHash = getAttr(startElement, "hash", "Delta hash is not present"); final String deltaSerial = getAttr(startElement, "serial", "Delta serial is not present"); deltas.add(new DeltaInfo(deltaUri, deltaHash, new BigInteger(deltaSerial))); break; } } } return new Notification(sessionId, serial, snapshotUri, snapshotHash, deltas); } catch (XMLStreamException e) { throw new RrdpException("Couldn't parse notification: ", e); } }  void parseSnapshot(InputStream inputStream, Consumer<SnapshotHeader> processSnapshotHeader, Consumer<SnapshotObject> processSnapshotObject); void parseDelta(InputStream inputStream, Consumer<DeltaHeader> processDeltaHeader, Consumer<DeltaElement> processDeltaElement); Notification notification(final InputStream inputStream);  }