As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
res.getWriter().write("les données");
Bonjour,Je suis en trains de voir comment fonctionne les Java-backed Web Scripts et j'ai une petite question:Comment peut-on renvoyer des données au client (web en général) autrement que via: res.getWriter().write("les données"); est-il possible d'utiliser une JSP ou quelque chose d'autre pour la présentation (style comme en FTL/javascript)?
Je passe via le java pour une question de performance…
Map<String, Object> model = new HashMap<String, Object>(); model.put("Var", "Hello World"); return model;
${model.Var}
${Var}
Wrapped Exception (with status template): Error during processing of the template 'Expression Var is undefined on line 7, column 21 in org/alfresco/audit/simple.get.html.ftl.'.
Exception: freemarker.core.InvalidReferenceException - Expression Var is undefined on line 6, column 19 in org/alfresco/audit/simple.get.html.ftl. freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124) freemarker.core.Expression.getStringValue(Expression.java:118) freemarker.core.Expression.getStringValue(Expression.java:93) freemarker.core.DollarVariable.accept(DollarVariable.java:76) freemarker.core.Environment.visit(Environment.java:208) freemarker.core.MixedContent.accept(MixedContent.java:92) freemarker.core.Environment.visit(Environment.java:208) freemarker.core.Environment.process(Environment.java:188) freemarker.template.Template.process(Template.java:237) org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:201) org.alfresco.web.scripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:505) org.alfresco.web.scripts.DeclarativeWebScript.renderFormatTemplate(DeclarativeWebScript.java:241) org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:147) org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:319) org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:320) org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:227) org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:368) org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:390) org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:273) org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:261) org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:139) org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:116) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) java.lang.Thread.run(Thread.java:619)
je dirais que peut-être le bean n'est pas correctement déclaré côté Spring
je dirais que peut-être le bean n'est pas correctement déclaré côté SpringEn fait j'ai repris l'exemple du wiki et quand je créé mon WebScript avec AbstractWebScript, il fonctionne bien.Mais je n'arrive pas à le faire fonctionner avec DeclarativeWebscript, pourtant:- j'etends bien la classe : org.alfresco.web.scripts.DeclarativeWebScript- j'ai overridé la méthode protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)- et j'ai construis son modèle dans une Map ( Clef Valeur/objet)En ce qui concerne l'intégration spring dans un fichier XML du bean et la description/intégration XML du web-script, je fais la même chose que l'exemple du wiki.
<bean id="webscript.org.alfresco.audit.simple.get" class="package.et.nom.de.la.ClasseDuWebScript" parent="webscript"> </bean>
L'intégration spring dans un fichier XML du bean est bien la même que j'etende la classe AbstractWebScript ou la classe DeclarativeWebscript ?
En ce qui concerne le fichier template, je l'ai nommé : nomWS.get.html.ftl et je l'ai placé au même endroit que la description du WS (nomWS.get.desc.xml), c'est bien ce qu'il faut faire?Y-a-t-il qqch à préciser quelque part pour indiquer qu'il faut utiliser mon fichier ftl (dans la classe java ou dans la déclaration du WS) ou cela se fait implicitement vu le nom du template?
package org.alfresco.module.auditscript; import java.util.HashMap; import java.util.Map; import org.alfresco.web.scripts.DeclarativeWebScript; import org.alfresco.web.scripts.WebScriptException; import org.alfresco.web.scripts.WebScriptRequest; import org.alfresco.web.scripts.Status; public class SimpleWebScript extends DeclarativeWebScript { @Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) { try { Map<String, Object> model = new HashMap<String, Object>(); model.put("Var", "Hello World"); return model; } catch(Exception e) { throw new WebScriptException("Erreur"); } } }
<bean id="webscript.org.alfresco.audit.simple.get" class="org.alfresco.module.auditscript.SimpleWebScript" parent="webscript"> </bean>
En ce qui concerne le fichier template, je l'ai nommé : nomWS.get.html.ftl et je l'ai placé au même endroit que la description du WS (nomWS.get.desc.xml), c'est bien ce qu'il faut faire?
<bean id="webscript.org.alfresco.audit.simple.get" class="org.alfresco.module.auditscript.SimpleWebScript" parent="webscript"></bean>
<bean id="webscript.be.etnic.alfresco.webscript.selector.get" class="be.etnic.alfresco.webscript.Selector" parent="webscript">
selector.get.html.ftl
selector.get.desc.xml
Perso, j'aime pas trop ceci:En ce qui concerne le fichier template, je l'ai nommé : nomWS.get.html.ftl et je l'ai placé au même endroit que la description du WS (nomWS.get.desc.xml), c'est bien ce qu'il faut faire?et surtout:<bean id="webscript.org.alfresco.audit.simple.get" class="org.alfresco.module.auditscript.SimpleWebScript" parent="webscript"></bean>J'ai toujours utilisé les même noms…
The naming convention of the Spring bean declaration is important.The prefix “webscript” is picked up by the Web Script engine. In this way, it knows that the bean you are declaring is a web script implementation.The ending “get” is picked up by the Web Script engine. It tells the Web Script engine which HTTP method to handle. In this case, an HTTP GET.The rest is then assumed to be the package and name of the Web Script.
<webscript> <shortname>The Simplest AUDIT Webscript</shortname> <description>WS de test</description> <url>/audit/simple</url> <authentication>admin</authentication> <format default="">argument</format> </webscript>
<html> <head> </head> <body> ${Var} </body> </html>
Mes noms de fichiers sont les suivants : simple.get.desc.xml et simple.get.html.ftl donc je ne pense pas que l'erreur soit ici.
Par contre mes fichiers se trouve dans : %TOMCAT%\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\org\alfresco\audit
J'utilise un AMP pour déployer mon WebScript et je ne sais pas si les différents fichiers sont mis au bon endroit.
Exception: org.alfresco.web.scripts.WebScriptException - Web Script format '' is not registered
<format default="">argument</format>
<webscript> <shortname>POST compas bean</shortname> <description>Permet de creer une demande</description> <url>/ui/compas/bean/compas</url> <authentication>guest</authentication> <transaction>requiresnew</transaction> </webscript>
<html> <body> ${mess} </body> </html>
public class Compas extends DeclarativeWebScript { private ServiceRegistry serviceRegistry; @Override protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptStatus status) { Map<String, Object> model = new HashMap<String, Object>(); model.put("mess", "Traitement java Compas…"); return model; } public void setServiceRegistry(ServiceRegistry serviceRegistry) { this.serviceRegistry =serviceRegistry; } }
Je suis sur que ma déclaration spring est correcte puisque je rentre dans le code de la fonction "setRenodocServiceRegistry".
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'> <beans> <!– Add aspect custom action –> <bean id="webscript.alfresco.extension.templates.webscripts.compas.bean.compas.post" class="fr.service.Compas" parent="webscript"> <property name="serviceRegistry"> <ref bean="ServiceRegistry" /> </property> </bean> </beans>
Pour résumer le webscript se trouve dans le répertoire alfresco/extension/templates/webscripts/compas/bean
<bean id="webscript.compas.bean.compas.post" class="fr.service.Compas" parent="webscript"> … </bean>