Не удалось заставить шаблон freemarker работать в рестлете, используемый протокол не объявлен в коннекторах клиента - PullRequest
0 голосов
/ 07 января 2012

Я пытаюсь передать местоположение моего шаблона ftl.

В приложении MyApplication extension

Я пытался ....

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 Ответ

3 голосов
/ 10 января 2012

Я помню, что тоже боролся с этим здесь .

Наконец, решение состоит в том, чтобы объявить клиентский протокол в параметрах сервлета для приложения:

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

см. Также Javadoc

...