Changeset 383


Ignore:
Timestamp:
Jan 8, 2013, 3:54:57 PM (11 years ago)
Author:
djay
Message:

Fix issue in JS support and for binary RawDataOutput?. Add Content-Length and Content-Disposition (optional) to response header. Add support to JS ZOO-API for sending headers and handling multi-valued inputs.

Location:
trunk/zoo-project
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/HISTORY.txt

    r380 r383  
    1212  * Add a [headers] section in main.cfg file to add specifics to header returned
    1313  * Add support for multiple outputs for both GET and POST requests
     14  * Add Content-Length to the headers if the result is sized
     15  * Add Content-Disposition to the headers if the result contains a filename
     16  * Add support for sending headers through JS ZOO-api
     17  * Add support for multi-valued inputs in JS ZOO-api
    1418
    1519Version 1.2.0-rc3
  • trunk/zoo-project/zoo-api/js/ZOO-api.js

    r377 r383  
    61596159    var body = new XML('<wps:Execute service="WPS" version="1.0.0" xmlns:wps="'+this.namespaces['wps']+'" xmlns:ows="'+this.namespaces['ows']+'" xmlns:xlink="'+this.namespaces['xlink']+'" xmlns:xsi="'+this.namespaces['xsi']+'" xsi:schemaLocation="'+this.schemaLocation+'"><ows:Identifier>'+this.identifier+'</ows:Identifier>'+this.buildDataInputsNode(inputs)+this.buildDataOutputsNode(outputs)+'</wps:Execute>');
    61606160    body = body.toXMLString();
    6161     var response = ZOO.Request.Post(this.url,body,['Content-Type: text/xml; charset=UTF-8']);
     6161    var headers=['Content-Type: text/xml; charset=UTF-8'];
     6162      if(arguments.length>2){
     6163        headers[headers.length]=arguments[2];
     6164      }
     6165    var response = ZOO.Request.Post(this.url,body,headers);
    61626166    return response;
    61636167  },
     
    62496253     */
    62506254    'literal': function(identifier,data) {
    6251       var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value+'</wps:LiteralData></wps:Data></wps:Input>');
     6255        if(data && !eval(data["isArray"])){
     6256            var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value+'</wps:LiteralData></wps:Data></wps:Input>');
    62526257      if (data.type)
    62536258        input.*::Data.*::LiteralData.@dataType = data.type;
     
    62566261      input = input.toXMLString();
    62576262      return input;
     6263        }else if(data){
     6264            var inputf="";
     6265            for(i=0;i<parseInt(data["length"]);i++){
     6266                var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value[i]+'</wps:LiteralData></wps:Data></wps:Input>');
     6267                if (data.type)
     6268                    input.*::Data.*::LiteralData.@dataType = data.type;
     6269                if (data.uom)
     6270                    input.*::Data.*::LiteralData.@uom = data.uom;
     6271                inputf += input.toXMLString();
     6272            }
     6273            return inputf;
     6274        }
     6275       
    62586276    }
    62596277  },
     
    62726290    for (var attr in inputs) {
    62736291      data = inputs[attr];
    6274       if (data.mimetype || data.type == 'complex')
     6292        if (data && (data.mimetype || data.type == 'complex'))
    62756293        builder = this.buildInput['complex'];
    6276       else if (data.type == 'reference' || data.type == 'url')
     6294        else if (data && (data.type == 'reference' || data.type == 'url'))
    62776295        builder = this.buildInput['reference'];
    62786296      else
  • trunk/zoo-project/zoo-kernel/service_internal.c

    r379 r383  
    17451745  xmlNodePtr n;
    17461746
     1747  printHeaders(m);
    17471748  doc = xmlNewDoc(BAD_CAST "1.0");
    17481749  maps* tmpMap=getMaps(m,"main");
     
    18991900          // mimeType information if present here. Maybe we can add more formats
    19001901          // here.
    1901           // If mimeType was not found, we then set txt as the default extension.
     1902          // If mimeType was not found, we then set txt as the default extension
    19021903          map* mtype=getMap(tmpI->content,"mimeType");
    19031904          if(mtype!=NULL){
     
    19191920        file_name=(char*)malloc((strlen(tmp1->value)+strlen(s->name)+strlen(ext->value)+strlen(tmpI->name)+13)*sizeof(char));
    19201921        sprintf(file_name,"%s/%s_%s_%i.%s",tmp1->value,s->name,tmpI->name,cpid+100000,ext->value);
    1921         FILE *ofile=fopen(file_name,"w");
     1922        FILE *ofile=fopen(file_name,"wb");
    19221923        if(ofile==NULL)
    19231924          fprintf(stderr,"Unable to create file on disk implying segfault ! \n");
     
    20002001          return;
    20012002        }
     2003        map* fname=getMapFromMaps(tmpI,tmpI->name,"filename");
     2004        if(fname!=NULL)
     2005          printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
     2006        map* rs=getMapFromMaps(tmpI,tmpI->name,"size");
     2007        if(rs!=NULL)
     2008          printf("Content-Length: %s\r\n",rs->value);
     2009
    20022010        char mime[1024];
    20032011        map* mi=getMap(tmpI->content,"mimeType");
     
    20202028            sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
    20212029        printf("%s",mime);
    2022         if(mi!=NULL && strncmp(mi->value,"image",5)==0){
    2023           map* rs=getMapFromMaps(tmpI,tmpI->name,"size");
     2030        if(rs!=NULL)
    20242031          fwrite(toto->value,atoi(rs->value),1,stdout);
    2025         }
    20262032        else
    2027           printf("%s",toto->value);
     2033          fwrite(toto->value,strlen(toto->value),1,stdout);
    20282034#ifdef DEBUG
    20292035        dumpMap(toto);
  • trunk/zoo-project/zoo-kernel/service_internal_js.c

    r377 r383  
    2525#include "service_internal.h"
    2626
     27#ifndef JSCLASS_GLOBAL_FLAGS
     28#define JSCLSAS_GLOBAL_FLAGS 0
     29#endif
     30
    2731static char dbg[1024];
    2832
     
    8185
    8286  /* The class of the global object. */
    83   JSClass global_class = {
     87  JSClass global_class= {
    8488    "global", JSCLASS_GLOBAL_FLAGS,
    8589    JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
     
    99103 
    100104  /* Create a context. */
    101   cx = JS_NewContext(rt,8192);
     105  cx = JS_NewContext(rt,81920);
    102106  if (cx == NULL){
    103107    return 1;
    104108  }
    105   JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT );//| JSOPTION_METHODJIT);
     109  JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT);
    106110  JS_SetVersion(cx, JSVERSION_LATEST);
    107111  JS_SetErrorReporter(cx, reportError);
     
    111115  global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL);
    112116  //#else
    113   //global = JS_NewObject(cx, &global_class, NULL,NULL);
     117  //global = JS_NewObject(cx, &global_class, 0,0);
    114118  //#endif
    115119
     
    150154   * Load the first part of the ZOO-API
    151155   */
    152   char *api0=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+16);
     156  char *api0=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+17);
    153157  sprintf(api0,"%s/%s/ZOO-proj4js.js",ntmp,tmpm1->value);
    154158#ifdef JS_DEBUG
     
    158162  fflush(stderr);
    159163
    160   char *api1=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+11);
     164  char *api1=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+13);
    161165  sprintf(api1,"%s/%s/ZOO-api.js",ntmp,tmpm1->value);
    162166#ifdef JS_DEBUG
     
    200204    exit(-1);
    201205  }
     206
    202207  /* Call a function in obj's scope. */
    203208  jsval argv[3];
     
    264269    fprintf(stderr," * %d * \n",res);
    265270#endif
    266     jsval tmp2;
    267     JSBool hasElement=JS_GetElement(cx,d,1,&tmp2);
    268     if(hasElement==JS_TRUE){
    269           freeMaps(outputs);
    270           free(*outputs);
    271       *outputs=mapsFromJSObject(cx,tmp2);
    272     }
     271    if(res==SERVICE_SUCCEEDED){
     272      jsval tmp2;
     273      JSBool hasElement=JS_GetElement(cx,d,1,&tmp2);
     274      if(hasElement==JS_TRUE){
     275        freeMaps(outputs);
     276        free(*outputs);
     277        *outputs=mapsFromJSObject(cx,tmp2);
     278      }
     279    }else{
     280      jsval tmp3;
     281      JSBool hasConf=JS_GetElement(cx,d,1,&tmp3);
     282      if(hasConf==JS_TRUE){
     283        freeMaps(main_conf);
     284        free(*main_conf);
     285        *main_conf=mapsFromJSObject(cx,tmp3);
     286      }
     287    }
     288
    273289  }
    274290  else{
    275291#ifdef JS_DEBUG
    276     fprintf(stderr,"The serice didn't return an array !\n");
    277 #endif
     292    fprintf(stderr,"The service didn't return an array !\n");
     293#endif
     294    /**
     295     * Extract result
     296     */
    278297    jsval tmp1;
    279298    JSBool hasResult=JS_GetProperty(cx,d,"result",&tmp1);
     
    283302    fprintf(stderr," * %d * \n",res);
    284303#endif
     304    /**
     305     * Extract outputs when available.
     306     */
    285307    jsval tmp2;
    286308    JSBool hasElement=JS_GetProperty(cx,d,"outputs",&tmp2);
    287 #ifdef JS_DEBUG
    288     if(!hasElement)
     309    if(!JSVAL_IS_VOID(tmp2) && hasElement==JS_TRUE){
     310      freeMaps(outputs);
     311      free(*outputs);   
     312      *outputs=mapsFromJSObject(cx,tmp2);
     313    }
     314    JS_MaybeGC(cx);
     315#ifdef JS_DEBUG
     316    if(JSVAL_IS_VOID(tmp2))
    289317      fprintf(stderr,"No outputs property returned\n");
    290     if(JS_IsArrayObject(cx,JSVAL_TO_OBJECT(tmp2)))
    291       fprintf(stderr,"outputs is array an as expected\n");
    292     else
    293       fprintf(stderr,"outputs is not an array as expected\n");
    294 #endif
    295     *outputs=mapsFromJSObject(cx,tmp2);
     318    else{
     319      if(JS_IsArrayObject(cx,JSVAL_TO_OBJECT(tmp2)))
     320        fprintf(stderr,"outputs is an array as expected\n");
     321      else
     322        fprintf(stderr,"outputs is not an array as expected\n");
     323    }
     324    JS_MaybeGC(cx);
     325#endif
     326
     327    /**
     328     * Extract conf when available.
     329     */
     330    jsval tmp3;
     331    JSBool hasConf=JS_GetProperty(cx,d,"conf",&tmp3);
     332    if(!JSVAL_IS_VOID(tmp3) && hasConf==JS_TRUE){
     333      freeMaps(main_conf);
     334      free(*main_conf);
     335      *main_conf=mapsFromJSObject(cx,tmp3);
     336    }
     337    JS_MaybeGC(cx);
     338
    296339#ifdef JS_DEBUG
    297340    dumpMaps(*outputs);
     
    299342  }
    300343  /* Cleanup. */
     344  JS_MaybeGC(cx);
    301345  JS_DestroyContext(cx);
    302346  JS_DestroyRuntime(rt);
     
    479523  jsuint len;
    480524  JSBool hasLen=JS_GetArrayLength(cx, tt, &len);
     525#ifdef JS_DEBUG
    481526  if(hasLen==JS_FALSE){
    482 #ifdef JS_DEBUG
    483527    fprintf(stderr,"outputs array is empty\n");
    484 #endif
    485   }
    486 #ifdef JS_DEBUG
     528  }
    487529  fprintf(stderr,"outputs array length : %d\n",len);
    488530#endif
     
    694736      tmp1=JSValToChar(cx,&tmp);
    695737#ifdef ULINET_DEBUG
     738      curl_easy_setopt(handle.handle,CURLOPT_VERBOSE,1);
    696739      fprintf(stderr,"Element of array n° %d, value : %s\n",i,tmp1);
    697740#endif
  • trunk/zoo-project/zoo-kernel/service_internal_js.h

    r377 r383  
    2727
    2828#pragma once
    29 
     29#ifdef WIN32
     30#include <wchar.h>
     31#endif
    3032#include "service.h"
    3133#include "service_internal.h"
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png