Index: branches/prototype-v0/zoo-project/zoo-kernel/caching.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/caching.c	(revision 887)
+++ branches/prototype-v0/zoo-project/zoo-kernel/caching.c	(revision 888)
@@ -411,4 +411,5 @@
     char *mimeType=NULL;
     int fsize=0;
+    char oriname[12];
     char cname[15];
     char vname[11];
@@ -430,4 +431,5 @@
       sprintf(cname,"cache_file_%d",i);
       tmp1=getMap(content->content,cname);
+      sprintf(oriname,"origin_%d",i);
       sprintf(vname,"value_%d",i);
       sprintf(sname,"size_%d",i);
@@ -441,4 +443,5 @@
     }else{
       sprintf(cname,"cache_file");
+      sprintf(oriname,"origin");
       sprintf(vname,"value");
       sprintf(sname,"size");
@@ -539,4 +542,6 @@
 	addToMap((*in)->content,sname,ltmp1);
 	addToMap((*in)->content,mname,mimeType);
+	char* origin=getProvenance(*m,request);
+	addToMap((*in)->content,oriname,origin);
 	if(memUse==NULL || strcasecmp(memUse->value,"load")==0){
 	  addToCache(*m,request,fcontent,mimeType,fsize, NULL, 0);
@@ -632,4 +637,5 @@
   char* cached=isInCache(*m,url);
   char *mimeType=NULL;
+  char *origin=NULL;
   int fsize=0;
   map* memUse=getMapFromMaps(*m,"main","memory");
@@ -674,4 +680,17 @@
       unlockFile(*m,lck);
     }
+    cached[strlen(cached)-1]='p';
+    s=stat(cached, &f_status);
+    if(s==0){
+      zooLock* lck=lockFile(*m,cached,'r');
+      if(lck==NULL)
+	return -1;
+      origin=(char*)malloc(sizeof(char)*(f_status.st_size+1));
+      FILE* f=fopen(cached,"rb");
+      fread(origin,f_status.st_size,1,f);
+      mimeType[f_status.st_size]=0;
+      fclose(f);
+      unlockFile(*m,lck);
+    }
   }else{    
     addRequestToQueue(m,hInternet,url,true);
@@ -683,4 +702,7 @@
   if(mimeType!=NULL){
     addToMap(*content,"fmimeType",mimeType);
+  }
+  if(origin!=NULL){
+    addToMap(*content,"origin",origin);
   }
 
Index: branches/prototype-v0/zoo-project/zoo-kernel/response_print.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/response_print.c	(revision 887)
+++ branches/prototype-v0/zoo-project/zoo-kernel/response_print.c	(revision 888)
@@ -33,4 +33,7 @@
 #include "cpl_vsi.h"
 #endif
+#ifdef USE_HPC
+#include "service_callback.h"
+#endif
 
 #ifndef TRUE
@@ -362,8 +365,8 @@
       nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
       xmlAddChild(nc4,xmlNewText(BAD_CAST buff));	      
-	if(vid==0)
-	  xmlAddChild(nc3,nc4);
-	else
-	  xmlAddChild(nc1,nc4);
+      if(vid==0)
+	xmlAddChild(nc3,nc4);
+      else
+	xmlAddChild(nc1,nc4);
     }
   }
