Print JasperReports client-side? - reporting

I have developed a web application that uses JasperReports. I noticed that the reports are printing server-side.
How do you make the reports print client-side (from the web browser)?
Any insights will be helpful.

Presuming you have a Servlets-based architecture:
Get a handle on the HttpServletResponse instance with HttpServletResponse response = this.getThreadLocalResponse(); (for instance).
Set the various headers to indicate a file attachment.
HttpServletResponse response = getServletResponse();
response.setHeader( "Content-Description", "File Transfer" );
response.setHeader( "Content-Disposition", "attachment; filename=" +
"report.pdf" );
response.setHeader( "Content-Type", "application/pdf" );
response.setHeader( "Content-Transfer-Encoding", "binary" );
Configure the JRExporter (jre) to use the HttpServletRespone's output stream:
jre.setParameter( JRExporterParameter.OUTPUT_STREAM, getOutputStream() );
Execute the report.
The browser will prompt the user to save the report as a PDF file. The user can print the PDF.

Related

How to fetch Request headers of a GET request from vbscript file

HI All I am new in handling http requests and am using UFT and vbscript to achieve the below requirement..I am able to send a GET request in Postman and it has a pre-request script which contains below,
pm.environment.set("hmacCreationTime", new Date().getTime());
and on sending the Get request everytime we get a unique Auth token. Here the value from the pre-request script is passed as a request header.When i try to send get request from UFT(VB script) the request throws "400 bad status" but is working fine in postman with the request headers as below
so i hardcoded the header("timestamp") using setRequestHeader method in my uft script and now i am able to generate the auth token.Please find below code
strWebServiceURL = "https://demo.com/customer/account/v1/auth/getauthtoken"
Set oWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
oWinHttp.SetTimeouts 0, 360000, 360000, 360000
'Open a HTTP connection to a HTTP resource
oWinHttp.Open "GET", strWebServiceURL, False
'owin
oWinHttp.SetRequestHeader "timestamp","1629371122124"
oWinHttp.SetRequestHeader "clientId","clientId"
oWinHttp.SetRequestHeader "User-Agent","neoload"
'oWinHttp.
'Send a HTTP request to the HTTP server with the header and body info
oWinHttp.Send
oWinHttp.WaitForResponse
'Get response
getRestRequest = oWinHttp.ResponseText
Set oWinHttp = Nothing
So i guess the timestamp value from the request Headers are required for the GET request to run successfully and is dynamically fetched from the pre-request script.is there a way to fetch the Request header values from the script ,also i tried getAllresponseheaders(but the timestamp header is not fetched )from UFT script or is there any workaround to achieve this or a way to create the timestamp value in vbscript? Any help to this would be really helpful.Thanks in advance
The following worked fine and can be included in library functions (let me know how it goes for you):
strURLUNPW = "YourWServicesURL,WSUN,WSPW"
msgbox (WebService_GET("YourWServicesURL,WSUN,WSPW")
Public Function WebService_GET(strURLUNPW)
arrURLUNPW = Split(strURLUNPW,",")
strPW = arrURLUNPW(2)
strUN = arrURLUNPW(1)
strURL = arrURLUNPW(0)
WebService_GET = ""
Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttpMain.open "GET",strURL,False,strUN,strPW
objXmlHttpMain.setRequestHeader "Accept", "*/*"
objXmlHttpMain.send strJSONToSend
WebService_GET = objXmlHttpMain.responseText
End Function

Capture raw axios request from AWS Lambda

I have code that calls a vendor API to do a formdata upload of a file by axios from inside an AWS Lambda. The call returns a 400 error. If I run the code locally using the same node version v14 it works. I want to capture both raw requests and compare them for differences. How do I capture both raw requests? I've tried using ngrok and pipedream but they don't show the raw but decode the request and the file.
let response = null;
try {
const newFile = fs.createReadStream(doc);
const formData = new FormData();
formData.append("file", newFile);
formData.append("url", url);
const headers = {
Authorization: "Bearer " + token,
...formData.getHeaders(),
};
console.log("Headers: ", headers);
response = await axios.post(`${APIBASE}/file/FileUpload`, formData, {
headers,
});
console.log("file upload response", response);
} catch (err) {
console.log("fileupload error at API", err);
}
You might be able to just use a custom request interceptor and interrogate at the requests that way.
https://axios-http.com/docs/interceptors
You're not able to capture the request on the network level, as this is totally controlled by AWS. Maybe there's a way to do this when running in a VPC, but I don't think so.
You could simply use a tool such as axios debug logger to print out all of the request and response contents (including headers etc) before the request is made/after the response has arrived. This might provide some more information as to where things are going wrong.
As to the cause of the problem, it is difficult to help you there since you haven't shared the error message nor do we know anything about the API you're trying to call.
There are multiple ways to debug
axios debug logger .
AWS cloud watch where you can see all the logs. you can capture the request
and response.
Use postman to call the prod lambda endpoint and verify the response.

spring boot - generating large csv file drops Content-Type and Content-Disposition headers

Controller action generates CSV content and returns it with header Content-Disposition: attachment; filename=file.csv
#GetMapping("/csv")
public void csvEmissions(HttpServletResponse response) {
try {
ColumnPositionMappingStrategy<CsvRow> mapStrategy
= new ColumnPositionMappingStrategy<>();
mapStrategy.setType(CsvRow.class);
String[] columns = new String[]{
"col1",
"col2"
};
mapStrategy.setColumnMapping(columns);
CSVWriter csvWriter = new CSVWriter(response.getWriter());
StatefulBeanToCsv<CsvRow> btcsv = new StatefulBeanToCsvBuilder<CsvRow>(response.getWriter())
.withMappingStrategy(mapStrategy)
.withSeparator(',')
.build();
btcsv.write(csvrows());
response.setContentType("text/csv");
response.setHeader("Content-Disposition", "attachment; filename=file.csv");
csvWriter.close();
} catch (IOException | CsvRequiredFieldEmptyException | CsvDataTypeMismatchException e) {
throw new RuntimeException(e.getMessage());
}
}
all works fine when there is not much CsvRow returned by csvrows() method. File is properly downloaded by the browser.
When rows count is larger (let's say over 200) it drops Content-Type and Content-Disposition header and browser prints CSV output as a text in the browser.
Only Transfer-Encoding: chunked header is present in the response.
Any suggestions how to make it downloadable for large amount of data?
Header Content-Length is missing from your response that's why large content is being fetched into chunks and browser displays into tab.
To get the content length try saving csv data into temporary file before putting it to response.
Also set the headers before writing data to response writer.
File file = createTempCSVFile();
response.setContentType("text/csv");
response.setContentLength((int)file.length());
response.setHeader("Content-Disposition", "attachment; filename=file.csv");
// write file data to response.getWriter();
Hope this helps!

Delete data from D365 in Batch Request, getting the error 'Content-Type' Header is missing

I am trying to create an Azure function to delete some data from a Dynamics 365 CE instance. The plan is to use the D365 WebAPI and the Batch Operations request to establish this.
Currently encountering an issue while sending a request after creating the batch request.
I have been referring to this documentation from Microsoft:
https://learn.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/execute-batch-operations-using-web-api
The code looks like:
var batchId = Guid.NewGuid().ToString();
log.LogInformation($"Batch Request Id = {batchId}.");
HttpRequestMessage deleteBatchRequestMessage = new HttpRequestMessage(HttpMethod.Post, "$batch");
deleteBatchRequestMessage.Content = new MultipartContent("mixed", "batch_" + batchId);
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(d365Url);
// Default Request Headers needed to be added in the HttpClient Object
client.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
client.DefaultRequestHeaders.Add("OData-Version", "4.0");
client.DefaultRequestHeaders.Add("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
d365HttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// Set the Authorization header with the Access Token received specifying the Credentials
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", d365Token);
HttpResponseMessage response = await client.SendAsync(deleteBatchRequestMessage);
var ass = await response.Content.ReadAsStringAsync();
But I keep getting the exception:
The 'Content-Type' header is missing. The 'Content-Type' header must be specified for each MIME part of a batch message.","ExceptionMessage":"The 'Content-Type' header is missing. The 'Content-Type' header must be specified for each MIME part of a batch message."
Is there any reason why you use WebApi? You can use the SDK and the IOrganizationService handle Everything. This will make your life very easy
http://www.threadpunter.com/azure/using-azure-functions-to-call-dynamics-365/

How can I output the response from one VBS file to a text file or a UIPath variable?

I have written some simple VBScript code to use a GET REST HTTP request. It is as follows:
endpoint="somethingsomething"
parameter ="?someparameters&sysparm_limit=10000"
Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP.6.0")
URL = endpoint & resource & parameter
On Error Resume Next
objXmlHttpMain.open "GET",URL, False, "admin", "jhdsjkF"
objXmlHttpMain.setRequestHeader "Content-Type", "application/xml"
objXmlHttpMain.setRequestHeader "Accept", "application/xml"
objXmlHttpMain.setRequestHeader "UserID", "admin"
objXmlHttpMain.setRequestHeader "Password", "jhdsjkF"
objXmlHttpMain.send
response = objXmlHttpMain.responsetext
Ideally, I want to store this response in a UIPath string variable to use it further in the sequence. Is there a way to do that?
However, if there isn't could you assist me in putting this response in a text file? I want the text file to be the same no matter how many times the VBScript is executed, and for the response to be written after the file gets cleared.
I'm not sure why ...
uipath = response
or
uipath = objXmlHttpMain.responsetext

Resources