Comments (29)
Hello frandevel,
Can you please describe how you try to embed a report into your application? Do you use the client to retrieve the report and attachments from JRS into your application and then serve it to the browser, or are you trying to load the report from JRS by creating an iframe with src pointing to the location of report?
from jrs-rest-java-client.
We are using the API directly with a Spring Template in this case (yet to migrate it to use the API client) to get the html output from it and we saw that the images use relative paths, so we implemented a parser that replaces (JSoup based) the src attribute values preprending the fully qualified URL to the jasperserver, but unfortunately it does not work because it seems that the images are only available for the export but not anymore.
We try to embed this HTML content into a Gwt panel
@Override
public String getReportAsHtml(String pathToReport, String params) {
String url = restServicesUrl + JS_URL_REPORT;
url += pathToReport + ".html?" + params;
LOG.info("Get ReportAsHtml from {} as {}", url, username);
try {
url += authenticationServiceClient.getSuperuserCredentialsAsUrlParams();
} catch (Exception e) {
throw new IllegalStateException("Errors occurred during the authentication process", e);
}
String reportAsHtml = restTemplate.getForObject(url, String.class);
return resourceServiceClient.qualifyFull(reportAsHtml, jasperHostUrl);
}
qualifyFull is the method that parses the content to use fully qualified url's pointing to the Jasper Server.
As I write it, I realise that probably it's not a question for this project as long as I'm not using yet the library for this.
Do you think it should be possible with the library to get this resources as well as the HTML? In which format?
Thanks a lot in advance and please feel free to tell me that this should be remove from here until it's using the library
Fran
from jrs-rest-java-client.
Hello once again,
If I understand correctly, you are using rest_v2/reports service to get a report; and when serving HTML contents to the user, you prepend JRS URL to image URLs, scripts etc, correct?
First of all, it is not recommended to serve HTML output with attachment URLs pointing to your original JRS — the problem is that while the visitors of your page where report is displayed will be authenticated to your application, they won't be authenticated to JRS and therefore wouldn't be able to load the images from JRS (most probably different cookies, different credentials, different host).
The recommended scenario is that you pull all required attachments from JRS along with the report, and then serve them to users from your application — both HTML and images. It is hard to implement when using /rest_v2/reports service, but is much easier using /rest_v2/reportExecutions. Please take a look at client documentation section on reports, or if you don't want to use this java client, refer to JRS Web Services guide to find out how to implement it yourself (hint: better use the client ;))
Also FYI, you don't have to implement URL rewriting in your application — there's a parameter attachmentPrefix
that you can utilize, and you'll get HTML from the server with already rewritten URLs.
Feel free to ask if you have any more questions,
With best regards,
Paul
from jrs-rest-java-client.
Wow, thanks a lot for the answer. I was really looking forward to get an answer like yours.
I WANT to use the library, so I'll give it a try with the reportExecutions service and let's see.
Thanks a lot for your help.
Best regards,
Fran
from jrs-rest-java-client.
Already working on using the client.
As feedback I would suggest that method "setPages" on ReportExecutionRequest class could be better documented. In which format do you need to specify the pages? It would also be nice to overload the method to accept have varargs as integer or strings and internally set it up to be compliant with what is expected. Or a list of Integer.
What should I use? "1,2,3,6"? "1-6"? "1 2 4 5 6"
Probably I'm missing something.
Thanks
from jrs-rest-java-client.
Hi Fran,
That's really not very good API. So I'm already working on small enhancements and when it will be ready I'll inform you and provide you with some examples.
For now, for setPages
method you should use "1-6"
from jrs-rest-java-client.
Ugh... To be very honest, I haven't looked into the client myself yet (we have been using another client internally before this one was created). From what I remember, pages
can be either a single page setPages("3")
or a range of pages like setPages("1-4")
, but only like that. Specifying comma-separated pages and ranges is currently unsupported.
I completely understand your frustration with the documentation. As far as I know, the primary priority was to have this client cover as much as possible (there are plans for its internal usage), implying that customers are already familiar with web services documentation. The documentation within the client will be there eventually ;)
from jrs-rest-java-client.
It would also be nice to have some wrapper class that could have the output as byte[] or InputStream as it is, but also having a list of attachments to put there all the downloaded resources, and then have some method like exportAsHtmlWithAttachments.
The list of resources should be something like ReportAttachment, with the byte[] and possibly the mime type as String, so the extension can be resolved and set in case of doing something with the resource.
What do you think?
from jrs-rest-java-client.
Thanks @Actine,
Actually I'm quite happy in overall with the client library. Just making some comments that could help to improve it a bit for the following user that gets in the same situation.
:O)
Thanks @boryskolesnykov , I just read your comment now.
from jrs-rest-java-client.
Ok. Just to keep you posted. It works. I get the HTML and also I can store locally the image resources... Now it's time for me to think about how to serve it to the user in the report I display, because this being a Gwt application probably I won't be able to just store it in the servlet context and reference it in the HTML code as a relative path. :O( Let's see, fingers crossed.
Thanks both @Actine and @boryskolesnykov for the big help.
Fran
from jrs-rest-java-client.
Fran,
I think that it's possible to add such wrapper class. The main purpose of this library was to provide convenient tools to work with reports, so it's a great idea.
Your feedback is very valuable for me, it helps to improve the client.
So when I'm done with this, I will inform you.
from jrs-rest-java-client.
@frandevel
If you don't succeed with your original plan, then you can just inline the images within the report using Data URI (not the nicest solution, but will work):
<img src="data:{media type of image};base64,{base64-encoded content}" />
from jrs-rest-java-client.
Thanks a lot again @Actine
This could be a first step solution at least to be able to deliver
from jrs-rest-java-client.
BTW @Actine ,
If you use attachmentPrefix
for getting this prefix in the HTML output, you cannot download the resources anymore because this prefix is used to compose the URL to download them.
So I guess that this property is only to use "alternative" url's (internal/external/wan/lan) pointing to the resources. Am I right @boryskolesnykov?
I could also think about this as a solution when you have also a webserver that is serving this kind of resources when they are static resources and not resources generated by the report (like chart images)
Thanks
Fran
from jrs-rest-java-client.
Fran,
attachmentPrefix
is useful only if you are firstly download attachments and then render HTML. It helps to organize directory stucture.
For example, if you specified attachmentPrefix
as ./image
, then you will have HTML like this:
...
<img src="./image/img_0_0_0"/>
...
And if your directory stucture wil be like this:
|-report
|-image
- image_0_0_0
- image_0_46_0
- index.html
you will be able to easily render your HTML
from jrs-rest-java-client.
Ok. Then I made a mistake about the order. Of course if you set the prefix before downloading the resources... It does not work.
Thanks a lot @boryskolesnykov
from jrs-rest-java-client.
I finished with small enhancements for reporting service.
Now you can build ReportExecutionRequest
in this way, each setXXX
method has Javadoc description:
ReportExecutionRequest.Builder requestBuilder = new ReportExecutionRequest.Builder();
ReportExecutionRequest request = requestBuilder
.setOutputFormat(ReportOutputFormat.HTML)
.setAttachmentsPrefix("./images/")
.setReportUnitUri("/reports/samples/AllAccounts")
.setAsync(true)
.setPages(3)
//.setPages(new PageRange(2, 5))
.build();
OperationResult<ReportExecutionDescriptor> result = session
.reportingService()
.newReportExecutionRequest(request);
And also, if you are using HTML output format you can download report with all its attachments at once:
HtmlReport htmlReport = session
.reportingService()
.reportExecutionRequest(executionDescriptor.getRequestId())
.export(htmlExport.getId())
.htmlReport(htmlExport);
from jrs-rest-java-client.
Looks a lot better @boryskolesnykov , big thanks.
Is the artifact already deployed for download? Or only in the source code?
from jrs-rest-java-client.
Artifact is already deployed.
<dependencies>
<dependency>
<groupId>com.jaspersoft</groupId>
<artifactId>jrs-rest-java-client</artifactId>
<version>5.5.0.2-ALPHA-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jaspersoft-clients-snapshots</id>
<name>Jaspersoft clients snapshots</name>
<url>http://jaspersoft.artifactoryonline.com/jaspersoft/jaspersoft-clients-snapshots</url>
</repository>
</repositories>
from jrs-rest-java-client.
@frandevel @boryskolesnykov
With regard to attachmentPrefix
— if you are using Report Executions service, you don't have to worry that URLs in HTML get rewritten before you have a chance to download attachments. The service specifically allows to download attachments by HTTP GET call to
{schema}://{host}:{port}/{contextPath}/rest_v2/reportExecutions/{executionId}/exports/{exportId}/attachments/{attachmentName}
, with all ID's and attachment name available from metadata. Again, I don't know yet how that is implemented in the client — I just know how the service itself works.
P.S. In fact, if you don't specify attachmentPrefix
, the exported report will load attachments in the very same way (img src's will point to the aforementioned endpoint).
See Web Services guide section for info
Also with regard to exporting multiple pages/ranges, e.g. "1, 2, 5-7" — while it's not possible to do this in one call, you can get these as separate export executions (not to be confused with report executions) — read this section for info.
(gosh I really need to familiarize with the client already. I was working with these API's a lot with internal client and PHP client, but not with this new Java client yet...)
from jrs-rest-java-client.
What a nice help I get from you guys... Big big thanks.
Fortunately @boryskolesnykov is working hard on it and you have features available quite fast ;O)
from jrs-rest-java-client.
From:
HtmlReport htmlReport = session
.reportingService()
.reportExecutionRequest(executionDescriptor.getRequestId())
.export(htmlExport.getId())
.htmlReport(htmlExport);
I don't find getId
available in the htmlReport
... Can it be a mistake? you're using the same object you pretend to create with the call.
Probably you're refering to the exportDescriptor instead.
Thanks in advance,
Fran
from jrs-rest-java-client.
Hi again @boryskolesnykov , when using your last change like this:
@Override
public HtmlReport getHtmlReport(String path, Map<String, String> params) {
Session session = openAdminSession();
ReportExecutionRequest executionRequest = buildReportExecutionRequest(path, ReportOutputFormat.HTML);
ReportExecutionDescriptor executionDescriptor = buildReportExecutionDescriptor(executionRequest, session);
ExportDescriptor exportDescriptor = buildExportDescriptor(executionDescriptor);
HtmlReport report = session
.reportingService()
.reportExecutionRequest(executionDescriptor.getRequestId())
.export(exportDescriptor.getId())
.htmlReport(exportDescriptor);
return report;
}
I get a:
com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.JSClientException: Output format is not 'HTML'
Around:
HtmlReport report = session
.reportingService()
.reportExecutionRequest(executionDescriptor.getRequestId())
.export(exportDescriptor.getId())
.htmlReport(exportDescriptor);
The same path has been tested successfully with the previous approach to export a report (without this new HtmlReport
class)
from jrs-rest-java-client.
Fran,
That's my fault. I didn't test it thoroughly, that's why you are getting this error. Try to update your SNAPSHOT, it should work now.
Regarding your question about HtmlReport.getId()
. It's again my fault :), I'll add this method ASAP.
from jrs-rest-java-client.
No problem @boryskolesnykov ! Glad to help
from jrs-rest-java-client.
Hi @boryskolesnykov ,
Should the methods be in the latest 5.5.0.02-ALPHA snapshot? I'm not getting them.
Any idea?
Thanks
from jrs-rest-java-client.
Fran,
If you you are using Maven, try to delete artifact from your local repository ang then get it again.
I suppose it will solve the problem.
from jrs-rest-java-client.
I did it, but I don't get the latest changes. Could it be that it has not been deployed to the artifact server?
In my POM I have:
<dependency>
<groupId>com.jaspersoft</groupId>
<artifactId>jrs-rest-java-client</artifactId>
<version>[5.5.0.2-ALPHA-SNAPSHOT,]</version>
</dependency>
from jrs-rest-java-client.
Artifact has been already deployed. It's strange that it doen's work.
Try to remove square brackets around the version
<version>5.5.0.2-ALPHA-SNAPSHOT</version>
from jrs-rest-java-client.
Related Issues (20)
- There is no JSESSIONID in the content of HTTP response after a bad request. HOT 2
- IllegalParameterValueException happens when there is a comma in the uri for Resources Service. HOT 1
- When getting data, in what situation will Bad Request occur ? HOT 1
- String index out of range: -14 HOT 1
- 400 Bad Request Create ClientSemanticLayerDataSource Domain HOT 1
- Unable to find contextual data of type: javax.ws.rs.ext.Providers at Autentication HOT 2
- Support for REST API dependsOn search parameter. HOT 1
- Build failure HOT 1
- TEXT Export for jrs-rest-java-client is not available HOT 1
- Support for this project? HOT 3
- Support to Jasper 7.1
- Support for jersey 2.27 HOT 2
- Read time out issue with JRS 7.1 server HOT 4
- Problem in exports object after reportExecution
- java.lang.NoClassDefFoundError: com/jaspersoft/jasperserver/jaxrs/client/providers/CustomRepresentationTypeProvider
- 生产自定义写的 jrxml ,出现bad request 问题
- Can't install maven dependency HOT 2
- still using log4j 1.2.17 HOT 1
- Missing Documentation For Uploading File Resources
- not compatible with spring boot 2.0.x and above
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jrs-rest-java-client.