@@ -753,78 +756,78 @@
  */
 void addMetadata(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,int vid){
-    int hasTitle=-1;
-    int hasValue=-1;
-    xmlNodePtr nc1;
-    map* oMeta=meta;
-    int isAdditionalParameters=-1;
-    int level=0;
-    map* test=getMap(meta,"title");
-    if(test!=NULL)
-      level+=1;
-    test=getMap(meta,"href");
-    if(test!=NULL)
-      level+=1;
-    test=getMap(meta,"role");
-    if(test!=NULL)
-      level+=1;
-    if(count(oMeta)>level+1)
-      isAdditionalParameters=1;
-    char *ctitle=NULL;
-    while(meta!=NULL){
-      if(hasTitle<0)
-	if(isAdditionalParameters<0)
-	  nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
-	else
-	  if(hasValue<0)
-	    nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
-      if(strncasecmp(meta->name,"title",5)==0 ||
-	 strcasecmp(meta->name,"href")==0 ||
-	 strcasecmp(meta->name,"role")==0 ){
-	int index=5;
-	if(strncasecmp(meta->name,"title",5)==0){
-	  index=6;
-	  hasTitle=1;
-	  if(ctitle!=NULL && strcasecmp(meta->value,ctitle)!=0){
-	      xmlAddChild(nc,nc1);
-	      nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
-	      free(ctitle);
-	      ctitle=NULL;
-	  }
-	  if(ctitle==NULL){
-	    char *tmp=(char*)malloc((strlen(meta->name)+1)*sizeof(char));
-	    snprintf(tmp,index,"%s",meta->name);
-	    xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp,BAD_CAST meta->value);
-	    free(tmp);
-	  }	  
-	  if(ctitle!=NULL)
-	    free(ctitle);
-	  ctitle=zStrdup(meta->value);
-	}
-      }else{
-	xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter");
-	xmlNodePtr nc3 = xmlNewNode(ns_ows, BAD_CAST "Name");
-	xmlAddChild(nc3,xmlNewText(BAD_CAST meta->name));
-	xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
-	xmlAddChild(nc4,xmlNewText(BAD_CAST meta->value));
-	xmlAddChild(nc2,nc3);
-	xmlAddChild(nc2,nc4);
-	xmlAddChild(nc1,nc2);
-	hasTitle=-1;
-      }
-      meta=meta->next;
-      if(hasTitle<0){
-	hasValue=1;
-	if(isAdditionalParameters){
-	  if(vid==0){
-	    meta=NULL;
-	    break;
-	  }else
-	    xmlAddChild(nc,nc1);
-	}
-      }
-    }
-    if(oMeta!=NULL && hasValue<0 && nc1!=NULL){
-      xmlAddChild(nc,nc1);
-    }
+  int hasTitle=-1;
+  int hasValue=-1;
+  xmlNodePtr nc1;
+  map* oMeta=meta;
+  int isAdditionalParameters=-1;
+  int level=0;
+  map* test=getMap(meta,"title");
+  if(test!=NULL)
+    level+=1;
+  test=getMap(meta,"href");
+  if(test!=NULL)
+    level+=1;
+  test=getMap(meta,"role");
+  if(test!=NULL)
+    level+=1;
+  if(count(oMeta)>level+1)
+    isAdditionalParameters=1;
+  char *ctitle=NULL;
+  while(meta!=NULL){
+    if(hasTitle<0)
+      if(isAdditionalParameters<0)
+	nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
+      else
+	if(hasValue<0)
+	  nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
+    if(strncasecmp(meta->name,"title",5)==0 ||
+       strcasecmp(meta->name,"href")==0 ||
+       strcasecmp(meta->name,"role")==0 ){
+      int index=5;
+      if(strncasecmp(meta->name,"title",5)==0){
+	index=6;
+	hasTitle=1;
+	if(ctitle!=NULL && strcasecmp(meta->value,ctitle)!=0){
+	  xmlAddChild(nc,nc1);
+	  nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
+	  free(ctitle);
+	  ctitle=NULL;
+	}
+	if(ctitle==NULL){
+	  char *tmp=(char*)malloc((strlen(meta->name)+1)*sizeof(char));
+	  snprintf(tmp,index,"%s",meta->name);
+	  xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp,BAD_CAST meta->value);
+	  free(tmp);
+	}	  
+	if(ctitle!=NULL)
+	  free(ctitle);
+	ctitle=zStrdup(meta->value);
+      }
+    }else{
+      xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter");
+      xmlNodePtr nc3 = xmlNewNode(ns_ows, BAD_CAST "Name");
+      xmlAddChild(nc3,xmlNewText(BAD_CAST meta->name));
+      xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
+      xmlAddChild(nc4,xmlNewText(BAD_CAST meta->value));
+      xmlAddChild(nc2,nc3);
+      xmlAddChild(nc2,nc4);
+      xmlAddChild(nc1,nc2);
+      hasTitle=-1;
+    }
+    meta=meta->next;
+    if(hasTitle<0){
+      hasValue=1;
+      if(isAdditionalParameters){
+	if(vid==0){
+	  meta=NULL;
+	  break;
+	}else
+	  xmlAddChild(nc,nc1);
+      }
+    }
+  }
+  if(oMeta!=NULL && hasValue<0 && nc1!=NULL){
+    xmlAddChild(nc,nc1);
+  }
 }
 
