无法使freemarker模板在restlet上运行,所使用的协议未在客户端连接器中声明

时间:2012-01-07 17:43:18

标签: java freemarker restlet

我正在尝试传递我的ftl模板的位置。

在MyApplication中扩展应用程序

我试过......

getConnectorService().getClientProtocols().add(Protocol.FILE);

我甚至试图摆脱这种感觉......

ConnectorService cs =new ConnectorService();
    cs.setClientProtocols(UtilMisc.toList(Protocol.FILE, Protocol.HTTP));
    setConnectorService(cs);

@Override
public Restlet createInboundRoot() {
    //I even added this in to get it to print out which had been set and they were in there!
    for(Protocol p :getConnectorService().getClientProtocols()){
        Debug.log(p.getName());
    }

    // initialize the Freemarker's configuration
    configuration = new Configuration();
    configuration
            .setTemplateLoader(new ContextTemplateLoader(
                    getContext(),
                    "file:/D:/development/myexample/deploy/myexample-integrations/webapp/myexample-base/service"));

然后我在我的HtmlRepresentationHandler中有这个......

    String templateName = "serviceInfo.ftl";
    MediaType mediaType = MediaType.APPLICATION_XHTML;
    TemplateRepresentationrep = new TemplateRepresentation(templateName, getApp().getConfiguration(), cleanServiceResultMapInstance(results), mediaType);

我总是得到同样的错误,我甚至尝试过其他协议都无济于事。

Jan 8, 2012 4:45:58 AM org.restlet.engine.component.ClientRouter getNext
 [java] WARNING: The protocol used by this request is not declared in the list of client connectors. (FILE)
 [java] WARNING: Unable to get the template serviceInfo.ftl. Error message: Template serviceInfo.ftl not found.

1 个答案:

答案 0 :(得分:3)

我记得也是这样打架here

最终解决方案是在应用程序的servlet参数中声明客户端协议:

  <servlet>
                 <init-param>
                         <param-name>or​g.restlet.clients​</param-name>
                         <param-value>HTTP HTTPS FILE</param-value>
                 </init-param>
  </servlet>

另见javadoc