private static Logger logger =
Logger.getLogger("org.onap.dmaap.datarouter.subscriber.SampleSubscriberServlet");
- private String outputDirectory;
- private String basicAuth;
+ private static String outputDirectory;
+ private static String basicAuth;
/**
* Configure the SampleSubscriberServlet.
try {
Files.createDirectory(Paths.get(outputDirectory));
} catch (IOException e) {
- logger.info("SubServlet: Failed to create delivery dir: " + e.getMessage());
+ logger.info("SubServlet: Failed to create delivery dir: " + e.getMessage(), e);
}
basicAuth = "Basic " + Base64.encodeBase64String((login + ":" + password).getBytes());
}
if (queryString != null) {
fileid = fileid + "?" + queryString;
}
- String publishid = req.getHeader("X-ATT-DR-PUBLISH-ID");
+ String publishid = req.getHeader("X-DMAAP-DR-PUBLISH-ID");
String 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));
+ Files.deleteIfExists(Paths.get(fullMetaDataPath));
logger.info(
"SampleSubServlet: Received delete for file id "
+ fileid
+ 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];
}
}
Files.move(Paths.get(tmpPath), Paths.get(fullPath), StandardCopyOption.REPLACE_EXISTING);
+ try (PrintWriter writer = new PrintWriter(new FileOutputStream(tmpMetaDataPath))) {
+ String metaData = req.getHeader("X-DMAAP-DR-META");
+ writer.print(metaData);
+ }
+ Files.move(Paths.get(tmpMetaDataPath), Paths.get(fullMetaDataPath), StandardCopyOption.REPLACE_EXISTING);
logger.info(
"SampleSubServlet: Received file id "
+ fileid
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