@@ -840,103 +843,103 @@
  */
 void addAdditionalParameters(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,int fromDb){
-    int hasTitle=-1;
-    int hasValue=-1;
-    int toAddAtEnd=-1;
-    int cnt=0;
-    xmlNodePtr* ncr=NULL;
-    xmlNodePtr nc1;
-    map* oMeta=meta;
-    int isAdditionalParameters=-1;
-    int level=0;
-    map* test=getMap(meta,"title");
-    map* otitle=getMap(meta,"title");
-    map* length=getMap(meta,"length");
-    int len=0;
-    char *ctitle=NULL;
+  int hasTitle=-1;
+  int hasValue=-1;
+  int toAddAtEnd=-1;
+  int cnt=0;
+  xmlNodePtr* ncr=NULL;
+  xmlNodePtr nc1;
+  map* oMeta=meta;
+  int isAdditionalParameters=-1;
+  int level=0;
+  map* test=getMap(meta,"title");
+  map* otitle=getMap(meta,"title");
+  map* length=getMap(meta,"length");
+  int len=0;
+  char *ctitle=NULL;
     
-    if(test!=NULL)
-      level+=1;
-    test=getMap(meta,"href");
-    if(test!=NULL)
-      level+=1;
-    test=getMap(meta,"role");
-    if(test!=NULL)
-      level+=1;
-    if(count(oMeta)>level+1)
-      isAdditionalParameters=1;
-
-    while(meta!=NULL){
-      if(hasTitle<0 && hasValue<0){
-	nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
-      }
-      if(strncasecmp(meta->name,"title",5)==0 ||
-	 strcasecmp(meta->name,"href")==0 ||
-	 strcasecmp(meta->name,"role")==0 ){
-	int index=5;
-	if(strncasecmp(meta->name,"title",5)==0){
-	  index=6;
-	  hasTitle=1;
-	  if(ctitle!=NULL && strcasecmp(meta->value,ctitle)!=0){
-	    xmlNodePtr ncTmp = xmlDocCopyNodeList(doc,nc1);
-	    xmlAddChild(nc,ncTmp);
-	    xmlFreeNode(nc1);
-	    toAddAtEnd=1;
-	    cnt++;
-	    nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
-	    free(ctitle);
-	    ctitle=NULL;
-	  }
-	  if(ctitle==NULL){
-	    char *tmp=(char*)malloc((strlen(meta->name)+1)*sizeof(char));
-	    snprintf(tmp,index,"%s",meta->name);
-	    xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp,BAD_CAST meta->value);
-	    free(tmp);
-	  }	  
-	  if(ctitle!=NULL)
-	    free(ctitle);
-	  ctitle=zStrdup(meta->value);
+  if(test!=NULL)
+    level+=1;
+  test=getMap(meta,"href");
+  if(test!=NULL)
+    level+=1;
+  test=getMap(meta,"role");
+  if(test!=NULL)
+    level+=1;
+  if(count(oMeta)>level+1)
+    isAdditionalParameters=1;
+
+  while(meta!=NULL){
+    if(hasTitle<0 && hasValue<0){
+      nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
+    }
+    if(strncasecmp(meta->name,"title",5)==0 ||
+       strcasecmp(meta->name,"href")==0 ||
+       strcasecmp(meta->name,"role")==0 ){
+      int index=5;
+      if(strncasecmp(meta->name,"title",5)==0){
+	index=6;
+	hasTitle=1;
+	if(ctitle!=NULL && strcasecmp(meta->value,ctitle)!=0){
+	  xmlNodePtr ncTmp = xmlDocCopyNodeList(doc,nc1);
+	  xmlAddChild(nc,ncTmp);
+	  xmlFreeNode(nc1);
+	  toAddAtEnd=1;
+	  cnt++;
+	  nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
+	  free(ctitle);
+	  ctitle=NULL;
+	}
+	if(ctitle==NULL){
+	  char *tmp=(char*)malloc((strlen(meta->name)+1)*sizeof(char));
+	  snprintf(tmp,index,"%s",meta->name);
+	  xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp,BAD_CAST meta->value);
+	  free(tmp);
+	}	  
+	if(ctitle!=NULL)
+	  free(ctitle);
+	ctitle=zStrdup(meta->value);
+      }else{
+	xmlNewNsProp(nc1,ns_xlink,BAD_CAST meta->name,BAD_CAST meta->value);
+      }
+    }else{
+      if(strncasecmp(meta->name,"length",6)!=0 && strncasecmp(meta->name,"fromDb",6)!=0){
+	xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter");
+	xmlNodePtr nc3 = xmlNewNode(ns_ows, BAD_CAST "Name");
+	xmlAddChild(nc3,xmlNewText(BAD_CAST meta->name));
+	xmlAddChild(nc2,nc3);
+	if(fromDb<0){
+	  char *mptr;
+	  char* meta_values=strtok_r(meta->value,",",&mptr);
+	  while(meta_values!=NULL){
+	    xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
+	    xmlAddChild(nc4,xmlNewText(BAD_CAST meta_values));
+	    xmlAddChild(nc2,nc4);
+	    meta_values=strtok_r(NULL,",",&mptr);
+	  }
 	}else{
-	  xmlNewNsProp(nc1,ns_xlink,BAD_CAST meta->name,BAD_CAST meta->value);
-	}
-      }else{
-	if(strncasecmp(meta->name,"length",6)!=0 && strncasecmp(meta->name,"fromDb",6)!=0){
-	  xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter");
-	  xmlNodePtr nc3 = xmlNewNode(ns_ows, BAD_CAST "Name");
-	  xmlAddChild(nc3,xmlNewText(BAD_CAST meta->name));
-	  xmlAddChild(nc2,nc3);
-	  if(fromDb<0){
-	    char *mptr;
-	    char* meta_values=strtok_r(meta->value,",",&mptr);
-	    while(meta_values!=NULL){
-	      xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
-	      xmlAddChild(nc4,xmlNewText(BAD_CAST meta_values));
-	      xmlAddChild(nc2,nc4);
-	      meta_values=strtok_r(NULL,",",&mptr);
-	    }
-	  }else{
-	    xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
-	    xmlAddChild(nc4,xmlNewCDataBlock(doc,BAD_CAST meta->value,strlen(meta->value)));
-	    xmlAddChild(nc2,nc4);
-	  }
-	  xmlAddChild(nc1,nc2);
-	}
-	hasTitle=-1;
-      }
-      meta=meta->next;
-      if(hasTitle<0){
-	//xmlAddChild(nc,nc1);
-	hasValue=1;
-      }/*else
-	if(ctitle!=NULL)
-	free(ctitle);*/
-    }
-    if(length!=NULL)
-      len=atoi(length->value);
-    if(otitle!=NULL)
-      len=1;
-    if(cnt<len){
-      xmlAddChild(nc,nc1);
-      free(ctitle);
-    }
+	  xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
+	  xmlAddChild(nc4,xmlNewCDataBlock(doc,BAD_CAST meta->value,strlen(meta->value)));
+	  xmlAddChild(nc2,nc4);
+	}
+	xmlAddChild(nc1,nc2);
+      }
+      hasTitle=-1;
+    }
+    meta=meta->next;
+    if(hasTitle<0){
+      //xmlAddChild(nc,nc1);
+      hasValue=1;
+    }/*else
+       if(ctitle!=NULL)
+       free(ctitle);*/
+  }
+  if(length!=NULL)
+    len=atoi(length->value);
+  if(otitle!=NULL)
+    len=1;
+  if(cnt<len){
+    xmlAddChild(nc,nc1);
+    free(ctitle);
+  }
 }
 
