<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: tomcat code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 01:41:21 GMT</pubDate>
    <description>DZone Snippets: tomcat code</description>
    <item>
      <title>Common keytool commands needed for living with Java</title>
      <link>http://snippets.dzone.com/posts/show/5362</link>
      <description>&lt;code&gt;&lt;br /&gt;// generate a key -- make it long lived so we dont have to do this again&lt;br /&gt;keytool -genkey -alias tomcat -keyalg RSA -validity 3650 -storepass changeit&lt;br /&gt;&lt;br /&gt;// export cert to a file&lt;br /&gt;keytool -export -rfc -v -file tomcatCert.crt -alias tomcat -storepass changeit&lt;br /&gt; &lt;br /&gt;// look at the cert in the file&lt;br /&gt;keytool -printcert -file tomcatCert.crt -storepass changeit&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// delete pre-existing cert&lt;br /&gt;keytool -delete -alias tomcat -keystore c:/apps/jdk/jre/lib/security/cacerts -storepass changeit&lt;br /&gt;&lt;br /&gt;// import cert into a keystore&lt;br /&gt;keytool -import -file tomcatCert.crt -trustcacerts -alias tomcat -keystore c:/apps/jdk/jre/lib/security/cacerts -storepass changeit&lt;br /&gt;&lt;br /&gt;// look at the imported cert&lt;br /&gt;keytool -list -alias tomcat -keystore c:/apps/jdk/jre/lib/security/cacerts -storepass changeit&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 14 Apr 2008 18:06:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5362</guid>
      <author>frost137 (Douglas Wyatt)</author>
    </item>
    <item>
      <title>Overriding Tomcat Valve to return extended login failure status</title>
      <link>http://snippets.dzone.com/posts/show/3715</link>
      <description>See &lt;a href="http://shadegrowncode.blogspot.com/2007/03/returning-login-failure-reason-in.html"&gt;Shade Grown Code&lt;/a&gt; for more information.&lt;br /&gt;&lt;br /&gt;ExtendedStatusSetter.java&lt;br /&gt;&lt;code&gt;&lt;br /&gt;package com.ofc.tomcat;&lt;br /&gt;&lt;br /&gt;import javax.servlet.http.HttpServletRequest;&lt;br /&gt;import javax.servlet.http.HttpServletResponse;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * Interface flagging that the implementing Realm can set request&lt;br /&gt; * headers providing additional information about an authentication&lt;br /&gt; * failure.&lt;br /&gt; *&lt;br /&gt; * @author Nicholas Sushkin&lt;br /&gt; */&lt;br /&gt;public interface ExtendedStatusSetter&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     * The request attribute under which we forward an extended failure status message&lt;br /&gt;     * (as an object of type String) to a login error page.&lt;br /&gt;     */&lt;br /&gt;    public static String LOGIN_FAILURE_MESSAGE_ATTR = &lt;br /&gt;        "com.ofc.tomcat.LOGIN_FAILURE_MESSAGE";&lt;br /&gt;    &lt;br /&gt;    public void setExtendedStatus(String username, HttpServletRequest request, HttpServletResponse response);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;ExtendedStatusFormAuthenticator.java&lt;br /&gt;&lt;code&gt;&lt;br /&gt;package com.ofc.tomcat;&lt;br /&gt;&lt;br /&gt;import org.apache.catalina.authenticator.Constants;&lt;br /&gt;import org.apache.catalina.authenticator.FormAuthenticator;&lt;br /&gt;import org.apache.catalina.Realm;&lt;br /&gt;import org.apache.catalina.connector.Request;&lt;br /&gt;import org.apache.catalina.connector.Response;&lt;br /&gt;import org.apache.catalina.deploy.LoginConfig;&lt;br /&gt;import org.apache.commons.logging.Log;&lt;br /&gt;import org.apache.commons.logging.LogFactory;&lt;br /&gt;import javax.servlet.RequestDispatcher;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * Adds extended authentication failure status to tomcat FormAuthenticator.&lt;br /&gt; *&lt;br /&gt; * @author Nicholas Sushkin&lt;br /&gt; */&lt;br /&gt;public class ExtendedStatusFormAuthenticator extends FormAuthenticator&lt;br /&gt;{&lt;br /&gt;    /**&lt;br /&gt;     * Descriptive information about this implementation.&lt;br /&gt;     */&lt;br /&gt;    protected static final String info =&lt;br /&gt;        "com.ofc.tomcat.ExtendedStatusFormAuthenticator/1.0";&lt;br /&gt;&lt;br /&gt;    private static Log log = LogFactory.getLog(ExtendedStatusFormAuthenticator.class);&lt;br /&gt;&lt;br /&gt;    // ------------------------------------------------------------- Properties&lt;br /&gt;    /**&lt;br /&gt;     * Return descriptive information about this Valve implementation.&lt;br /&gt;     */&lt;br /&gt;    @Override&lt;br /&gt;    public String getInfo() &lt;br /&gt;    {&lt;br /&gt;        return info;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    // ------------------------------------------------------------- Overridden behavior&lt;br /&gt;    /**&lt;br /&gt;     * Called to forward to the error page&lt;br /&gt;     * &lt;br /&gt;     * @param request Request we are processing&lt;br /&gt;     * @param response Response we are creating&lt;br /&gt;     * @param config    Login configuration describing how authentication&lt;br /&gt;     *              should be performed&lt;br /&gt;     */&lt;br /&gt;    @Override&lt;br /&gt;    protected void forwardToErrorPage(Request request, Response response, LoginConfig config) &lt;br /&gt;    {&lt;br /&gt;        Realm realm = context.getRealm();&lt;br /&gt;&lt;br /&gt;        if (realm instanceof ExtendedStatusSetter)&lt;br /&gt;        {&lt;br /&gt;            log.debug("realm implements ExtendedStatusSetter, setting extended status for error page");&lt;br /&gt;            String username = request.getParameter(Constants.FORM_USERNAME);&lt;br /&gt;            ((ExtendedStatusSetter) realm).setExtendedStatus(username, request.getRequest(), response.getResponse());&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            log.debug("realm does not implement ExtendedStatusSetter, NOT setting extended status for error page");&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        RequestDispatcher disp =&lt;br /&gt;            context.getServletContext().getRequestDispatcher&lt;br /&gt;            (config.getErrorPage());&lt;br /&gt;        try {&lt;br /&gt;            disp.forward(request.getRequest(), response.getResponse());&lt;br /&gt;            response.finishResponse();&lt;br /&gt;        } catch (Throwable t) {&lt;br /&gt;            log.warn("Unexpected error forwarding to error page", t);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Realm implementation will include the following&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public class AccountLockoutDatasourceRealm extends DataSourceRealm implements ExtendedStatusSetter&lt;br /&gt;{&lt;br /&gt;    // ...&lt;br /&gt;&lt;br /&gt;    public void setExtendedStatus(String username, HttpServletRequest request, HttpServletResponse response)&lt;br /&gt;    {&lt;br /&gt;        setMessage(request, "Account locked");&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    protected void setMessage(HttpServletRequest request, String message)&lt;br /&gt;    {&lt;br /&gt;        request.setAttribute(ExtendedStatusSetter.LOGIN_FAILURE_MESSAGE_ATTR, message);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 22 Mar 2007 22:25:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3715</guid>
      <author>NicholasSushkin (Nicholas Sushkin)</author>
    </item>
    <item>
      <title>Tomcat debug</title>
      <link>http://snippets.dzone.com/posts/show/3098</link>
      <description>// description of your code here&lt;br /&gt;Parametre de conf pour lancer un tomcat en debug afin de se connecter a distance sur le port 8000&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Xdebug -Xrunjdwp:transport=dt_socket,adress=8000,server=y,suspend=n&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 06 Dec 2006 18:25:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3098</guid>
      <author>Mickael (Mickael)</author>
    </item>
    <item>
      <title>Getting A Data Source From Tomcat</title>
      <link>http://snippets.dzone.com/posts/show/1595</link>
      <description>// You can setup a data source in tomcat using a context file&lt;br /&gt;// or you can set one up using the Administration web pages&lt;br /&gt;// as well. Either way you do it, here is the simple code to&lt;br /&gt;// get the data source from Tomcat so you can start pulling&lt;br /&gt;// out database connections.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// Obtain our environment naming context&lt;br /&gt;Context initCtx = new InitialContext();&lt;br /&gt;Context envCtx = (Context) initCtx.lookup("java:comp/env");&lt;br /&gt;&lt;br /&gt;// Look up our data source by the name we gave it when we created it. &lt;br /&gt;// In this case that's "jdbc/EmployeeDB".&lt;br /&gt;DataSource ds = (DataSource) envCtx.lookup("jdbc/EmployeeDB");&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 28 Feb 2006 04:13:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1595</guid>
      <author>JohnMunsch (John Munsch)</author>
    </item>
    <item>
      <title>StartupItem Script for Tomcat on OS X 10.3</title>
      <link>http://snippets.dzone.com/posts/show/790</link>
      <description>&lt;code&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;        &lt;br /&gt;##&lt;br /&gt;# Start Tomcat&lt;br /&gt;##&lt;br /&gt;&lt;br /&gt;. /etc/rc.common&lt;br /&gt;&lt;br /&gt;export JAVA_HOME=/Library/Java/Home&lt;br /&gt;export CATALINA_HOME="/usr/local/tomcat"&lt;br /&gt;export TOMCAT_HOME="/usr/local/tomcat"&lt;br /&gt;&lt;br /&gt;StartService ()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;	if [ "${TOMCAT:=-NO-}" = "-YES-" ]; then&lt;br /&gt;&lt;br /&gt;	    ConsoleMessage "Starting Tomcat"&lt;br /&gt;            sh ${TOMCAT_HOME}/bin/startup.sh&lt;br /&gt;	fi&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;StopService()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;	ConsoleMessage "Stopping Tomcat"&lt;br /&gt;    sh ${TOMCAT_HOME}/bin/shutdown.sh&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;RestartService ()&lt;br /&gt;{&lt;br /&gt;    StopService&lt;br /&gt;    StartService&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;RunService "$1"&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 06 Oct 2005 23:50:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/790</guid>
      <author>santry (Sean Santry)</author>
    </item>
    <item>
      <title>Killing Tomcat on Linux</title>
      <link>http://snippets.dzone.com/posts/show/318</link>
      <description>&lt;code&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;&lt;br /&gt;#args to pass to kill&lt;br /&gt;ARG=$1&lt;br /&gt;&lt;br /&gt;for file in `find /proc -regex /proc/[0-9]+ 2&gt; /dev/null`; do&lt;br /&gt;&lt;br /&gt;    # FIXME: this will execute the command but I don't think that grep &lt;br /&gt;    # if `grep org.apache.catalina.startup.Bootstrap $file/cmdline`; then &lt;br /&gt;&lt;br /&gt;    if `grep --silent org.apache.catalina.startup.Bootstrap $file/cmdline 2&gt; /dev/null`; then &lt;br /&gt;&lt;br /&gt;        #get the localname of this process id.&lt;br /&gt;        #cat $file/cmdline&lt;br /&gt;&lt;br /&gt;        #now go ahead and kill this guy&lt;br /&gt;        base=`basename $file`&lt;br /&gt;        echo kill $ARG $base&lt;br /&gt;        kill $ARG $base&lt;br /&gt;&lt;br /&gt;    fi &lt;br /&gt;&lt;br /&gt;done&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 24 May 2005 23:59:24 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/318</guid>
      <author>l00pek (l00pek)</author>
    </item>
  </channel>
</rss>
