Jump to content
Changes to the Jaspersoft community edition download ×

C# reportExecutions code


Recommended Posts

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);                        }                    }                }            }        }    }[/code]


Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...