1

我正在通过框架实现 Felix 5.4 玩 OSGi。目前我想在 OSGi 框架上安装一个应用程序服务器作为一个包。我看过 Pax-web,这对我来说似乎是完美的解决方案。但是,在成功启动所有必需的捆绑包后,该软件抱怨以下错误:

org.ops4j.pax.web.pax-web-jetty-bundle[org.ops4j.pax.web.service.internal.Activator] : Unable to start pax web server: Exception while starting Jetty
java.lang.RuntimeException: Exception while starting Jetty
        at org.ops4j.pax.web.service.jetty.internal.JettyServerImpl.start(JettyServerImpl.java:188)
        at org.ops4j.pax.web.service.jetty.internal.ServerControllerImpl$Stopped.start(ServerControllerImpl.java:415)
        at org.ops4j.pax.web.service.jetty.internal.ServerControllerImpl.start(ServerControllerImpl.java:71)
        at org.ops4j.pax.web.service.jetty.internal.ServerControllerImpl$Unconfigured.configure(ServerControllerImpl.java:707)
        at org.ops4j.pax.web.service.jetty.internal.ServerControllerImpl.configure(ServerControllerImpl.java:87)
        at org.ops4j.pax.web.service.internal.Activator.updateController(Activator.java:353)
        at org.ops4j.pax.web.service.internal.Activator$3.run(Activator.java:295)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.ops4j.pax.web.service.jetty.internal.JettyServerImpl.start(JettyServerImpl.java:151)
        ... 11 more
Caused by: java.lang.NoSuchMethodException: class org.eclipse.jetty.server.HttpConfiguration.setMaxErrorDispatches(class java.lang.String)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.set(XmlConfiguration.java:582)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:411)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:815)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:423)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:298)
        at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:248)
        ... 16 more

通过查看错误,似乎某些 Jetty 配置在 pax-embedded jetty 版本中不可用。特别是maxErrorDispatches,blockingTimeoutpersistentConnectionsEnabled导致错误。但是,即使注释掉这 3 个属性,pax-web 也不会启动(无法连接到 127.0.0.1),并且在一些日志之后,只会打印:

org.ops4j.pax.web.pax-web-jetty-bundle[org.ops4j.pax.web.service.internal.ConfigurationImpl]:读取配置属性 org.ops4j.pax.web.config.url 失败

我试图解决这个问题,但由于我不是 OSGi 和 Jetty 的专家,所以我想不出任何解决方案。为了给我的场景添加一些上下文,这里有一些额外的信息:

  • 我正在使用 felix 5.4;
  • 我使用的是 Windows 10 64 位;
  • jetty.xml i在conf/、bin/felix文件夹同目录下;
  • 发射费利克斯通过java -jar bin\felix.jar

安装的捆绑包:

lb
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (5.6.0)|5.6.0
    1|Active     |    1|ASM (5.1.0)|5.1.0
    2|Active     |    1|ASM commons classes (5.1.0)|5.1.0
    3|Active     |    1|ASM Tree class visitor (5.1.0)|5.1.0
    4|Active     |    1|javax.servlet API v.3.0 (3.0.0.SNAPSHOT)|3.0.0.SNAPSHOT
    5|Active     |    1|Apache Felix Bundle Repository (2.0.8)|2.0.8
    6|Active     |    1|Apache Felix Gogo Command (0.16.0)|0.16.0
    7|Active     |    1|Apache Felix Gogo Runtime (0.16.2)|0.16.2
    8|Active     |    1|Apache Felix Gogo Shell (0.10.0)|0.10.0
    9|Active     |    1|osgi (3.0.0)|3.0.0
   10|Active     |    1|OPS4J Pax Logging - API (1.9.0)|1.9.0
   11|Active     |    1|OPS4J Pax Web - API (4.3.0)|4.3.0
   12|Active     |    1|OPS4J Pax Web - Extender - WAR (4.3.0)|4.3.0
   13|Active     |    1|OPS4J Pax Web - Jetty Bundle (4.3.0)|4.3.0
   14|Active     |    1|OPS4J Pax Web - Jsp Support (4.3.0)|4.3.0
   15|Active     |    1|OPS4J Pax Web - Service SPI (4.3.0)|4.3.0
   16|Active     |    1|Apache XBean OSGI Bundle Utilities (4.5.0)|4.5.0
   17|Active     |    1|Apache XBean :: Classpath Resource Finder (4.5.0)|4.5.0

config.properties(从评论中删除):

org.osgi.framework.system.packages.extra=org.apache.juli.logging

org.osgi.framework.bootdelegation=sun.*,com.sun.*

