我正在學習如何將Apache Velocity與Apache Camel(在Karaf中)用於託管動態網頁,但是當我嘗試在另一個包含速度文件時收到資源錯誤即使他們在同一個目錄中。camel-velocity找不到資源
如果我從第一個文件中刪除行#parse("${page}.vm")
,一切都按預期工作。
這是我的整個設置。除安裝camel-velocity和jetty-9外,此處未列出的所有內容均爲默認的ServiceMix 7.0.0安裝程序。
駱駝路線
<route id="web_route">
<from uri="jetty:http://localhost:8080/test?sessionSupport=true&matchOnUriPrefix=true"/>
<to uri="velocity:file:web/vm/webpage.vm?contentCache=false"/>
</route>
/web/vm/webpage.vm內容
Hello sir $!{headers.name}! Welcome to the VM World!
#set($page="$headers.CamelHttpUrl")
#set($page="$page.substring($page.lastIndexOf('/')).substring(1)")
#parse("${page}.vm")
/web/vm/hello.vm內容
Hello World!
本地主機:8080 /測試/你好
org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'hello.vm'
at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:474)
at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:352)
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1533)
at org.apache.velocity.runtime.directive.Parse.render(Parse.java:197)
at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
at org.apache.velocity.runtime.RuntimeInstance.render(RuntimeInstance.java:1378)
at org.apache.velocity.runtime.RuntimeInstance.evaluate(RuntimeInstance.java:1314)
at org.apache.velocity.app.VelocityEngine.evaluate(VelocityEngine.java:272)
at org.apache.camel.component.velocity.VelocityEndpoint.onExchange(VelocityEndpoint.java:212)
at org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:71)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)
at org.apache.camel.component.jetty.CamelContinuationServlet.service(CamelContinuationServlet.java:191)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
at org.eclipse.jetty.servlets.MultiPartFilter.doFilter(MultiPartFilter.java:146)
at org.apache.camel.component.jetty.CamelFilterWrapper.doFilter(CamelFilterWrapper.java:43)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)
那麼,爲什麼不能將其導入hello.vm?
你在哪裏保持你的速度文件?資源? – soorapadman
@soorapadman我將速度文件保存在%KARAF_HOME%/ web/vm /下,沒有設置資源 – Tezra
在這種情況下,您不應該這樣通過。檢查此Url:http://camel.apache.org/using-propertyplaceholder.html – soorapadman