2015-06-02 23 views
1

我们从某处文件系统,但是外面的web应用程序的提供静态文件的简单问题苦苦挣扎,但我们不能让它运行。服务与码头静态文件karaf(外束)

有关于如何做到这一点的例子服务器,但他们都不工作,到目前为止,我们无法找到一个人,它实际上没有工作的确认。

,因为它是陈述 这里 https://ops4j1.jira.com/wiki/display/paxweb/Advanced+Jetty+Configuration 或这里 ops4j GitHub sample

所以加入的jetty.xml这在etc目录中找到的jetty.xml已被编辑:

<Get name="handler"> 
     <Call name="addHandler"> 
      <Arg> 
       <New class="org.eclipse.jetty.servlet.ServletContextHandler"> 
        <Set name="contextPath">/fileserver</Set> 
        <Set name="resourceBase">/Users/Shared/testenv</Set> 
        <Call name="addServlet"> 
         <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg> 
         <Arg>/</Arg> 
        </Call> 
       </New> 
      </Arg> 
     </Call> 
    </Get> 

或本:

<Get name="handler"> 
     <Call name="addHandler"> 
      <Arg> 
       <New class="org.eclipse.jetty.server.handler.ContextHandler"> 
        <Set name="contextPath">/fileserver</Set> 
        <Set name="handler"> 
         <New class="org.eclipse.jetty.server.handler.ResourceHandler"> 
          <Set name="resourceBase">/Users/Shared/testenv</Set> 
          <Set name="directoriesListed">true</Set> 
         </New> 
        </Set> 
       </New> 
      </Arg> 
     </Call> 
    </Get> 

With两个版本的jetty/karaf启动正常,当karaf关闭时,我可以看到

2015-06-02 12:02:57,838 | INFO | pool-7-thread-2 | ContextHandler
| org.eclipse.jetty.aggregate.jetty-all-server - 8.1.15.v20140411 |停止oejsServletContextHandler {/文件服务器,文件:/用户/共享/ testenv /}

但文件没有下本地主机服务:8181 /文件服务器

它是工作(在新安装的唯一途径卡拉夫容器)是使用

<Set name="handler"> 
     <New class="org.eclipse.jetty.server.handler.HandlerList"> 
      <Set name="handlers"> 
       <Array type="org.eclipse.jetty.server.Handler"> 
        <Item> 
         <New class="org.eclipse.jetty.servlet.ServletContextHandler"> 
          <Set name="contextPath">/fileserver</Set> 
          <Set name="resourceBase">/Users/Shared/testenv</Set> 
          <Call name="addServlet"> 
           <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg> 
           <Arg>/</Arg> 
          </Call> 
         </New> 
        </Item> 
       </Array> 
      </Set> 
     </New> 
    </Set> 

但是,这样做,将打破其他网络应用程序运行在卡拉夫。例如,我们使用Camel Servlet组件。

所以确实有人通过服务例如码头在karaf或静态文件现在如何做到这一点的工作配置?

任何帮助表示赞赏。预先感谢!

顺便说一句:使用Karaf 3.0.3

编辑:

我重新运行阿奇姆给出并启用DEBUG洛片断测试。

采用WordPress 15:33:25492 | DEBUG | pool-6-thread-1 | XmlConfiguration | 71 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.15.v20140411 | XML o.e.j.s.h.ContextHandler {/,null} .setContextPath(/ static-content) 2015-06-03 15:33:25,527 | DEBUG | pool-6-thread-1 | XmlConfiguration | 71 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.15.v20140411 | XML o.e.j.s.h.ContextHandler {/静态内容,NULL} .setHandler([email protected]) 2015年6月3日15:33:25529 | DEBUG | pool-6-thread-1 |货柜
| 71 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.15.v20140411 |容器o.e.j.s.h.ContextHandler {/ static-content,null} + [email protected] as handler 2015-06-03 15:33:25,529 | DEBUG | pool-6-thread-1 |货柜
| 71 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.15.v20140411 |容器 org.op[email protected]6665534e + o.e.j.s.h.ContextHandler {/ static-content,null} as handler 2015-06-03 15:33:25,542 | DEBUG | pool-6-thread-1 | AbstractLifeCycle
| 71 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.15.v20140411 |启动o.e.j.s.h.ContextHandler {/ static-content,null} 2015-06-03 15:33:25,542 | DEBUG | pool-6-thread-1 | AbstractHandler
| 71 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.15.v20140411 |启动o.e.j.s.h.ContextHandler {/ static-content,null} 2015-06-03 15:33:25,543 | DEBUG | pool-6-thread-1 | AbstractLifeCycle
| 71 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.15.v20140411 | STARTED o.e.j.s.h.ContextHandler {/ static-content,null} 2015-06-03 15:34:27,974 | DEBUG |/static-content |服务器
| 71 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.15.v20140411 | REQUEST/static-content on AsyncHttpConnection @ 638f2d20,g = HttpGenerator {s = 0,h = -1,b = -1,c = -1},p = HttpParser {s = -5,1 = 10,c = 0},r = 1 2015-06-03 15:34:27,974 | DEBUG |/static-content | ServerModel
| 78 - org.ops4j.pax.web.pax-web-spi - 3.1.4 |匹配 [/ static-content] ... 2015-06-03 15:34:27,975 | DEBUG | /static-content | ServerModel | 78 - org.ops4j.pax.web.pax-web-spi - 3.1.4 |路径[/静态内容]确实 不匹配任何上下文2015-06-03 15:34:27,975 | DEBUG | /static-content |服务器| 71 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.15.v20140411 | 响应/静态内容200处理=虚假

