Add creation of metadata file on subscriber 08/75808/2
authoreconwar <conor.ward@est.tech>
Tue, 15 Jan 2019 15:56:03 +0000 (15:56 +0000)
committereconwar <conor.ward@est.tech>
Tue, 15 Jan 2019 15:56:03 +0000 (15:56 +0000)
Change-Id: Ia6aa3f038b35e47a0811de84a9aeab58acecd268
Issue-ID: DMAAP-963
Signed-off-by: econwar <conor.ward@est.tech>
datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SampleSubscriberServlet.java
datarouter-subscriber/src/test/java/org/onap/dmaap/datarouter/subscriber/SampleSubscriberServletTest.java

index 3842574..2805128 100644 (file)
@@ -140,9 +140,12 @@ public class SampleSubscriberServlet extends HttpServlet {
         URLEncoder.encode(fileid, "UTF-8").replaceAll("^\\.", "%2E").replaceAll("\\*", "%2A");
     String fullPath = outputDirectory + "/" + filename;
     String tmpPath = outputDirectory + "/." + filename;
         URLEncoder.encode(fileid, "UTF-8").replaceAll("^\\.", "%2E").replaceAll("\\*", "%2A");
     String fullPath = outputDirectory + "/" + filename;
     String tmpPath = outputDirectory + "/." + filename;
+    String fullMetaDataPath = outputDirectory + "/" + filename + ".M";
+    String tmpMetaDataPath = outputDirectory + "/." + filename + ".M";
     try {
       if (isdelete) {
         Files.deleteIfExists(Paths.get(fullPath));
     try {
       if (isdelete) {
         Files.deleteIfExists(Paths.get(fullPath));
+        Files.deleteIfExists(Paths.get(fullMetaDataPath));
         logger.info(
             "SampleSubServlet: Received delete for file id "
                 + fileid
         logger.info(
             "SampleSubServlet: Received delete for file id "
                 + fileid
@@ -154,6 +157,7 @@ public class SampleSubscriberServlet extends HttpServlet {
                 + fullPath);
       } else {
         new File(tmpPath).createNewFile();
                 + fullPath);
       } else {
         new File(tmpPath).createNewFile();
+        new File(tmpMetaDataPath).createNewFile();
         try (InputStream is = req.getInputStream();
             OutputStream os = new FileOutputStream(tmpPath)) {
           byte[] buf = new byte[65536];
         try (InputStream is = req.getInputStream();
             OutputStream os = new FileOutputStream(tmpPath)) {
           byte[] buf = new byte[65536];
@@ -163,6 +167,11 @@ public class SampleSubscriberServlet extends HttpServlet {
           }
         }
         Files.move(Paths.get(tmpPath), Paths.get(fullPath), StandardCopyOption.REPLACE_EXISTING);
           }
         }
         Files.move(Paths.get(tmpPath), Paths.get(fullPath), StandardCopyOption.REPLACE_EXISTING);
+        try (PrintWriter writer = new PrintWriter(new FileOutputStream(tmpMetaDataPath))) {
+          String metaData = req.getHeader("X-ATT-DR-META");
+          writer.print(metaData);
+        }
+        Files.move(Paths.get(tmpMetaDataPath), Paths.get(fullMetaDataPath), StandardCopyOption.REPLACE_EXISTING);
         logger.info(
             "SampleSubServlet: Received file id "
                 + fileid
         logger.info(
             "SampleSubServlet: Received file id "
                 + fileid
@@ -177,6 +186,7 @@ public class SampleSubscriberServlet extends HttpServlet {
       resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
     } catch (IOException ioe) {
       Files.deleteIfExists(Paths.get(tmpPath));
       resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
     } catch (IOException ioe) {
       Files.deleteIfExists(Paths.get(tmpPath));
+      Files.deleteIfExists(Paths.get(tmpMetaDataPath));
       logger.info(
           "SampleSubServlet: Failed to process file "
               + fullPath
       logger.info(
           "SampleSubServlet: Failed to process file "
               + fullPath
index e31b347..f3700e9 100755 (executable)
@@ -100,6 +100,7 @@ public class SampleSubscriberServletTest {
     when(request.getHeader("Authorization")).thenReturn("Basic TE9HSU46UEFTU1dPUkQ=");
     when(request.getPathInfo()).thenReturn("/publish/1/testfile");
     when(request.getHeader("X-ATT-DR-PUBLISH-ID")).thenReturn("1");
     when(request.getHeader("Authorization")).thenReturn("Basic TE9HSU46UEFTU1dPUkQ=");
     when(request.getPathInfo()).thenReturn("/publish/1/testfile");
     when(request.getHeader("X-ATT-DR-PUBLISH-ID")).thenReturn("1");
+    when(request.getHeader("X-ATT-DR-META")).thenReturn("{\"Key\":\"Value\"}");
     when(request.getQueryString()).thenReturn(null);
     ServletInputStream inStream = mock(ServletInputStream.class);
     when(request.getInputStream()).thenReturn(inStream);
     when(request.getQueryString()).thenReturn(null);
     ServletInputStream inStream = mock(ServletInputStream.class);
     when(request.getInputStream()).thenReturn(inStream);