- Main Page
- Data Structures
- Files

- File List
- Globals

# samples/jsrun.c

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (C) 2007 JasperSoft http://www.jaspersoft.com
    00003  *
    00004  * This program is free software; you can redistribute it and/or modify
    00005  * it under the terms of the GNU General Public License as published by
    00006  * the Free Software Foundation; either version 2 of the License, or
    00007  * (at your option) any later version.
    00008  *
    00009  * This program is distributed WITHOUT ANY WARRANTY; and without the
    00010  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00011  * See the GNU General Public License for more details.
    00012  *
    00013  * You should have received a copy of the GNU General Public License
    00014  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
    00015  * or write to:
    00016  *
    00017  * Free Software Foundation, Inc.,
    00018  * 59 Temple Place - Suite 330,
    00019  * Boston, MA  USA  02111-1307
    00020  */
    00021
    00033 #include <jasperserver.h>
    00034
    00035 const char server[] = "http://127.0.0.1:8080/jasperserver/services/repository";
    00036
    00037 void run_report(char *reportUnitUri, char *outfile)
    00038 {
    00039       jasperserver_request_t *request = NULL;
    00040       jasperserver_server_t *jasperServer = NULL;
    00041       jasperserver_argument_t *argPdfExport = NULL;
    00042       jasperserver_resource_descriptor_t *res = NULL;
    00043       jasperserver_operation_result_t *operationResult = NULL;
    00044
    00045       // Create a new structure of type jasperserver_server_t to save the
    00046       // server url and credentials.
    00047       jasperServer = jasperserver_server_new();
    00048       jasperserver_string_cset(jasperServer->url, server);
    00049       jasperserver_string_cset(jasperServer->username, "tomcat");
    00050       jasperserver_string_cset(jasperServer->password, "tomcat");
    00051
    00052       // Create a new structure of type jasperserver_request_t to store
    00053       // the request information like the resource to list
    00054       request = jasperserver_request_new();
    00055
    00056       // Set PDF as export format...
    00057       argPdfExport = jasperserver_argument_new();
    00058       jasperserver_string_cset(argPdfExport->name, JS_ARG_RUN_OUTPUT_FORMAT);
    00059       jasperserver_string_cset(argPdfExport->value, JS_ARG_RUN_OUTPUT_FORMAT_HTML);
    00060
    00061       jasperserver_list_append((jasperserver_list_t **)&request->arguments, (jasperserver_list_t *)argPdfExport);
    00062
    00063       //Creating and populating a new resource_descriptor...
    00064       res = jasperserver_resource_descriptor_new();
    00065       request->resource = res;
    00066       jasperserver_string_cset(res->uriString, reportUnitUri);
    00067
    00068       // Call the web service
    00069       operationResult = jasperserver_ws_runReport(jasperServer, request, outfile);
    00070
    00071       if (operationResult->returnCode == 0)
    00072       {
    00073          printf("Server version: %s, Return code: '%d', Return message '%s'\n", JS_CSTR( operationResult->version),  operationResult->returnCode, JS_CSTR( operationResult->returnMessage ));
    00074          printf("Requested resource: %s\n\n", JS_CSTR( request->resource->uriString));
    00075          fflush( stdout );
    00076       }
    00077       else
    00078       {
    00079           printf("Error executing the service: %d (%s)", operationResult->returnCode, JS_UTFSTR(operationResult->returnMessage) );
    00080       }
    00081
    00082       jasperserver_server_free( jasperServer );
    00083       jasperserver_request_free( request );
    00084       jasperserver_operation_result_free( operationResult );
    00085
    00086 }
    00087
    00088
    00089 int main(int argc, char **argv)
    00090 {
    00091    char *reportUnitUri = NULL;
    00092    char *outfile = NULL;
    00093    printf("JasperServer list sample (C) 2007 JasperSoft Corp.!\n");
    00094
    00095    if (argc > 1)
    00096    {
    00097      reportUnitUri = argv[1];
    00098      if (argc > 2)
    00099      {
    00100           outfile = argv[2];
    00101      }
    00102    }
    00103    else
    00104    {
    00105      printf("Usage: jsrun <reportUnitUri> [output file name]\n");
    00106      printf("I.e.  jsrun /reports/samples/AllAccounts allaccounts.html\n");
    00107      exit(0);
    00108    }
    00109    run_report(reportUnitUri, outfile);
    00110
    00111   return 0;
    00112 }