PrintWriter out = response.getWriter();
try {
ConfigService cs = (ConfigService)getApplicationContext().getBean("config");
IDPConfig idpConfig = cs.getIDPConfig(realm);
LOG.debug(idpConfig.toString());
MetadataWriter mw = new MetadataWriter();
Document metadata = mw.getMetaData(idpConfig);
out.write(DOM2Writer.nodeToString(metadata));
} catch (Exception ex) {
LOG.error("Failed to get metadata document: ", ex);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}