在这里,我注意到得到版本(不工作),并设置版本(工作)之间的差异。

设置设置类org.eclipse.jetty.server.handler.HandlerList get获取,并添加到类org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection,被描述为

码头处理程序的集合,只调用处理器(=上下文)是 执行后请求路径匹配基于字符串匹配的请求路径的 到注册别名

莫不是关于别名有问题吗?

编辑2:

我试图挖掘到这一点,但我真的不能得到这个工作。我不知道集成测试和常规karaf之间的区别,但必须有一个问题。要重现此问题,只需取一个新的karaf(3.0.3)容器,执行feature:install war并将该片段添加到etc/jetty.xml中,使其看起来像这样并编辑resourceBase的路径,使其与本地路径匹配。

<?xml version="1.0"?> 

<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting// 
DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> 

<Configure class="org.eclipse.jetty.server.Server"> 

    <!-- =========================================================== --> 
    <!-- Set connectors --> 
    <!-- =========================================================== --> 
    <!-- One of each type! --> 
    <!-- =========================================================== --> 

    <!-- Use this connector for many frequently idle connections and for 
     threadless continuations. --> 
    <Call name="addConnector"> 
     <Arg> 
      <New class="org.eclipse.jetty.server.nio.SelectChannelConnector"> 
       <Set name="host"> 
        <Property name="jetty.host" /> 
       </Set> 
       <Set name="port"> 
        <Property name="jetty.port" default="8181" /> 
       </Set> 
       <Set name="maxIdleTime">300000</Set> 
       <Set name="Acceptors">2</Set> 
       <Set name="statsOn">false</Set> 
       <Set name="confidentialPort">8443</Set> 
       <Set name="lowResourcesConnections">20000</Set> 
       <Set name="lowResourcesMaxIdleTime">5000</Set> 
      </New> 
     </Arg> 
    </Call> 

    <!-- =========================================================== --> 
    <!-- Configure Authentication Realms --> 
    <!-- Realms may be configured for the entire server here, or --> 
    <!-- they can be configured for a specific web app in a context --> 
    <!-- configuration (see $(jetty.home)/contexts/test.xml for an --> 
    <!-- example). --> 
    <!-- =========================================================== --> 
    <Call name="addBean"> 
     <Arg> 
      <New class="org.eclipse.jetty.plus.jaas.JAASLoginService"> 
       <Set name="name">karaf</Set> 
       <Set name="loginModuleName">karaf</Set> 
       <Set name="roleClassNames"> 
        <Array type="java.lang.String"> 
         <Item>org.apache.karaf.jaas.boot.principal.RolePrincipal 
         </Item> 
        </Array> 
       </Set> 
      </New> 
     </Arg> 
    </Call> 
    <Call name="addBean"> 
     <Arg> 
      <New class="org.eclipse.jetty.plus.jaas.JAASLoginService"> 
       <Set name="name">default</Set> 
       <Set name="loginModuleName">karaf</Set> 
       <Set name="roleClassNames"> 
        <Array type="java.lang.String"> 
         <Item>org.apache.karaf.jaas.boot.principal.RolePrincipal 
         </Item> 
        </Array> 
       </Set> 
      </New> 
     </Arg> 
    </Call> 
    <Get name="handler"> 
    <Call name="addHandler"> 
     <Arg> 
      <New class="org.eclipse.jetty.server.handler.ContextHandler"> 
       <Set name="contextPath">/static-content</Set> 
       <Set name="handler"> 
        <New class="org.eclipse.jetty.server.handler.ResourceHandler"> 
         <Set name="resourceBase">/Users/Shared/testenv/in</Set> 
         <Set name="directoriesListed">true</Set> 
        </New> 
       </Set> 
      </New> 
     </Arg> 
    </Call> 
