2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
20 package org.openecomp.portalapp.controller.core;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.util.HashMap;
26 import java.util.jar.Attributes;
27 import java.util.jar.Manifest;
29 import javax.servlet.ServletContext;
30 import javax.servlet.http.HttpServletRequest;
32 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
33 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.web.bind.annotation.RequestMapping;
36 import org.springframework.web.bind.annotation.RequestMethod;
37 import org.springframework.web.bind.annotation.ResponseBody;
38 import org.springframework.web.bind.annotation.RestController;
41 * This controller responds to a request for the web application manifest,
42 * returning a JSON with the information that was created at build time.
44 * Manifest entries have names with hyphens, which means Javascript code can't
45 * simply use the shorthand object.key; instead use object['key'].
49 public class ManifestController extends RestrictedBaseController {
51 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ManifestController.class);
54 * Required to obtain the webapp manifest.
57 private ServletContext context;
59 /** Path to resource on classpath */
60 private final String MANIFEST_RESOURCE_PATH = "/META-INF/MANIFEST.MF";
63 * Gets the content of the webapp manifest file META-INF/MANIFEST.MF.
65 * @return Attributes object with key-value pairs from the manifest
68 private Attributes getWebappManifest() throws IOException {
69 // Manifest is formatted as Java-style properties
70 InputStream inputStream = context.getResourceAsStream(MANIFEST_RESOURCE_PATH);
71 if (inputStream == null)
72 throw new IOException("getWebappManifest: failed to get resource at path " + MANIFEST_RESOURCE_PATH);
73 Manifest manifest = new Manifest(inputStream);
75 return manifest.getMainAttributes();
79 * Gets the webapp manifest contents as a JSON object.
82 * @return A map of key-value pairs. On success:
94 * { "error": "message" }
97 @RequestMapping(value = { "/manifest" }, method = RequestMethod.GET, produces = "application/json")
99 public Map<Object, Object> getManifest(HttpServletRequest request) {
101 Attributes attributes = getWebappManifest();
103 } catch (Exception ex) {
104 logger.error(EELFLoggerDelegate.errorLogger, "getManifest failed", ex);
105 Map<Object, Object> response = new HashMap<Object, Object>();
106 response.put("error", "failed to get manifest: " + ex.toString());