C# reportExecutions code

0

JasperServer Version: 7.2.0

.NET Framework Version: 4.6.1

Trying to create a JasperServer client library to use with another .NET-based application to do reporting. I built the following C# class to handle the reportExecutions method for the JasperServer REST API. Using the same parameters in Postman (baseUrl, authorization, json request), I get the expected report execution response, so I know my server configuration and credentials are correct. However, when I try to send the same request using the HttpClient module, I get an error response back with error code: generic.error.message (real helpful info there TIBCO, NOT!). I would appreciate it if someone can take a peek at my code below and see if you can spot where my issue could be coming from. Thanks!

public class reportExecutions
    {
        static HttpClient client = new HttpClient();
 
        public static async void sendReportExecutionRequestAsync(string baseUrl, string authorization, string request)
        {
            // baseUrl = https://hostname/jasperserver/rest_v2
            // authorization = base64 encoded user:password
            // request = {"reportUnitUri":"/reports/HelloWorld","async":true,"freshData":false,"saveDataSnapshot":false,"outputFormat":"pdf","interactive":false,"ignorePagination":false,"pages":null,"parameters":null}
 
            string restMethod = "/reportExecutions";
 
            using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, baseUrl + restMethod))
            using (HttpContent requestContent = new StringContent(request, Encoding.UTF8, "application/json"))
            {
                requestMessage.Headers.Add("Authorization", authorization);
                requestMessage.Headers.Add("Accept", "application/json");
                requestMessage.Method = HttpMethod.Post;
 
                // DEBUG: See what the json content being sent looks like:
                string content = requestContent.ReadAsStringAsync().Result;
                Debug.WriteLine(content);
 
                using (HttpResponseMessage response = await client.SendAsync(requestMessage))
                {
                    using (HttpContent responseContent = response.Content)
                    {
                        var result = await responseContent.ReadAsStringAsync();
 
                        if (result != null)
                        {
                            if (result.Contains("{\"message\":"))
                            {
                                models.errorResponse er = JsonConvert.DeserializeObject<models.errorResponse>(result);
 
                                Debug.WriteLine("Error Response");
                                Debug.WriteLine("Message: " + er.message);
                                Debug.WriteLine("Error Code: " + er.errorCode);
                                Debug.WriteLine("Error UID: " + er.errorUid);
                            }
                            else
                            {
                                models.reportExecutionResponse rer = JsonConvert.DeserializeObject<models.reportExecutionResponse>(result);
 
                                Debug.WriteLine("Report Execution Result");
                                Debug.WriteLine("Report URI: " + rer.reportURI);
                                Debug.WriteLine("Request ID: " + rer.requestId);
                                Debug.WriteLine("Status: " + rer.status);
                                Debug.WriteLine("Exports");
                                foreach (models.Export e in rer.exports)
                                {
                                    Debug.WriteLine("Export ID: " + e.id);
                                    Debug.WriteLine("Status: " + e.status);
                                }
                            }
                        }
                        else
                        {
                            Debug.WriteLine("No Content, Status Code: " + response.StatusCode);
                        }
                    }
                }
            }
 
        }
    }

trboyden's picture
Joined: Feb 6 2017 - 4:03pm
Last seen: 2 weeks 1 day ago

No, nothing was output to the jasperserver.log file. Anywhere else I can/should look?

trboyden - 1 month 2 weeks ago

2 Answers:

0

With REST or any API call from a remote location, you don't want to give much information away for security purposes.

Where there any exceptions logged on the JasperReports Server side?

 

swood_1's picture
619
Joined: Nov 15 2012 - 10:47am
Last seen: 12 hours 13 min ago
0

No, nothing was output to the jasperserver.log file. Anywhere else I can/should look?

trboyden's picture
Joined: Feb 6 2017 - 4:03pm
Last seen: 2 weeks 1 day ago
Feedback
randomness