org.osgi.framework.storage.clean=onFirstInit

felix.auto.deploy.action=install,start

felix.auto.deploy.dir=pax

felix.log.level=1

org.osgi.framework.startlevel.beginning=1

felix.startlevel.bundle=1

org.osgi.service.http.port=8080
obr.repository.url=http://felix.apache.org/obr/releases.xml

org.ops4j.pax.web.config.file=jetty.xml

码头配置(无注释):

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

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

    <Get name="ThreadPool">
      <Set name="minThreads" type="int"><Property name="jetty.threadPool.minThreads" deprecated="threads.min" default="10"/></Set>
      <Set name="maxThreads" type="int"><Property name="jetty.threadPool.maxThreads" deprecated="threads.max" default="200"/></Set>
      <Set name="idleTimeout" type="int"><Property name="jetty.threadPool.idleTimeout" deprecated="threads.timeout" default="60000"/></Set>
      <Set name="detailedDump">false</Set>
    </Get>

    <Call name="addBean">
      <Arg>
        <New class="org.eclipse.jetty.util.thread.ScheduledExecutorScheduler"/>
      </Arg>
    </Call>

    <New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
      <Set name="secureScheme"><Property name="jetty.httpConfig.secureScheme" default="https" /></Set>
      <Set name="securePort"><Property name="jetty.httpConfig.securePort" deprecated="jetty.secure.port" default="8443" /></Set>
      <Set name="outputBufferSize"><Property name="jetty.httpConfig.outputBufferSize" deprecated="jetty.output.buffer.size" default="32768" /></Set>
      <Set name="outputAggregationSize"><Property name="jetty.httpConfig.outputAggregationSize" deprecated="jetty.output.aggregation.size" default="8192" /></Set>
      <Set name="requestHeaderSize"><Property name="jetty.httpConfig.requestHeaderSize" deprecated="jetty.request.header.size" default="8192" /></Set>
      <Set name="responseHeaderSize"><Property name="jetty.httpConfig.responseHeaderSize" deprecated="jetty.response.header.size" default="8192" /></Set>
      <Set name="sendServerVersion"><Property name="jetty.httpConfig.sendServerVersion" deprecated="jetty.send.server.version" default="true" /></Set>
      <Set name="sendDateHeader"><Property name="jetty.httpConfig.sendDateHeader" deprecated="jetty.send.date.header" default="false" /></Set>
      <Set name="headerCacheSize"><Property name="jetty.httpConfig.headerCacheSize" default="512" /></Set>
      <Set name="delayDispatchUntilContent"><Property name="jetty.httpConfig.delayDispatchUntilContent" deprecated="jetty.delayDispatchUntilContent" default="true"/></Set>
      <Set name="maxErrorDispatches"><Property name="jetty.httpConfig.maxErrorDispatches" default="10"/></Set>
      <Set name="blockingTimeout"><Property name="jetty.httpConfig.blockingTimeout" default="-1"/></Set>
      <Set name="persistentConnectionsEnabled"><Property name="jetty.httpConfig.persistentConnectionsEnabled" default="true"/></Set>
    </New>

    <Set name="handler">
      <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
        <Set name="handlers">
         <Array type="org.eclipse.jetty.server.Handler">
           <Item>
             <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
           </Item>
           <Item>
             <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
           </Item>
         </Array>
        </Set>
      </New>
    </Set>

    <Set name="stopAtShutdown"><Property name="jetty.server.stopAtShutdown" default="true"/></Set>
    <Set name="stopTimeout"><Property name="jetty.server.stopTimeout" default="5000"/></Set>
    <Set name="dumpAfterStart"><Property name="jetty.server.dumpAfterStart" deprecated="jetty.dump.start" default="false"/></Set>
    <Set name="dumpBeforeStop"><Property name="jetty.server.dumpBeforeStop" deprecated="jetty.dump.stop" default="false"/></Set>

</Configure>
4

1 回答 1

0

您的码头版本似乎与 pax 网络版本相匹配。所以这应该不是问题。

我刚刚在 Apache karaf 4.0.7 中测试了 pax web。也使用了 pax-web 4.3.0 和 jetty 9.2.1。不过,Karaf 使用单独的码头捆绑包。

所以我怀疑 pax-web-jetty-bundle 中有错误。您可以为此在 ops4j 上打开 jira 问题吗?

现在要解决您的问题,您应该安装 Apache karaf 使用的相同包。下载并启动 karaf 4.0.7 并执行功能:安装 http。

然后使用 la -u 检查捆绑包。如果您使用相同的捆绑包,那么它也应该适用于您。

于 2016-10-18T07:24:21.617 回答