您可以在Jetty中为每个Web应用程序分配jetty-rewrite.xml文件吗? [英] Can you assign per web app jetty-rewrite.xml files in Jetty?

查看:106
本文介绍了您可以在Jetty中为每个Web应用程序分配jetty-rewrite.xml文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个Web应用程序/上下文是否有一种方法可以仅针对特定Web应用程序指定重写文件?我看到当前正在工作的唯一方法是在启动它时通过命令行.我在想,也许是override.xml文件甚至上下文xml文件中的设置.

Is there a way per web app / context to specify a rewrite file just for that particular webapp? The only way I see this currently working is via the command line when you start it. I was thinking perhaps a setting in the override.xml file or even in the context xml file.

推荐答案

如果使用context.xml可部署对象,则可以将RewriteHandler规则集成到应用程序特定的上下文xml中.

If you use context.xml deployables you can integrate the RewriteHandler rules into the app specific context xml.

示例:这是在码头分布中找到的${jetty.home}/contexts/test.xml的替换context.xml.它添加了一条规则,该规则只是在所有请求的响应上添加一个cookie(visited = yes).

Example: this is a replacement context.xml of the ${jetty.home}/contexts/test.xml found in the jetty-distribution. It adds a rule that simply adds a cookie (visited=yes) on the response for all requests.

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
  <Set name="contextPath">/</Set>
  <Set name="handler">
    <New id="Rewrite" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">
      <Set name="handler">
        <New class="org.eclipse.jetty.webapp.WebAppContext">
          <Set name="contextPath">/</Set>
          <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test.war</Set>
          <Set name="extractWAR">true</Set>
          <Set name="copyWebDir">false</Set>
          <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
          <Set name="overrideDescriptor"><SystemProperty name="jetty.home" default="."/>/contexts/test.d/override-web.xml</Set>
        </New>
      </Set>
      <Set name="rewriteRequestURI">true</Set>
      <Set name="rewritePathInfo">false</Set>
      <Set name="originalPathAttribute">requestedPath</Set>

      <!-- add a cookie to each path visited -->
      <Call name="addRule">
        <Arg>
          <New class="org.eclipse.jetty.rewrite.handler.CookiePatternRule">
            <Set name="pattern">/*</Set>
            <Set name="name">visited</Set>
            <Set name="value">yes</Set>
          </New>
        </Arg>
      </Call>
     </New>
  </Set>
</Configure>

要验证此规则是否有效,请启动码头,转到http://localhost:8080/,然后使用会话"测试组件,您会看到visited=true在顶部显示为cookie.

To verify that this rule works, start jetty, goto http://localhost:8080/ and then use the "Sessions" test component, you'll see that visited=true will be visible as a cookie at the top.

这篇关于您可以在Jetty中为每个Web应用程序分配jetty-rewrite.xml文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