@@ -1999,7 +2002,7 @@
 	if(testResponse==NULL || tmp0==NULL){
 	  if(vid==0)
-	      printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
+	    printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
 	  else
-	      printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
+	    printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
 	}
 	else
@@ -2137,5 +2140,5 @@
   else{
     /*
-    dumpElements(e);
+      dumpElements(e);
     */
     return;
@@ -2146,5 +2149,5 @@
        || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0
        || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0)
-    xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value);
+      xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value);
     tmp=tmp->next;
   }
@@ -2352,5 +2355,5 @@
 	     strstr(tmp2->value, "json") != NULL ||            //    (will not be parsed by XML reader) 
 	     strstr(tmp2->value, "ecmascript") != NULL
-	   ) {
+	     ) {
 	    xmlAddChild((vid==0?nc3:nc2),xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value)));
 	  }   
@@ -2358,5 +2361,5 @@
 	    if (strstr(tmp2->value, "xml") != NULL ||                 // if XML-based format
 		// include for backwards compatibility,
-	      // although correct mime type is ...kml+xml:		   
+		// although correct mime type is ...kml+xml:		   
 		strstr(tmp2->value, "google-earth.kml") != NULL
 		) { 
@@ -2580,4 +2583,6 @@
 
     tmp=getMapArray(s,"text",cnt);
+    if(tmp==NULL)
+      tmp=getMapArray(s,"message",cnt);
     nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText");
     if(tmp!=NULL){
@@ -2741,4 +2746,5 @@
     map* usid=getMapFromMaps(m,"lenv","usid");
     int itn=0;
+    int error=-1;
   NESTED0:
     while(tmpI!=NULL){
@@ -2768,103 +2774,107 @@
 	  (geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0) ) ) 
 #else
-      if(toto!=NULL && strcasecmp(toto->value,"true")==0)
+	if(toto!=NULL && strcasecmp(toto->value,"true")==0)
 #endif
-	{
-	  elements* in=getElements(s->outputs,tmpI->name);
-	  if(in==NULL && s->outputs->child!=NULL){
-	    in=getElements(s->outputs->child,tmpI->name);
-	  }
-	  char *format=NULL;
-	  if(in!=NULL && in->format!=NULL){
-	    format=in->format;
-	  }else
-	    format=(char*)"LiteralData";
-	  if(format!=NULL && strcasecmp(format,"BoundingBoxData")==0){
-	    addToMap(tmpI->content,"extension","xml");
-	    addToMap(tmpI->content,"mimeType","text/xml");
-	    addToMap(tmpI->content,"encoding","UTF-8");
-	    addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd");
-	  }
-
-	  char *file_path=NULL;
-	  if(gfile==NULL) {
-	    map *ext=getMap(tmpI->content,"extension");
-	    char file_ext[32];
+	  {
+	    elements* in=getElements(s->outputs,tmpI->name);
+	    if(in==NULL && s->outputs->child!=NULL){
+	      in=getElements(s->outputs->child,tmpI->name);
+	    }
+	    char *format=NULL;
+	    if(in!=NULL && in->format!=NULL){
+	      format=in->format;
+	    }else
+	      format=(char*)"LiteralData";
+	    if(format!=NULL && strcasecmp(format,"BoundingBoxData")==0){
+	      addToMap(tmpI->content,"extension","xml");
+	      addToMap(tmpI->content,"mimeType","text/xml");
+	      addToMap(tmpI->content,"encoding","UTF-8");
+	      addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd");
+	    }
+
+	    char *file_path=NULL;
+	    if(gfile==NULL) {
+	      map *ext=getMap(tmpI->content,"extension");
+	      char file_ext[32];
 	    
-	    if( ext != NULL && ext->value != NULL) {
-	      strncpy(file_ext, ext->value, 32);
+	      if( ext != NULL && ext->value != NULL) {
+		strncpy(file_ext, ext->value, 32);
+	      }
+	      else {
+		// Obtain default file extension (see mimetypes.h).	      
+		// If the MIME type is not recognized, txt is used as the default extension
+		map* mtype=getMap(tmpI->content,"mimeType");
+		getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);
+	      }
+	      if(file_name!=NULL)
+		free(file_name);
+	      file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char));
+	      sprintf(file_name,"ZOO_DATA_%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);
+	      itn++;
+	      file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
+	      sprintf(file_path,"%s/%s",tmp1->value,file_name);
+
+	      FILE *ofile=fopen(file_path,"wb");
+	      if(ofile==NULL){
+		char tmpMsg[1024];
+		sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name);
+		errorException(m,tmpMsg,"InternalError",NULL);
+		free(file_name);
+		free(file_path);
+		return;
+	      }
+
+	      toto=getMap(tmpI->content,"value");
+	      if(toto==NULL){
+		char tmpMsg[1024];
+		sprintf(tmpMsg,_("No value found for the requested output %s."),tmpI->name);
+		errorException(m,tmpMsg,"InternalError",NULL);
+		fclose(ofile);
+		free(file_name);
+		free(file_path);
+		return;
+	      }
+	      if(strcasecmp(format,"BoundingBoxData")!=0){
+		map* size=getMap(tmpI->content,"size");
+		if(size!=NULL && toto!=NULL)
+		  fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile);
+		else
+		  if(toto!=NULL && toto->value!=NULL)
+		    fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);
+	      }else{
+		printBoundingBoxDocument(m,tmpI,ofile);
+	      }
+	      fclose(ofile);
 	    }
