Index: /trunk/zoo-project/zoo-kernel/request_parser.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/request_parser.c	(revision 630)
+++ /trunk/zoo-project/zoo-kernel/request_parser.c	(revision 631)
@@ -902,33 +902,4 @@
 			  addToMap (tmpmaps->content, "value",
 				    (char *) tmp);
-			  map *tmpv = getMap (tmpmaps->content, "value");
-			  char *res = NULL;
-			  char *curs = tmpv->value;
-			  int i = 0;
-			  for (i = 0; i <= strlen (tmpv->value) / 64;
-			       i++)
-			    {
-			      if (res == NULL)
-				res =
-				  (char *) malloc (67 * sizeof (char));
-			      else
-				res =
-				  (char *) realloc (res,
-						    (((i + 1) * 65) +
-						     i) * sizeof (char));
-			      int csize = i * 65;
-			      strncpy (res + csize, curs, 64);
-			      if (i == xmlStrlen (tmp) / 64)
-				strcat (res, "\n\0");
-			      else
-				{
-				  strncpy (res + (((i + 1) * 64) + i),
-					   "\n\0", 2);
-				  curs += 64;
-				}
-			    }
-			  free (tmpv->value);
-			  tmpv->value = zStrdup (res);
-			  free (res);
 			  xmlFree (tmp);
 			}
@@ -937,6 +908,8 @@
 		}
 	      cur2 = cur2->next;
+	      while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE){
+		cur2 = cur2->next;
+	      }
 	    }
-
 	  {
 	    maps *testPresence =
Index: /trunk/zoo-project/zoo-kernel/service.h
===================================================================
--- /trunk/zoo-project/zoo-kernel/service.h	(revision 630)
+++ /trunk/zoo-project/zoo-kernel/service.h	(revision 631)
@@ -1058,9 +1058,5 @@
 	fprintf(stderr,"%s = %s\n",tmpV[i],tmpVI->value);
 #endif
-	if(i<7)
-	  setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
-	else
-	  if(strncasecmp(tmpV[7],"mimeType",8)==0)
-	    setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
+	setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
       }
     }
Index: /trunk/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_internal.c	(revision 630)
+++ /trunk/zoo-project/zoo-kernel/service_internal.c	(revision 631)
@@ -2948,4 +2948,81 @@
 }
 
