[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / service / ManifestServiceImpl.java
1 /*-
2  * ================================================================================
3  * ECOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 package org.openecomp.portalapp.portal.service;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.util.jar.Attributes;
25 import java.util.jar.Manifest;
26
27 import javax.servlet.ServletContext;
28
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.context.annotation.EnableAspectJAutoProxy;
31 import org.springframework.stereotype.Service;
32
33 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
34 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
35
36 @Service("manifestService")
37 @EnableAspectJAutoProxy
38 @EPMetricsLog
39 public class ManifestServiceImpl implements ManifestService {
40         @Autowired
41         ServletContext context;
42
43         /*
44          * (non-Javadoc)
45          * @see org.openecomp.portalapp.portal.service.ManifestService#getWebappManifest()
46          */
47         public Attributes getWebappManifest() throws IOException {
48                 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ManifestServiceImpl.class);
49                 // Path to resource on classpath
50                 final String MANIFEST_RESOURCE_PATH = "/META-INF/MANIFEST.MF";
51                 // Manifest is formatted as Java-style properties
52                 try {
53                         InputStream inputStream = context.getResourceAsStream(MANIFEST_RESOURCE_PATH);
54                         Manifest manifest = new Manifest(inputStream);
55                         inputStream.close();
56                         return manifest.getMainAttributes();
57                 } catch (IOException e) {
58                         logger.error(EELFLoggerDelegate.errorLogger, "getWebappManifest: failed to read/find manifest");
59                         throw e;
60                 }
61         }
62 }