-	    else {
-	      // Obtain default file extension (see mimetypes.h).	      
-	      // If the MIME type is not recognized, txt is used as the default extension
-	      map* mtype=getMap(tmpI->content,"mimeType");
-	      getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);
+
+	    map *tmp2=getMapFromMaps(m,"main","tmpUrl");
+	    map *tmp3=getMapFromMaps(m,"main","serverAddress");
+	    char *file_url=NULL;
+	    if(strncasecmp(tmp2->value,"http://",7)==0 ||
+	       strncasecmp(tmp2->value,"https://",8)==0){
+	      file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char));
+	      sprintf(file_url,"%s/%s",tmp2->value,file_name);
+	    }else{
+	      file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char));
+	      sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name);
 	    }
+	    addToMap(tmpI->content,"Reference",file_url);
 	    if(file_name!=NULL)
 	      free(file_name);
-	    file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char));
-	    sprintf(file_name,"ZOO_DATA_%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);
-	    itn++;
-	    file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
-	    sprintf(file_path,"%s/%s",tmp1->value,file_name);
-
-	    FILE *ofile=fopen(file_path,"wb");
-	    if(ofile==NULL){
-	      char tmpMsg[1024];
-	      sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name);
-	      errorException(m,tmpMsg,"InternalError",NULL);
-	      free(file_name);
-	      free(file_path);
-	      return;
-	    }
-
-	    toto=getMap(tmpI->content,"value");
-	    if(toto==NULL){
-	      char tmpMsg[1024];
-	      sprintf(tmpMsg,_("No value found for the requested output %s."),tmpI->name);
-	      errorException(m,tmpMsg,"InternalError",NULL);
-	      fclose(ofile);
-	      free(file_name);
-	      free(file_path);
-	      return;
-	    }
-	    if(strcasecmp(format,"BoundingBoxData")!=0){
-	      map* size=getMap(tmpI->content,"size");
-	      if(size!=NULL && toto!=NULL)
-		fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile);
-	      else
-		if(toto!=NULL && toto->value!=NULL)
-		  fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);
-	    }else{
-	      printBoundingBoxDocument(m,tmpI,ofile);
-	    }
-	    fclose(ofile);
-	  }
-
-	  map *tmp2=getMapFromMaps(m,"main","tmpUrl");
-	  map *tmp3=getMapFromMaps(m,"main","serverAddress");
-	  char *file_url=NULL;
-	  if(strncasecmp(tmp2->value,"http://",7)==0 ||
-	     strncasecmp(tmp2->value,"https://",8)==0){
-	    file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char));
-	    sprintf(file_url,"%s/%s",tmp2->value,file_name);
-	  }else{
-	    file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char));
-	    sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name);
-	  }
-	  addToMap(tmpI->content,"Reference",file_url);
-	  if(file_name!=NULL)
-	    free(file_name);
-	  if(file_url!=NULL)
-	    free(file_url);
-	  file_name=NULL;
-	}
+	    if(file_url!=NULL)
+	      free(file_url);
+	    file_name=NULL;
+	  }
 #ifdef USE_MS
