2017-03-08 32 views
0

我寫了一個呈現CSV的Alfresco Web腳本,它運行良好。Web腳本錯誤500模板被忽略

在特定的情況下,我希望Web腳本爲return an error 500 as JSON,所以我爲它編寫了一個.json.500.ftl模板。

問題:錯誤500始終顯示爲HTML(默認Web腳本錯誤模板)。
我做錯了什麼?

我的文件:

auditlog.get.desc.xml 
auditlog.get.csv.ftl 
auditlog.get.json.500.ftl 

auditlog.get.json.500.ftl只包含{"error": "abc is not correct"}

auditlog.get.desc.xml包含:

<webscript> 
    <shortname>Audit Log Web Script</shortname> 
    <description>Returns audit data for a given day</description> 
    <url>/theapp/auditlog</url> 
    <authentication>admin</authentication> 
    <format default="csv"></format> 
</webscript> 

所有這些文件都在tomcat/webapps/alfresco/WEB-INF/classes/alfresco/extension/templates/webscripts/,我已經重新啓動露天。

+0

嘗試調用這個樣子,HTTP://本地主機:8080 /戶外/服務/ 該app /審計日誌格式= JSON我加入了格式= JSON在最後? 。但它可能會影響格式的原始請求參數。 –

+0

@MuralidharanDeenathayalan:正確返回JSON。如果一切順利,我希望能夠獲得CSV,但只有在出現錯誤500的情況下才能獲得JSON ......也許Web腳本技術並不意味着要這麼做? –

+1

如果您使用的是Java支持的webscript IIRC,則可以將webscript返回格式覆蓋爲JSON。請參閱'org.springframework.extensions.webscripts.DeclarativeWebScript'和'org.springframework.extensions.webscripts.DeclarativeWebScript.renderFormatTemplate(String,Map ,Writer)'方法。 –

回答

2
<format default="csv"></format> 

上面的行會嘗試獲取與「auditlog.get.csv.500.ftl」的名字,這是不是有你的情況的模板。

它只會嘗試獲取不同的響應模板,如果您在url中傳遞不同的參數,如下所示。

http://localhost:8080/share/service/demo/webscript?format=json

+0

所以你的結論是我的需求(相同的請求返回CSV是好的,JSON是KO)不能在不調整Web腳本系統的情況下實現,對吧? –

+0

沒有得到你。 –

+0

首先,你沒有提到任何關於html模板的事情,第二是如果服務器返回500錯誤,它會呈現500.ftl,如你所定義的那樣。我想你應該閱讀標記是如何工作的在描述符中。 –