/* * @(#)AdminURLServlet.java 1.18 97/10/25 * * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved. * * This software is the confidential and proprietary information of Sun * Microsystems, Inc. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Sun. * * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. * * CopyrightVersion 1.0 */ import java.io.*; import java.net.InetAddress; import javax.servlet.*; import javax.servlet.http.*; import com.sun.server.*; import com.sun.server.http.*; /** * Admin URL servlet. This servlet finds out the web page for this service's * administration, and return its HREF as a pre-formatted HTML link. * *
NOTE: This servlet relies on internal APIs of the Java Web * Server, which are subject to change. */ public class AdminURLServlet extends HttpServlet { private String linkMessage = "Administration Service"; /** * Set the message for the link. Different sites can use * different messages, for example in different languages. */ public void setLinkMessage (String message) { linkMessage = message; } /** * Get the message for the link. */ public String getLinkMessage () { return linkMessage; } /** * Returns a pre-formatted HTML link. */ public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { try { // // get Admin Service handles // // XXX this returns the wrong service -- it's for this process, // not the "mother of services". // Service adminService = ServiceManager.getService("adminservice"); ServiceParameters adminParams = adminService.getParameters(); ServiceEndpoint ep = (adminService.getEndpoints())[0]; // // use transport endpoint to get network addressing info // int adminPort = ep.getPort(); String adminHost = ep.getInterface(); if (adminHost.equals("*")) { adminHost = ServerProcess.getParameters().getDefaultHost(); } // // construct a HTML "href" to identify the URL of the web page // used to adminster the service. // StringBuffer hrefString = new StringBuffer(); // XXX doesn't support use of HTTPS !! hrefString.append(""); hrefString.append(linkMessage); String outString = hrefString.toString(); PrintWriter out = res.getWriter (); out.println(outString); } catch (IOException e) { throw e; } catch (Exception exc) { throw new ServletException ( "Cannot create administration tool URL: " + exc.getMessage()); } } private static void debug(String message) { if (debugging) { System.err.println("AdminURLServlet: " + message); } } private static final boolean debugging = false; }