-      else{
+	else{
 	  if(testMap!=NULL){
+	    map* nbFeatures;
 	    setMapInMaps(m,"lenv","state","out");
 	    setReferenceUrl(m,tmpI);
+	    nbFeatures=getMap(tmpI->content,"nb_features");
 	    geodatatype=getMap(tmpI->content,"geodatatype");
-	    if(geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0)
+	    if((nbFeatures!=NULL && atoi(nbFeatures->value)==0) ||
+	       (geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0))
+	      error=1;
 	      res=SERVICE_FAILED;
 	  }
@@ -2887,8 +2897,17 @@
     dumpMaps(m);
 #endif
-    printProcessResponse(m,request_inputs1,cpid,
-			 s, s->name,res,  // replace serviceProvider with serviceName in stored response file name
-			 request_inputs,
-			 request_outputs);
+    if(error<0)
+      printProcessResponse(m,request_inputs1,cpid,
+			   s, s->name,res,  // replace serviceProvider with serviceName in stored response file name
+			   request_inputs,
+			   request_outputs);
+    else{
+      maps* tmpMaps=getMaps(m,"lenv");
+      dumpMap(tmpMaps->content);
+#ifdef USE_HPC
+      invokeCallback(m,NULL,NULL,7,0);
+#endif
+      printExceptionReportResponse(m,tmpMaps->content);
+    }
   }
   else{
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c	(revision 887)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c	(revision 888)
@@ -320,4 +320,5 @@
 
   map* targetPathMap=getMapFromMaps(*main_conf,configurationId,"remote_data_path");
+  map* targetPersistentPathMap=getMapFromMaps(*main_conf,configurationId,"remote_persistent_data_path");
   
   pthread_t threads_pool[50];
@@ -362,7 +363,15 @@
 	  for(i=0;i<len;i++){
 	    map* tmp=getMapArray(input->content,"cache_file",i);
+	    map* origin=getMapArray(input->content,"origin",i);
 	    char* targetName=strrchr(tmp->value,'/');
-	    char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char));
-	    sprintf(targetPath,"%s/%s",targetPathMap->value,targetName);
+	    char *targetPath;
+	    if(origin!=NULL && strcasecmp(origin->value,"SHARED")==0 && targetPersistentPathMap!=NULL){
+	      targetPath=(char*)malloc((strlen(targetPersistentPathMap->value)+strlen(targetName)+2)*sizeof(char));
+	      sprintf(targetPath,"%s/%s",targetPersistentPathMap->value,targetName);
+	    }
+	    else{
+	      targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char));
+	      sprintf(targetPath,"%s/%s",targetPathMap->value,targetName);
+	    }
 	    setMapArray(input->content,"targetPath",i,targetPath);
 	    setMapArray(input->content,"localPath",i,tmp->value);
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 887)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 888)
@@ -185,10 +185,19 @@
     map* useMs=getMap(tmpI->content,"useMapserver");
     if((minNb==NULL || atoi(minNb->value)>=1) && useMs!=NULL && strncasecmp(useMs->value,"true",4)==0){
+      int lIndex=0;
+      maps* lenv=getMaps(m,"lenv");
+      if(getMapFromMaps(m,"lenv","mapErrorNb")==NULL)
+	setMapInMaps(m,"lenv","mapErrorNb","0");
+      else{
+	map* tmpV=getMapFromMaps(m,"lenv","mapErrorNb");
+	lIndex=atoi(tmpV->value)+1;
+	addIntToMap(lenv->content,"mapErrorNb",lIndex);
+      }
       setMapInMaps(m,"lenv","mapError","true");
-      setMapInMaps(m,"lenv","locator",tmpI->name);
+      setMapArray(lenv->content,"locator",lIndex,tmpI->name);
       if(nbElements==NULL)
-	setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data."));
+	setMapArray(lenv->content,"message",lIndex,_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data."));
       else
-	setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not access any feature or pixel in te resulting file."));
+	setMapArray(lenv->content,"message",lIndex,_("The ZOO-Kernel was able to retrieve the data but could not access any feature or pixel in te resulting file."));
       if(getMapFromMaps(m,"lenv","state")==NULL)
 	errorException (m, _("Unable to find any geographic data"), "WrongInputData", tmpI->name);
@@ -889,4 +898,17 @@
        */
       tmpMap=getMap(output->content,"msStyle");
+      if(tmpMap==NULL){
+        switch(myLayer->type){
+	case MS_LAYER_POLYGON:
+	  tmpMap=getMapFromMaps(conf,"main","msStylePoly");
+	  break;
+	case MS_LAYER_LINE:
+	  tmpMap=getMapFromMaps(conf,"main","msStyleLine");
+	  break;
+	default:
+	  tmpMap=getMapFromMaps(conf,"main","msStylePoint");
+	  break;
+        }
+      }
       if(tmpMap!=NULL)
 	msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0);
@@ -1135,5 +1157,4 @@
     CPLErrorReset();
     GDALGetRasterStatistics( hBand, TRUE, TRUE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev);
-    //GDALComputeRasterStatistics( hBand, TRUE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev, NULL,NULL);
     char tmpN[21];
     sprintf(tmpN,"Band%d",iBand+1);
Index: branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c	(revision 887)
+++ branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c	(revision 888)
@@ -653,7 +653,7 @@
 int fileMd5Check(maps** conf,const char* localPath,const char* targetPath){
   if(strstr(localPath,".zca")!=NULL){
-    char *logPath=NULL;
-    char *command=(char*)malloc((strlen(targetPath)+27)*sizeof(char));
-    sprintf(command,"md5sum %s | awk {'print $1'}",targetPath);
+    char *logPath=NULL;    
+    char *command=(char*)malloc(((2*strlen(targetPath))+42)*sizeof(char));
+    sprintf(command,"(md5sum %s | awk {'print $1'}) && touch %s",targetPath,targetPath);
     if(ssh_exec(*conf,command,ssh_get_cnt(*conf))<=0){
       return -1;
