diff options
author | Jack Magne <jmagne@dhcp-16-213.sjc.redhat.com> | 2014-04-14 15:39:50 -0700 |
---|---|---|
committer | Jack Magne <jmagne@dhcp-16-213.sjc.redhat.com> | 2014-04-15 14:40:28 -0700 |
commit | 19664d23cf0808a25e736b97fb12144b60b84aba (patch) | |
tree | 6c53785ae12fdeca3ad5e6a039226f19746d0da2 /base/tps-tomcat/src | |
parent | 32a0192af220f2b18f79a9231310fefd22182afb (diff) | |
download | pki-19664d23cf0808a25e736b97fb12144b60b84aba.tar.gz pki-19664d23cf0808a25e736b97fb12144b60b84aba.tar.xz pki-19664d23cf0808a25e736b97fb12144b60b84aba.zip |
PhoneHome feature:
1. Provides an xml file served by TPS to allow the client(esc) to configure itself to contact TPS.
2. Edewata review fixes. Return application/xml instead of text/xml, and fix how the phone home file path is calculated.
Diffstat (limited to 'base/tps-tomcat/src')
-rw-r--r-- | base/tps-tomcat/src/org/dogtagpki/server/tps/TPSPhoneHome.java | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSPhoneHome.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSPhoneHome.java new file mode 100644 index 000000000..e34b8495f --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSPhoneHome.java @@ -0,0 +1,88 @@ +package org.dogtagpki.server.tps; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.netscape.certsrv.apps.CMS; + +public class TPSPhoneHome extends HttpServlet { + + private static final long serialVersionUID = 1864386666927370987L; + private static String phoneHomeName = "phoneHome.xml"; + + public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + //Simply return xml file to the client + //In the future we could get this info from elsewhere such as LDAP + + CMS.debug("TPSPhoneHome entering."); + + renderPhoneHome(request, response); + } + + private void renderPhoneHome(HttpServletRequest request, HttpServletResponse response) throws ServletException, + IOException { + ServletOutputStream stream = null; + BufferedInputStream buf = null; + FileInputStream input = null; + + try { + + stream = response.getOutputStream(); + response.setContentType("application/xml"); + + String confPath = getConfigPath(); + + confPath += File.separator + phoneHomeName; + + input = new FileInputStream(confPath); + // InputStream input = ctx.getResourceAsStream(phoneHomeName); + buf = new BufferedInputStream(input); + + int readBytes = 0; + while ((readBytes = buf.read()) != -1) + stream.write(readBytes); + + } catch (IOException e) { + CMS.debug("TPSPhoneHome.renderPhoneHome: Error encountered: " + e); + throw new ServletException("TPSPhoneHome.renderPhoneHome: Error encountered: " + e); + } finally { + if (stream != null) + stream.close(); + if (buf != null) + buf.close(); + if (input != null) + input.close(); + } + + } + + private String getConfigPath() { + + String path = null; + String context = getServletContext().getContextPath(); + + // get subsystem name by removing the / prefix from the context + String subsystem = context.startsWith("/") ? context.substring(1) : context; + + // catalina.base points to instance dir + String instanceDir = System.getProperty("catalina.base"); + + //Finish off path of conf directory + path = instanceDir + File.separator + "conf" + File.separator + + subsystem + File.separator; + + CMS.debug("TPSPhoneHome.getConfigPath: returning: " + path); + + return path; + + } + +} |