- Main Page
- Data Structures
- Files

- File List
- Globals

# samples/jsget.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
    00031 #include <jasperserver.h>
    00032
    00033 const char server[] = "http://127.0.0.1:8080/jasperserver/services/repository";
    00034
    00041 void get_resource(char *resource, char *outfile)
    00042 {
    00043       jasperserver_request_t *request = NULL;
    00044       jasperserver_server_t *jasperServer = NULL;
    00045       jasperserver_resource_descriptor_t *res = NULL;
    00046       jasperserver_operation_result_t *operationResult = NULL;
    00047
    00048       // Create a new structure of type jasperserver_server_t to save the
    00049       // server url and credentials.
    00050       jasperServer = jasperserver_server_new();
    00051       jasperserver_string_cset(jasperServer->url, server);
    00052       jasperserver_string_cset(jasperServer->username, "tomcat");
    00053       jasperserver_string_cset(jasperServer->password, "tomcat");
    00054
    00055       // Create a new structure of type jasperserver_request_t to store
    00056       // the request information like the resource to list
    00057       request = jasperserver_request_new();
    00058
    00059       //Creating and populating a new resource_descriptor...
    00060       res = jasperserver_resource_descriptor_new();
    00061       request->resource = res;
    00062       jasperserver_string_cset(res->uriString, resource);
    00063
    00064       // Call the web service
    00065       operationResult = jasperserver_ws_get(jasperServer, request, outfile);
    00066
    00067       if (operationResult->returnCode == 0)
    00068       {
    00069          printf("Server version: %s, Return code: '%d', Return message '%s'\n", JS_CSTR( operationResult->version),  operationResult->returnCode, JS_CSTR( operationResult->returnMessage ));
    00070          printf("Requested resource: %s\n\n", JS_CSTR( request->resource->uriString));
    00071          fflush( stdout );
    00072
    00073          if (operationResult->resources)
    00074          {
    00075             jasperserver_print_resource_descriptor( operationResult->resources, 0 );
    00076          }
    00077       }
    00078       else
    00079       {
    00080           //printf("Error executing the service: %d (%s)", operationResult->returnCode, JS_UTFSTR(operationResult->returnMessage) );
    00081           printf("Error executing the service: %d (%s)", operationResult->returnCode, JS_UTFSTR(operationResult->returnMessage) );
    00082       }
    00083
    00084       jasperserver_server_free( jasperServer );
    00085       jasperserver_request_free( request );
    00086       jasperserver_operation_result_free( operationResult );
    00087
    00088 }
    00089
    00090
    00091 int main(int argc, char **argv)
    00092 {
    00093    char *resource = NULL;
    00094    char *outfile = NULL;
    00095    printf("JasperServer list sample (C) 2007 JasperSoft Corp.!\n");
    00096
    00097    if (argc > 1)
    00098    {
    00099      resource = argv[1];
    00100      if (argc > 2)
    00101      {
    00102           outfile = argv[2];
    00103      }
    00104    }
    00105    else
    00106    {
    00107      printf("Usage: jsget <resource uri> [output file name]\n");
    00108      printf("I.e.  jsget /images/JRLogo myimage.gif\n");
    00109      exit(0);
    00110    }
    00111    get_resource(resource, outfile);
    00112
    00113   return 0;
    00114 }