+/**
+ * Write a file from value and length
+ *
+ * @param fname the file name
+ * @param val the value
+ * @param length the value length
+ */
+int writeFile(char* fname,char* val,int length){
+  FILE* of=fopen(fname,"wb");
+  if(of==NULL){
+    return -1;
+  }
+  size_t ret=fwrite(val,sizeof(char),length,of);
+  if(ret<length){
+    fprintf(stderr,"Write error occured!\n");
+    fclose(of);
+    return -1;
+  }
+  fclose(of);
+  return 1;
+}
+
+/**
+ * Dump all values in a maps as files
+ *
+ * @param main_conf the maps containing the settings of the main.cfg file
+ * @param in the maps containing values to dump as files
+ */
+void dumpMapsValuesToFiles(maps** main_conf,maps** in){
+  map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath");
+  map* tmpSid=getMapFromMaps(*main_conf,"lenv","sid");
+  maps* inputs=*in;
+  int length=0;
+  while(inputs!=NULL){
+    if(getMap(inputs->content,"mimeType")!=NULL &&
+       getMap(inputs->content,"cache_file")==NULL){
+      map* cMap=inputs->content;
+      if(getMap(cMap,"length")!=NULL){
+	map* tmpLength=getMap(cMap,"length");
+	int len=atoi(tmpLength->value);
+	int k=0;
+	for(k=0;k<len;k++){
+	  map* cMimeType=getMapArray(cMap,"mimeType",k);
+	  map* cValue=getMapArray(cMap,"value",k);
+	  map* cSize=getMapArray(cMap,"size",k);
+	  char file_ext[32];
+	  getFileExtension(cMimeType != NULL ? cMimeType->value : NULL, file_ext, 32);
+	  char* val=(char*)malloc((strlen(tmpPath->value)+strlen(inputs->name)+strlen(tmpSid->value)+strlen(file_ext)+16)*sizeof(char));
+	  sprintf(val,"%s/Input_%s_%s_%d.%s",tmpPath->value,inputs->name,tmpSid->value,k,file_ext);
+	  length=0;
+	  if(cSize!=NULL){
+	    length=atoi(cSize->value);
+	  }
+	  writeFile(val,cValue->value,length);
+	  setMapArray(cMap,"cache_file",k,val);
+	  free(val);
+	}
+      }else{
+	int length=0;
+	map* cMimeType=getMap(cMap,"mimeType");
+	map* cValue=getMap(cMap,"value");
+	map* cSize=getMap(cMap,"size");
+	char file_ext[32];
+	getFileExtension(cMimeType != NULL ? cMimeType->value : NULL, file_ext, 32);
+	char *val=(char*)malloc((strlen(tmpPath->value)+strlen(inputs->name)+strlen(tmpSid->value)+strlen(file_ext)+16)*sizeof(char));
+	sprintf(val,"%s/Input_%s_%s_%d.%s",tmpPath->value,inputs->name,tmpSid->value,0,file_ext);
+	if(cSize!=NULL){
+	  length=atoi(cSize->value);
+	}
+	writeFile(val,cValue->value,length);
+	addToMap(cMap,"cache_file",val);
+	free(val);
+      }
+    }
+    inputs=inputs->next;
+  }
+}
 
 /**
@@ -3008,7 +3085,44 @@
 
 /**
+ * Read Base64 value and split it value by lines of 64 char.
+ *
+ * @param in the map containing the value to split
+ */
+void readBase64(map **in){
+  char *res = NULL;
+  char *curs = (*in)->value;
+  int i = 0;
+  for (i = 0; i <= strlen ((*in)->value) / 64;
+       i++)
+    {
+      if (res == NULL)
+	res =
+	  (char *) malloc (65 * sizeof (char));
+      else
+	res =
+	  (char *) realloc (res,
+			    (((i + 1) * 65) +
+			     i) * sizeof (char));
+      int csize = i * 65;
+      strncpy (res + csize, curs, 64);
+      if (i == strlen ((*in)->value) / 64)
+	strcat (res, "\n\0");
+      else
+	{
+	  strncpy (res + (((i + 1) * 64) + i),
+		   "\n\0", 2);
+	  curs += 64;
+	}
+    }
+  free ((*in)->value);
+  (*in)->value = zStrdup (res);
+  free (res);
+}
+
+/**
  * Make sure that each value encoded in base64 in a maps is decoded.
  *
  * @param in the maps containing the values
+ * @see readBase64
  */
 void ensureDecodedBase64(maps **in){
@@ -3018,4 +3132,5 @@
     if(tmp!=NULL && strncasecmp(tmp->value,"base64",6)==0){
       tmp=getMap(cursor->content,"value");
+      readBase64(&tmp);
       addToMap(cursor->content,"base64_value",tmp->value);
       int size=0;
@@ -3037,4 +3152,5 @@
 	  sprintf(key,"base64_value_%d",i);
 	  tmp=getMapArray(cursor->content,"value",i);
+	  readBase64(&tmp);
 	  addToMap(cursor->content,key,tmp->value);
 	  int size=0;
@@ -4122,2 +4238,3 @@
 #endif
 }
+
Index: /trunk/zoo-project/zoo-kernel/service_internal.h
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_internal.h	(revision 630)
+++ /trunk/zoo-project/zoo-kernel/service_internal.h	(revision 631)
@@ -202,4 +202,6 @@
   void outputResponse(service*,maps*,maps*,map*,int,maps*,int);
 
+  void dumpMapsValuesToFiles(maps**,maps**);
+
   char *base64(const char*,int);
   char *base64d(const char*,int,int*);
Index: /trunk/zoo-project/zoo-kernel/service_internal_otb.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_internal_otb.c	(revision 630)
+++ /trunk/zoo-project/zoo-kernel/service_internal_otb.c	(revision 631)
@@ -98,26 +98,4 @@
 
 /**
- * Write a file from value and length
- *
- * @param fname the file name
- * @param val the value
- * @param length the value length
- */
-int writeFile(char* fname,char* val,int length){
-  FILE* of=fopen(fname,"wb");
-  if(of==NULL){
-    return -1;
-  }
-  size_t ret=fwrite(val,sizeof(char),length,of);
-  if(ret<length){
-    fprintf(stderr,"Write error occured!\n");
-    fclose(of);
-    return -1;
-  }
-  fclose(of);
-  return 1;
-}
-
-/**
  * Load and run an OTB Application corresponding to the service by using inputs parameters.
  * Define the m_Conf 
@@ -137,5 +115,4 @@
   map* tmp=NULL;
   int res=-1;
-
   std::vector<std::string> list = ApplicationRegistry::GetAvailableApplications();
   if (list.size() == 0){
@@ -146,6 +123,8 @@
     free(tmps);
     res=-1;
+    return res;
   }
   else{
+    dumpMapsValuesToFiles(main_conf,real_inputs);
     for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it){
       if(s->name==*it){
@@ -212,106 +191,9 @@
 		    setMapInMaps(inputs,paramKey.c_str(),"generated_file",tmp);
 		    dynamic_cast<OutputImageParameter *> (param.GetPointer())->SetPixelType(outPixType);
-		  }else{
-		    map* tmpPath=getMapFromMaps(m,"main","tmpPath");
-		    map* tmpSid=getMapFromMaps(m,"lenv","sid");
-		    map* tmpVal=getMapFromMaps(inputs,paramKey.c_str(),"mimeType");
-		    char file_ext[32];
-		    getFileExtension(tmpVal != NULL ? tmpVal->value : NULL, file_ext, 32);
-		    if(type == ParameterType_InputImageList){
-		      char *val=(char*)malloc((strlen(tmpPath->value)+strlen(s->name)+strlen(tmpSid->value)+strlen(file_ext)+13)*sizeof(char));
-		      sprintf(val,"%s/Input_%s_%s_%d.%s",tmpPath->value,s->name,tmpSid->value,0,file_ext);
-		      int length=0;
-		      map* tmpSize=getMap(test,"size");
-		      if(tmpSize!=NULL){
-			length=atoi(tmpSize->value);
-		      }
-		      writeFile(val,test->value,length);
-		      values.push_back(val);
-		      free(val);
-		      map* tmpLength=getMapFromMaps(inputs,paramKey.c_str(),"length");
-		      if(tmpLength!=NULL){
-			int len=atoi(tmpLength->value);
-			maps* tmpI=getMaps(inputs,paramKey.c_str());
-			for(int k=1;k<len;k++){
-			  val=(char*)malloc((strlen(tmpPath->value)+strlen(s->name)+strlen(tmpSid->value)+strlen(file_ext)+13)*sizeof(char));
-			  sprintf(val,"%s/Input_%s_%s_%d.%s",tmpPath->value,s->name,tmpSid->value,k,file_ext);
-			  length=0;
-			  map* tmpV=getMapArray(tmpI->content,"value",k);
-			  tmpSize=getMapArray(tmpI->content,"size",k);
-			  if(tmpSize!=NULL){
-			    length=atoi(tmpSize->value);
-			  }
-			  writeFile(val,tmpV->value,length);
-			  values.push_back(val);
-			  free(val);
-			}
-		      }
-		      dynamic_cast<InputImageListParameter *> (param.GetPointer())->SetListFromFileName(values);
-		    }
-		    else
-		      if(type == ParameterType_InputVectorData || type == ParameterType_InputImage
-			   || type == ParameterType_ComplexInputImage || type == ParameterType_InputVectorData
-			   || type == ParameterType_InputFilename){
-			char tmp[1024];
-			char* ext="json";
-			if(tmpVal!=NULL){
-			  char *val=(char*)malloc((strlen(tmpPath->value)+strlen(s->name)+strlen(tmpSid->value)+strlen(file_ext)+10)*sizeof(char));
-			  sprintf(val,"%s/Input_%s_%s.%s",tmpPath->value,s->name,tmpSid->value,file_ext);
-			  int length=0;
-			  map* tmpSize=getMap(test,"size");
-			  if(tmpSize!=NULL){
-			    length=atoi(tmpSize->value);
-			  }
-			  writeFile(val,test->value,length);
-
-			  if(strncasecmp(tmpVal->value,"application/zip",14)==0){
-
-			    char tmpName[1024];
-			    sprintf(tmpName,"/vsizip/%s",val);
-			    char **files=VSIReadDir(tmpName);
-			    int nFiles = CSLCount( files );
-			    char tmpSSName[1024];
-			    sprintf(tmpSSName,"%s/Input_%s_%s",tmpPath->value,s->name,tmpSid->value);
-			    mkdir(tmpSSName,0777);
-			    
-			    char tmpSName[1024];
-			    for(int kk=0;kk<nFiles;kk++){
-			      sprintf(tmpSName,"%s/%s",tmpName,files[kk]);
-			      VSILFILE* fmain=VSIFOpenL(tmpSName, "rb");
-			      if(fmain!=NULL){
-				VSIFSeekL(fmain,0,SEEK_END);
-				long count=VSIFTellL(fmain);
-				VSIRewindL(fmain);
-				
-				char *content=(char*) malloc((count+1)*sizeof(char));  
-				VSIFReadL(content,1,count*sizeof(char),fmain);
-				
-				char tmpSSSName[1024];
-				sprintf(tmpSSSName,"%s/%s",tmpSSName,files[kk]);
-				
-				FILE* fx=fopen(tmpSSSName, "wb");
-				fwrite(content,1,count,fx);
-				fclose(fx);
-				VSIFCloseL(fmain);
-				free(content);
-				std::string test1(tmpSSSName);
-				if(test1.find(".shp")!=std::string::npos){
-				  setMapInMaps(inputs,paramKey.c_str(),"cache_file",tmpSSSName);
-				  test=getMapFromMaps(inputs,paramKey.c_str(),"cache_file");
-				}
-			      }
-			    }
-			    m_Application->SetParameterString(paramKey, test->value);
-			  }else{
-			    m_Application->SetParameterString(paramKey, val);
-			  }
-			  free(val);
-			}
-		      }
-		      else
-			if(test->value!=NULL)
-			  m_Application->SetParameterString(paramKey, test->value);
-		  }
-
+		  }
+		  else{ 
+		    if(test!=NULL && test->value!=NULL)
+		      m_Application->SetParameterString(paramKey, test->value);
+		  }
 		}else{
 		  if(type == ParameterType_OutputVectorData){
Index: /trunk/zoo-project/zoo-kernel/service_internal_ruby.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_internal_ruby.c	(revision 630)
+++ /trunk/zoo-project/zoo-kernel/service_internal_ruby.c	(revision 631)
@@ -32,6 +32,5 @@
 /**
  * Load a Ruby file then run the function corresponding to the service by
- * passing the conf, inputs and outputs parameters by value as JavaScript
- * Objects.
+ * passing the conf, inputs and outputs parameters by refernce as Ruby Hash.
  *
  * @param main_conf the conf maps containing the main.cfg settings
Index: /trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 630)
+++ /trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 631)
@@ -1968,7 +1968,6 @@
           if (lid < 0)
             {
-              fprintf (stderr, "ERROR %s %d\n", __FILE__, __LINE__);
-              fflush (stderr);
-              return -1;
+              return errorException (m, _("Lock failed"),
+			      "InternalError", NULL);
             }
           else
@@ -1976,9 +1975,7 @@
               if (lockShm (lid) < 0)
                 {
-                  fprintf (stderr, "ERROR %s %d\n", __FILE__, __LINE__);
-                  fflush (stderr);
-                  return -1;
+		  return errorException (m, _("Lock failed"),
+					 "InternalError", NULL);
                 }
-              fflush (stderr);
             }
           f0 = freopen (fbkp, "w+", stdout);
@@ -1987,5 +1984,27 @@
           fclose (stdin);
 #endif
+
+	  /**
+	   * set status to SERVICE_STARTED and flush stdout to ensure full 
+	   * content was outputed (the file used to store the ResponseDocument).
+	   * The rewind stdout to restart writing from the bgining of the file,
+	   * this way the data will be updated at the end of the process run.
+	   */
+          printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value,
+                                SERVICE_STARTED, request_input_real_format,
+                                request_output_real_format);
+          fflush (stdout);
+          unlockShm (lid);
+          fflush (stderr);
+          fbkp1 =
+            (char *)
+            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
+                     1024) * sizeof (char));
+          sprintf (fbkp1, "%s/%s_final_%d.xml", r_inputs->value,
+                   r_inputs1->value, cpid);
+
+          f1 = freopen (fbkp1, "w+", stdout);
           free (flog);
+
 	  if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
 	    freeService (&s1);
@@ -2006,26 +2025,8 @@
 	    return -1;
 	  }
-      /**
-       * set status to SERVICE_STARTED and flush stdout to ensure full 
-       * content was outputed (the file used to store the ResponseDocument).
-       * The rewind stdout to restart writing from the bgining of the file,
-       * this way the data will be updated at the end of the process run.
-       */
-          printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value,
-                                SERVICE_STARTED, request_input_real_format,
-                                request_output_real_format);
-          fflush (stdout);
-          unlockShm (lid);
-          fflush (stderr);
-          fbkp1 =
-            (char *)
-            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
-                     1024) * sizeof (char));
-          sprintf (fbkp1, "%s/%s_final_%d.xml", r_inputs->value,
-                   r_inputs1->value, cpid);
-          f1 = freopen (fbkp1, "w+", stdout);
           loadServiceAndRun (&m, s1, request_inputs,
                              &request_input_real_format,
                              &request_output_real_format, &eres);
+
         }
       else
