Created
September 22, 2016 02:15
-
-
Save jmcshane/396c500613926cb808eb54bfac4122d1 to your computer and use it in GitHub Desktop.
Endpoint to expose the manifest details of a jar or war file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
public class ManifestDetailsController { | |
private static final Logger logger = LoggerFactory.getLogger(ManifestDetailsController.class); | |
@RequestMapping(value="/getManifestDetails" ,method = RequestMethod.GET) | |
@ResponseBody | |
public Map<String,Object> getManifestDetails() { | |
Enumeration<URL> resource; | |
Map<String,Object> result = new HashMap<String,Object> (); | |
try { | |
resource = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME); | |
URL url = resource.nextElement(); | |
InputStream is = url.openStream(); | |
Manifest manifest = new Manifest(is); | |
Attributes mainAttributes = manifest.getMainAttributes(); | |
for (Object key : mainAttributes.keySet()) { | |
result.put(key.toString(), mainAttributes.get(key)); | |
} | |
} | |
catch (IOException e) { | |
logger.warn("Manifest details failed", e); | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment