Даже если я согласен с ответом, ведьма заявляет, что JasperServer был создан для извлечения данных сам по себе, мне все равно приходилось передавать данные через остальной API, потому что это унаследованный для моей компании способ создания отчетов Jasper и потому что мы хотим использовать пользовательские сервисы Java для извлечения данных.
Я обнаружил, что описанное выше является самым простым способом сделать это.
Имея это простое пользовательское ПО, которое вы хотите передать в отчет через веб-API:
public class CustomReport {
private String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public CustomReport() {
super();
}
1) Определите пользовательский скриптлет jasper, который должен быть развернут на сервере в качестве ресурса, связанного с отчетом. Ведьма десериализует строку в пользовательский объект pojo, используя GSON:
public class CustomScriptlet
extends JRDefaultScriptlet { public void afterReportInit()
throws JRScriptletException
{
Object customSerializedObj = getParameterValue("customSerialized");
if (customSerializedObj != null)
{
String customSerializedStr = customSerializedObj.toString();
if ((customSerializedStr != null) && (customSerializedStr.length() > 0))
{
CustomReport customReport = new Gson().fromJson(customSerializedStr,
CustomReport.class);
setVariableValue("customReport", customReport);
}
}
}
2) Используйте параметр / переменную с пользовательским скриптлетом на сервере jasper:
<scriptlet name="Scriptlet_1" class="eu.dedalus.jasper.api.scriptlet.CustomScriptlet">
<scriptletDescription><![CDATA[CustomScriptlet]]></scriptletDescription>
</scriptlet>
<parameter name="customSerialized" class="java.lang.String"/>
<variable name="customReport" class="com.test.CustomReport" calculation="System"/>
3) Вызовите API @ jasperserver / rest_v2 / reportExecutions следующим образом:
"reportUnitUri" : "/report/Custom_report",
"async":"false",
"outputFormat":"pdf",
"parameters" : {
"reportParameter" : [
{
"name": "customReport",
"value": ["{ \"content\" : \"test content\" } "]
}
]
}