Changeset 383
- Timestamp:
- Jan 8, 2013, 3:54:57 PM (12 years ago)
- Location:
- trunk/zoo-project
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/HISTORY.txt
r380 r383 12 12 * Add a [headers] section in main.cfg file to add specifics to header returned 13 13 * 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 14 18 15 19 Version 1.2.0-rc3 -
trunk/zoo-project/zoo-api/js/ZOO-api.js
r377 r383 6159 6159 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>'); 6160 6160 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); 6162 6166 return response; 6163 6167 }, … … 6249 6253 */ 6250 6254 '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>'); 6252 6257 if (data.type) 6253 6258 input.*::Data.*::LiteralData.@dataType = data.type; … … 6256 6261 input = input.toXMLString(); 6257 6262 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 6258 6276 } 6259 6277 }, … … 6272 6290 for (var attr in inputs) { 6273 6291 data = inputs[attr]; 6274 if (data.mimetype || data.type == 'complex')6292 if (data && (data.mimetype || data.type == 'complex')) 6275 6293 builder = this.buildInput['complex']; 6276 else if (data.type == 'reference' || data.type == 'url')6294 else if (data && (data.type == 'reference' || data.type == 'url')) 6277 6295 builder = this.buildInput['reference']; 6278 6296 else -
trunk/zoo-project/zoo-kernel/service_internal.c
r379 r383 1745 1745 xmlNodePtr n; 1746 1746 1747 printHeaders(m); 1747 1748 doc = xmlNewDoc(BAD_CAST "1.0"); 1748 1749 maps* tmpMap=getMaps(m,"main"); … … 1899 1900 // mimeType information if present here. Maybe we can add more formats 1900 1901 // 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 1902 1903 map* mtype=getMap(tmpI->content,"mimeType"); 1903 1904 if(mtype!=NULL){ … … 1919 1920 file_name=(char*)malloc((strlen(tmp1->value)+strlen(s->name)+strlen(ext->value)+strlen(tmpI->name)+13)*sizeof(char)); 1920 1921 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"); 1922 1923 if(ofile==NULL) 1923 1924 fprintf(stderr,"Unable to create file on disk implying segfault ! \n"); … … 2000 2001 return; 2001 2002 } 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 2002 2010 char mime[1024]; 2003 2011 map* mi=getMap(tmpI->content,"mimeType"); … … 2020 2028 sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 2021 2029 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) 2024 2031 fwrite(toto->value,atoi(rs->value),1,stdout); 2025 }2026 2032 else 2027 printf("%s",toto->value);2033 fwrite(toto->value,strlen(toto->value),1,stdout); 2028 2034 #ifdef DEBUG 2029 2035 dumpMap(toto); -
trunk/zoo-project/zoo-kernel/service_internal_js.c
r377 r383 25 25 #include "service_internal.h" 26 26 27 #ifndef JSCLASS_GLOBAL_FLAGS 28 #define JSCLSAS_GLOBAL_FLAGS 0 29 #endif 30 27 31 static char dbg[1024]; 28 32 … … 81 85 82 86 /* The class of the global object. */ 83 JSClass global_class 87 JSClass global_class= { 84 88 "global", JSCLASS_GLOBAL_FLAGS, 85 89 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, … … 99 103 100 104 /* Create a context. */ 101 cx = JS_NewContext(rt,8192 );105 cx = JS_NewContext(rt,81920); 102 106 if (cx == NULL){ 103 107 return 1; 104 108 } 105 JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT );//| JSOPTION_METHODJIT);109 JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT); 106 110 JS_SetVersion(cx, JSVERSION_LATEST); 107 111 JS_SetErrorReporter(cx, reportError); … … 111 115 global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL); 112 116 //#else 113 //global = JS_NewObject(cx, &global_class, NULL,NULL);117 //global = JS_NewObject(cx, &global_class, 0,0); 114 118 //#endif 115 119 … … 150 154 * Load the first part of the ZOO-API 151 155 */ 152 char *api0=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+1 6);156 char *api0=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+17); 153 157 sprintf(api0,"%s/%s/ZOO-proj4js.js",ntmp,tmpm1->value); 154 158 #ifdef JS_DEBUG … … 158 162 fflush(stderr); 159 163 160 char *api1=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+1 1);164 char *api1=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+13); 161 165 sprintf(api1,"%s/%s/ZOO-api.js",ntmp,tmpm1->value); 162 166 #ifdef JS_DEBUG … … 200 204 exit(-1); 201 205 } 206 202 207 /* Call a function in obj's scope. */ 203 208 jsval argv[3]; … … 264 269 fprintf(stderr," * %d * \n",res); 265 270 #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 273 289 } 274 290 else{ 275 291 #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 */ 278 297 jsval tmp1; 279 298 JSBool hasResult=JS_GetProperty(cx,d,"result",&tmp1); … … 283 302 fprintf(stderr," * %d * \n",res); 284 303 #endif 304 /** 305 * Extract outputs when available. 306 */ 285 307 jsval tmp2; 286 308 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)) 289 317 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 296 339 #ifdef JS_DEBUG 297 340 dumpMaps(*outputs); … … 299 342 } 300 343 /* Cleanup. */ 344 JS_MaybeGC(cx); 301 345 JS_DestroyContext(cx); 302 346 JS_DestroyRuntime(rt); … … 479 523 jsuint len; 480 524 JSBool hasLen=JS_GetArrayLength(cx, tt, &len); 525 #ifdef JS_DEBUG 481 526 if(hasLen==JS_FALSE){ 482 #ifdef JS_DEBUG483 527 fprintf(stderr,"outputs array is empty\n"); 484 #endif 485 } 486 #ifdef JS_DEBUG 528 } 487 529 fprintf(stderr,"outputs array length : %d\n",len); 488 530 #endif … … 694 736 tmp1=JSValToChar(cx,&tmp); 695 737 #ifdef ULINET_DEBUG 738 curl_easy_setopt(handle.handle,CURLOPT_VERBOSE,1); 696 739 fprintf(stderr,"Element of array n° %d, value : %s\n",i,tmp1); 697 740 #endif -
trunk/zoo-project/zoo-kernel/service_internal_js.h
r377 r383 27 27 28 28 #pragma once 29 29 #ifdef WIN32 30 #include <wchar.h> 31 #endif 30 32 #include "service.h" 31 33 #include "service_internal.h"
Note: See TracChangeset
for help on using the changeset viewer.