</Get> 

</Configure> 

尝试使用localhost:8181/static-content通过浏览器访问上下文。

结果始终为404 - 未找到。

我们已经在运行linux和windows的多个系统上试过了。

回答

1

这个问题可能与pax-web版本有关。在卡拉夫3.0.5它使用我已阅读(对不起,我无法找到链接)版本的Pax-web 3.2.6有一个与提供静态内容相关的错误。

我已经在卡拉夫4.0.3(Pax-web 4.2.3)中测试过@ Achim的方法,它的工作方式就像魅力一样。

0

其实你已经在你的样品中得到了它,这是最好的方式。 正如可以看到这integration test它正在工作。

,所以请确保您有根据本吧:

<Get name="handler"> 
    <Call name="addHandler"> 
     <Arg> 
      <New class="org.eclipse.jetty.server.handler.ContextHandler"> 
       <Set name="contextPath">/static-content</Set> 
       <Set name="handler"> 
        <New class="org.eclipse.jetty.server.handler.ResourceHandler"> 
         <Set name="resourceBase">target/logs</Set> 
         <Set name="directoriesListed">true</Set> 
        </New> 
       </Set> 
      </New> 
     </Arg> 
    </Call> 
</Get> 
+0

我再次检查并在上述问题中提出了一些更多的细节。感谢您查看这个。 – Florian

+0

Achim与Karaf 3.0.5,只是将此片段添加到jetty.xml中并不适用于我。我刚刚公布了我作为这个问题的答案所采取的确切步骤(请参阅上文)。 –

0

我不能得到这个工作的。 使用新鲜下载Karaf 3.0.5:

$ cd /tmp 
$ tar xzf ~/Downloads/apache-karaf-3.0.5.tar.gz 
$ ./apache-karaf-3.0.5/bin/karaf 
     __ __     ____  
    ///_/____ __________ _/ __/  
    /,</__ `/ ___/ __ `/ /_   
    //| |/ /_/////_//__/   
    /_/ |_|\__,_/_/ \__,_/_/   

    Apache Karaf (3.0.5) 

Hit '<tab>' for a list of available commands 
and '[cmd] --help' for help on a specific command. 
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown Karaf. 

[email protected]()> 

检查东西是否有尚未:

$ curl http://localhost:8181/ 
curl: (7) Failed to connect to localhost port 8181: Connection refused 

好。还没有码头。

安装PAX网络

[email protected]()> feature:repo-add mvn:org.ops4j.pax.web/pax-web-features/2.1.0/xml/features 
Adding feature url mvn:org.ops4j.pax.web/pax-web-features/2.1.0/xml/features 
[email protected]()> feature:install pax-jetty 
[email protected]()> feature:install http 

,卷曲

$ curl http://localhost:8181/ 
... 
<h2>HTTP ERROR: 404</h2> 
<hr /><i><small>Powered by Jetty://</small></i> 
... 

好再次检查。码头还活着。

添加ResourceHandler到Apache的karaf-3.0.5的/ etc /的jetty.xml

<Get name="handler"> 
    <Call name="addHandler"> 
     <Arg> 
      <New class="org.eclipse.jetty.server.handler.ContextHandler"> 
       <Set name="contextPath">/static-content</Set> 
       <Set name="handler"> 
        <New class="org.eclipse.jetty.server.handler.ResourceHandler"> 
         <Set name="resourceBase">/tmp</Set> 
         <Set name="directoriesListed">true</Set> 
        </New> 
       </Set> 
      </New> 
     </Arg> 
    </Call> 
</Get> 

卷曲仍认为404:

$ curl http://localhost:8181/ 
... 
<h2>HTTP ERROR: 404</h2> 
... 

不知道我需要重新启动任何东西。无论如何,我重新启动整个卡拉夫。

两个卷发给404:

$ curl http://localhost:8181/ 
$ curl http://localhost:8181/static-content 

在Apache的karaf-3.0.5的/ etc/org.ops4j.pax.logging.cfg

log4j.rootLogger=DEBUG, out, osgi:* 

卷曲仍然得到404启用调试日志记录对于http://localhost:8181/static-content和karaf.log说:

