0

実行時に JSESSIONID Cookie の PATH を動的に変更できる必要がある Java アプリケーションを Tomcat 6.0.24 で実行しています。最も簡単な方法は org.apache.catalina.core.StandardContext を拡張し、代わりに getEncodedPath 関数をオーバーライドすることであると判断するまで、フィルターで Cookie を操作することに長い時間を費やしました。

StandardContext を拡張する MultiTabContext というカスタム コンテキストを作成し、発生したすべてのクラスパスの問題を取り除きました。Context を catalina/conf/server.xml に定義しました (context.xml にある必要があることはわかっていますが、後でその問題に取り組みます)。

<Server port="8005" shutdown="SHUTDOWN">
  ...
  <Service name="Catalina">
    ...
    <Engine name="Catalina" defaultHost="localhost">
      ...
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
        ...
        <!-- HERE IS MY CONTEXT -->
        <Context className="foo.app.server.MultiTabContext"
                 path=""
                 crossContext="false"
                 debug="0"
                 reloadable="true"/>
      </Host>
    </Engine>
  </Service>
</Server>

これが私の MultiTabContext です:

package foo.app.server;

import org.apache.catalina.core.StandardContext;

public class MultiTabContext extends StandardContext {

    @Override
    public String getEncodedPath() {
        return super.getEncodedPath();
    }
}

パスが "" であるため、StandardContext ではなく、すべてのリクエストでコンテキストが使用されることを期待していました。ただし、アプリケーションは私の代わりにまだ StandardContext を使用しています。Tomcat が StandardContext の代わりに私のものを使用するように Context を定義する方法を知っている人はいますか (または JSESSIONID Cookie パスを動的に変更するためのより良い方法を知っていますか)?

4

1 に答える 1

0

天気があなたの質問に答えるのに役立つかどうかはわかりません。しかし、私には役立つかもしれないアプローチがあります。リクエストが処理されるときに、実行時にJSESSIONIDCookieパスを変更できます。

/**
 * This gets the information from the request
 * 
 * @param parameter, pass JSESSION ID 
 * @return
 */
protected String getRequestInfo(HttpServletRequest request, String parameter)
{
    Cookie[] cookies = null;
    if (request.getRequestURI() == null || request.getRequestURI().length() == 0) 
    {
        performanceLogger.debug(" Request generated null pointer");
    }
    try 
    {
        cookies = request.getCookies();
    } 
    catch (Exception ex)
    {
        cookies = null;

    }
    if (cookies == null || cookies.length == 0)
    {
        return null;
    }

    String paramValue = null;
    for (Cookie c : cookies)
    {
        if (c.getName().equals(parameter)) 
        {
            //change the path of JESSION ID over here 
            break;
        }
    }
    return paramValue;
}
于 2013-01-31T22:52:45.110 に答える