eb823250001acdc022913a6a19e3447f7d844147
[portal.git] / portal-BE / src / main / java / org / onap / portal / service / ManifestService.java
1 package org.onap.portal.service;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.util.jar.Attributes;
6 import java.util.jar.Manifest;
7 import javax.servlet.ServletContext;
8 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.context.annotation.EnableAspectJAutoProxy;
11 import org.springframework.stereotype.Service;
12
13 @Service
14 @EnableAspectJAutoProxy
15 public class ManifestService {
16
17     @Autowired
18     ServletContext context;
19
20     public Attributes getWebappManifest() throws IOException {
21         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ManifestService.class);
22         // Path to resource on classpath
23         final String MANIFEST_RESOURCE_PATH = "/META-INF/MANIFEST.MF";
24         // Manifest is formatted as Java-style properties
25         try {
26             InputStream inputStream = context.getResourceAsStream(MANIFEST_RESOURCE_PATH);
27             Manifest manifest = new Manifest(inputStream);
28             inputStream.close();
29             return manifest.getMainAttributes();
30         } catch (IOException e) {
31             logger.error(EELFLoggerDelegate.errorLogger, "getWebappManifest: failed to read/find manifest");
32             throw e;
33         }
34     }
35 }