2015-11-14 12:57:00,938 | DEBUG | 673-63 Selector0 | nio        | 70 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.17.v20150415 | created [email protected]{l(/127.0.0.1:46304)<->r(/127.0.0.1:8181),s=0,open=true,ishut=false,oshut=false,rb=false,wb=false,w=true,i=0}-{[email protected],g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} 
2015-11-14 12:57:00,939 | DEBUG | qtp425678673-70 | HttpParser      | 70 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.17.v20150415 | filled 92/92 
2015-11-14 12:57:00,939 | DEBUG | /static-content | Server       | 70 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.17.v20150415 | REQUEST /static-content on [email protected],g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=-5,l=3,c=0},r=1 
2015-11-14 12:57:00,940 | DEBUG | /static-content | ServerModel      | 77 - org.ops4j.pax.web.pax-web-spi - 3.2.6 | Matching [/static-content]... 
2015-11-14 12:57:00,940 | DEBUG | /static-content | ServerModel      | 77 - org.ops4j.pax.web.pax-web-spi - 3.2.6 | Path [/static-content] does not match any context 
2015-11-14 12:57:00,940 | DEBUG | /static-content | Server       | 70 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.17.v20150415 | RESPONSE /static-content 200 handled=false 
2015-11-14 12:57:00,940 | DEBUG | qtp425678673-70 | AsyncHttpConnection    | 70 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.17.v20150415 | Enabled read interest [email protected]{l(/127.0.0.1:46304)<->r(/127.0.0.1:8181),s=1,open=true,ishut=false,oshut=false,rb=false,wb=false,w=true,i=0r}-{[email protected],g=HttpGenerator{s=4,h=0,b=0,c=-1},p=HttpParser{s=0,l=3,c=0},r=1} 
2015-11-14 12:57:00,941 | DEBUG | qtp425678673-70 | ChannelEndPoint     | 70 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.17.v20150415 | ishut [email protected]{l(/127.0.0.1:46304)<->r(/127.0.0.1:8181),s=1,open=true,ishut=false,oshut=false,rb=false,wb=false,w=true,i=0r}-{[email protected],g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=-3},r=1} 
2015-11-14 12:57:00,941 | DEBUG | qtp425678673-70 | HttpParser      | 70 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.17.v20150415 | filled -1/0 
2015-11-14 12:57:00,941 | DEBUG | qtp425678673-70 | AsyncHttpConnection    | 70 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.17.v20150415 | Disabled read interest while writing response [email protected]{l(/127.0.0.1:46304)<->r(/127.0.0.1:8181),s=1,open=true,ishut=true,oshut=false,rb=false,wb=false,w=true,i=0r}-{[email protected],g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=0,l=0,c=-3},r=1} 
2015-11-14 12:57:00,942 | DEBUG | qtp425678673-70 | ChannelEndPoint     | 70 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.17.v20150415 | close [email protected]{l(/127.0.0.1:46304)<->r(/127.0.0.1:8181),s=1,open=true,ishut=true,oshut=false,rb=false,wb=false,w=true,i=0r}-{[email protected],g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=0,l=0,c=-3},r=1} 
2015-11-14 12:57:00,942 | DEBUG | 673-63 Selector0 | nio        | 70 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.17.v20150415 | destroyEndPoint [email protected]{l(null)<->r(0.0.0.0/0.0.0.0:8181),s=0,open=false,ishut=true,oshut=true,rb=false,wb=false,w=true,i=0!}-{[email protected],g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=0,l=0,c=-3},r=1} 
2015-11-14 12:57:00,943 | DEBUG | 673-63 Selector0 | AbstractHttpConnection   | 70 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.17.v20150415 | closed [email protected],g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=0,l=0,c=-3},r=1 

然后尝试DefaultServlet为纲的Advanced Jetty Configuration, 与

<Get name="handler"> 
    <Call name="addHandler"> 
     <Arg> 
    <New class="org.eclipse.jetty.servlet.ServletContextHandler"> 
      <Set name="contextPath">/static-content</Set> 
      <Set name="resourceBase">/tmp</Set> 
      <Call name="addServlet"> 
      <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg> 
      <Arg>/</Arg> 
      </Call> 
     </New> 
     </Arg> 
    </Call> 
</Get> 

重新启动Karaf代替我以前在另外的jetty.xml,和卷曲http://localhost:8181/static-content仍然给404 和Karaf日志本质上说,同与ResourceHandler。

什么是缺失?

+2

这并没有真正回答这个问题。如果您有不同的问题,可以通过单击[提问](http://stackoverflow.com/questions/ask)来提问。您也可以[添加赏金](http://stackoverflow.com/help/privileges/set-bounties)来引起对此问题的更多关注。 - [来自评论](/ review/low-quality-posts/10205763) – theB

+0

正确,我的“答案”实际上并没有回答这个问题。 我将其添加为Achim评论的后续内容,提供有关如何重现问题的更多详细信息。 –