Index: trunk/zoo-project/zoo-kernel/server_internal.c
===================================================================
--- trunk/zoo-project/zoo-kernel/server_internal.c	(revision 984)
+++ trunk/zoo-project/zoo-kernel/server_internal.c	(revision 985)
@@ -1143,7 +1143,4 @@
     if(dirp!=NULL){
       while ((dp = readdir(dirp)) != NULL){
-#ifdef DEBUG
-	fprintf(stderr,"File : %s searched : %s\n",dp->d_name,tmp);
-#endif
 	if(strstr(dp->d_name,pid)!=0){
 	  sprintf(fileName,"%s/%s",r_inputs->value,dp->d_name);
@@ -1164,26 +1161,8 @@
       }
     }
-    map* pmStatusFile=getMapFromMaps(conf,"lenv","file.statusFile");
-    if(pmStatusFile!=NULL && zUnlink(pmStatusFile->value)!=0){
-	if(e_type==NULL || strncasecmp(e_type->value,"json",4)!=0)
-	  errorException (conf, 
-			  _("The job cannot be removed, a file cannot be removed"),
-			  "NoApplicableCode", NULL);
-	else{
-	  setMapInMaps(conf,"lenv","error","true");
-		    setMapInMaps(conf,"lenv","code","NoApplicableCode");
-		    setMapInMaps(conf,"lenv","message",_("The job cannot be removed, a file cannot be removed"));
-	}
-	return;
-      }
 #ifdef RELY_ON_DB
     removeService(conf,pid);
 #endif
     if(e_type==NULL || strncasecmp(e_type->value,"json",4)!=0){
-      /* No need to call 7_1 when an execution is dismissed.
-	 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-	 invokeCallback(conf,NULL,NULL,7,1);
-	 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-      */
       map* statusInfo=createMap("JobID",pid);
       addToMap(statusInfo,"Status","Dismissed");
Index: trunk/zoo-project/zoo-kernel/service_json.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_json.c	(revision 984)
+++ trunk/zoo-project/zoo-kernel/service_json.c	(revision 985)
@@ -287,5 +287,5 @@
       json_object* prop1=json_object_new_object();
       json_object_object_add(prop1,"default",json_object_new_boolean(isDefault));
-      json_object_object_add(prop1,"mimeType",json_object_new_string(tmpMap1->value));
+      json_object_object_add(prop1,"mediaType",json_object_new_string(tmpMap1->value));
       tmpMap1=getMap(iot->content,"encoding");
       if(tmpMap1!=NULL)
@@ -1046,21 +1046,13 @@
     json_object* res=json_object_new_array();
     map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
-    map* oIdentifier=getMapFromMaps(conf,"lenv","oIdentifier");
-    char* cpath=(char*)malloc((strlen(tmpPath->value)+strlen(oIdentifier->value)+14)*sizeof(char));
-    sprintf(cpath,"%s/statusInfos/%s",tmpPath->value,oIdentifier->value);
     struct dirent *dp;
-    DIR *dirp = opendir (cpath);
+    DIR *dirp = opendir (tmpPath->value);
     if(dirp!=NULL){
       while ((dp = readdir (dirp)) != NULL){
-	char* extn = strstr(dp->d_name, ".json");
+	char* extn = strstr(dp->d_name, "_status.json");
 	if(extn!=NULL){
 	  char* tmpStr=zStrdup(dp->d_name);
-	  tmpStr[strlen(dp->d_name)-5]=0;
-	  json_object* cjob=json_object_new_object();
-	  json_object_object_add(cjob,"id",json_object_new_string(tmpStr));
-	  json_object *jobj=printJobStatus(conf,tmpStr);
-	  if(jobj!=NULL)
-	    json_object_object_add(cjob,"infos",jobj);
-	  free(tmpStr);
+	  tmpStr[strlen(dp->d_name)-12]=0;
+	  json_object* cjob=printJobStatus(conf,tmpStr);
 	  json_object_array_add(res,cjob);
 	}
@@ -1121,7 +1113,7 @@
 	json_object* res3=json_object_new_object();
 	if(tmpMap!=NULL)
-	  json_object_object_add(res3,"mimeType",json_object_new_string(tmpMap->value));
+	  json_object_object_add(res3,"mediaType",json_object_new_string(tmpMap->value));
 	else{
-	  json_object_object_add(res3,"mimeType",json_object_new_string("text/plain"));
+	  json_object_object_add(res3,"mediaType",json_object_new_string("text/plain"));
 	  map* pmDataType=getMap(resu->content,"dataType");
 	  if(pmDataType!=NULL){
@@ -1248,5 +1240,4 @@
     json_object* res=json_object_new_array();
     map *tmpPath = getMapFromMaps (conf, "openapi", "rootUrl");
-    map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier");
     map *sessId = getMapFromMaps (conf, "lenv", "usid");
     if(sessId==NULL){
@@ -1254,11 +1245,9 @@
     }
     char *Url0=(char*) malloc((strlen(tmpPath->value)+
-			       strlen(cIdentifier->value)+
 			       strlen(sessId->value)+18)*sizeof(char));
     int needResult=-1;
     char *message, *status;
-    sprintf(Url0,"%s/processes/%s/jobs/%s",
+    sprintf(Url0,"%s/jobs/%s",
 	    tmpPath->value,
-	    cIdentifier->value,
 	    sessId->value);
     if(getMapFromMaps(conf,"lenv","gs_location")==NULL)
@@ -1276,9 +1265,8 @@
       free(Url0);
       Url0=(char*) malloc((strlen(tmpPath->value)+
-			   strlen(cIdentifier->value)+strlen(sessId->value)+
+			   strlen(sessId->value)+
 			   25)*sizeof(char));
-      sprintf(Url0,"%s/processes/%s/jobs/%s/results",
+      sprintf(Url0,"%s/jobs/%s/results",
 	      tmpPath->value,
-	      cIdentifier->value,
 	      sessId->value);
       json_object* val1=json_object_new_object();
@@ -1305,5 +1293,4 @@
   char* json_getStatusFilePath(maps* conf){
     map *tmpPath = getMapFromMaps (conf, "main", "tmpPath");
-    map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier");
     map *sessId = getMapFromMaps (conf, "lenv", "usid");
     if(sessId!=NULL){
@@ -1313,21 +1300,9 @@
     }else
       sessId = getMapFromMaps (conf, "lenv", "gs_usid");
+    
     char *tmp1=(char*) malloc((strlen(tmpPath->value)+
-			       strlen(cIdentifier->value)+14)*sizeof(char));
-    sprintf(tmp1,"%s/statusInfos/%s",
+			       strlen(sessId->value)+14)*sizeof(char));
+    sprintf(tmp1,"%s/%s_status.json",
 	    tmpPath->value,
-	    cIdentifier->value);
-    if(zMkdir(tmp1) != 0 && errno != EEXIST){
-      fprintf(stderr,"Issue creating directory %s\n",tmp1);
-      return NULL;
-    }
-    tmp1=(char*) realloc(tmp1,(strlen(tmpPath->value)+
-			       strlen(cIdentifier->value)+
-			       strlen(sessId->value)+21)*sizeof(char));
-    int needResult=0;
-    char *message, *rstatus;
-    sprintf(tmp1,"%s/statusInfos/%s/%s.json",
-	    tmpPath->value,
-	    cIdentifier->value,
 	    sessId->value);
     return tmp1;
@@ -1336,10 +1311,7 @@
   char* getResultPath(maps* conf,char* jobId){
     map *tmpPath = getMapFromMaps (conf, "main", "tmpPath");
-    map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier");
     char *pacUrl=(char*) malloc((strlen(tmpPath->value)+
-				 strlen(cIdentifier->value)+
 				 strlen(jobId)+8)*sizeof(char));
-    sprintf(pacUrl,"%s/%s_%s.json",tmpPath->value,
-	    cIdentifier->value,jobId);
+    sprintf(pacUrl,"%s/%s.json",tmpPath->value,jobId);
     return pacUrl;
   }
@@ -1472,4 +1444,5 @@
     if(sessId!=NULL)
       json_object_object_add(res,"jobID",json_object_new_string(sessId->value));
+
     json_object_object_add(res,"status",json_object_new_string(rstatus));
     map* mMap=getMapFromMaps(conf,"lenv","gs_message");
@@ -1486,11 +1459,6 @@
       json_object* res1=json_object_new_array();
       map *tmpPath = getMapFromMaps (conf, "openapi", "rootUrl");
-      map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier");
-      char *Url0=(char*) malloc((strlen(tmpPath->value)+
-				 strlen(cIdentifier->value)+
-				 17)*sizeof(char));
-      sprintf(Url0,"%s/processes/%s/jobs",	      
-	      tmpPath->value,
-	      cIdentifier->value);
+      char *Url0=(char*) malloc((strlen(tmpPath->value)+17)*sizeof(char));
+      sprintf(Url0,"%s/jobs",tmpPath->value);
       json_object* val=json_object_new_object();
       json_object_object_add(val,"title",
Index: trunk/zoo-project/zoo-kernel/sqlapi.c
===================================================================
--- trunk/zoo-project/zoo-kernel/sqlapi.c	(revision 984)
+++ trunk/zoo-project/zoo-kernel/sqlapi.c	(revision 985)
@@ -565,5 +565,5 @@
     return NULL;
   OGRFeature  *poFeature = NULL;
-  const char *tmp1;
+  char *tmp1;
   int hasRes=-1;
   while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
Index: trunk/zoo-project/zoo-kernel/ulinet.c
===================================================================
--- trunk/zoo-project/zoo-kernel/ulinet.c	(revision 984)
+++ trunk/zoo-project/zoo-kernel/ulinet.c	(revision 985)
@@ -32,5 +32,4 @@
 #include <assert.h>
 #include <ctype.h>
-#include "fcgi_stdio.h"
 
 /**
Index: trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 984)
+++ trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 985)
@@ -443,4 +443,146 @@
 }
 
+
+/**
+ * Parse the ZOO-Service ZCFG to fill the service datastructure
+ *
+ * @param zooRegistry the populated registry
+ * @param m the maps pointer to the content of main.cfg file
+ * @param spService the pointer to the service pointer to be filled
+ * @param request_inputs the map pointer for http request inputs
+ * @param ntmp the path where the ZCFG files are stored
+ * @param cIdentifier the service identifier
+ * @param funcError the error function to be used in case of error
+ */
+int fetchService(registry* zooRegistry,maps* m,service** spService, map* request_inputs,char* ntmp,char* cIdentifier,void (funcError) (maps*, map*)){
+  char tmps1[1024];
+  map *r_inputs=NULL;
+  service* s1=*spService;
+  map* pmExecutionType=getMapFromMaps(m,"main","executionType");
+  map* import = getMapFromMaps (m, IMPORTSERVICE, cIdentifier); 
+  if (import != NULL && import->value != NULL) { 
+    strncpy(tmps1, import->value, 1024);
+    setMapInMaps (m, "lenv", "Identifier", cIdentifier);
+    setMapInMaps (m, "lenv", "oIdentifier", cIdentifier);
+  } 
+  else {
+    snprintf (tmps1, 1024, "%s/%s.zcfg", ntmp, cIdentifier);
+#ifdef DEBUG
+    fprintf (stderr, "Trying to load %s\n", tmps1);
+#endif
+    if (strstr (cIdentifier, ".") != NULL)
+      {
+	setMapInMaps (m, "lenv", "oIdentifier", cIdentifier);
+	char *identifier = zStrdup (cIdentifier);
+	parseIdentifier (m, ntmp, identifier, tmps1);
+	map *tmpMap = getMapFromMaps (m, "lenv", "metapath");
+	if (tmpMap != NULL)
+	  addToMap (request_inputs, "metapath", tmpMap->value);
+	free (identifier);
+      }
+    else
+      {
+	setMapInMaps (m, "lenv", "oIdentifier", cIdentifier);
+	setMapInMaps (m, "lenv", "Identifier", cIdentifier);
+      }
+  }
+
+  r_inputs = getMapFromMaps (m, "lenv", "Identifier");
+
+#ifdef META_DB
+  int metadb_id=_init_sql(m,"metadb");
+  //FAILED CONNECTING DB
+  if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){
+    fprintf(stderr,"ERROR CONNECTING METADB\n");
+  }
+  if(metadb_id>=0)
+    *spService=extractServiceFromDb(m,cIdentifier,0);
+  if(s1!=NULL){
+    inheritance(zooRegistry,spService);
+#ifdef USE_HPC
+    addNestedOutputs(spService);
+#endif
+    if(zooRegistry!=NULL){
+      freeRegistry(&zooRegistry);
+      free(zooRegistry);
+    }
+  }else /* Not found in MetaDB */{
+#endif
+    *spService = createService();
+    if (*spService == NULL)
+      {
+	freeMaps (&m);
+	free (m);
+	if(zooRegistry!=NULL){
+	  freeRegistry(&zooRegistry);
+	  free(zooRegistry);
+	}
+	map* error=createMap("code","InternalError");
+	if(pmExecutionType!=NULL && strncasecmp(pmExecutionType->value,"xml",3)==0){
+	    addToMap(error,"locator", "NULL");
+	    addToMap(error,"text",_("Unable to allocate memory"));
+	}
+	else{
+	  addToMap(error,"message",_("Unable to allocate memory"));
+	}
+
+	setMapInMaps(m,"lenv","status_code","404 Bad Request");
+	funcError(m,error);
+
+	return 1; /*errorException (m, _("Unable to allocate memory"),
+		    "InternalError", NULL);*/
+      }
+
+    int saved_stdout = zDup (fileno (stdout));
+    zDup2 (fileno (stderr), fileno (stdout));
+    int t = readServiceFile (m, tmps1, spService, cIdentifier);
+    if(t>=0){
+      inheritance(zooRegistry,spService);
+#ifdef USE_HPC
+      addNestedOutputs(spService);
+#endif
+    }
+    if(zooRegistry!=NULL){
+      freeRegistry(&zooRegistry);
+      free(zooRegistry);
+    }
+    fflush(stderr);
+    fflush (stdout);
+    zDup2 (saved_stdout, fileno (stdout));
+    zClose (saved_stdout);
+    if (t < 0)
+      {
+	r_inputs = getMapFromMaps (m, "lenv", "oIdentifier");
+	if(r_inputs!=NULL){
+	  char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value));
+	  sprintf (tmpMsg,
+		   _
+		   ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."),
+		   r_inputs->value);
+	  map* error=createMap("code","NoSuchProcess");
+	  if(pmExecutionType!=NULL && strncasecmp(pmExecutionType->value,"xml",3)==0){
+	    addToMap(error,"locator", "identifier");
+	    addToMap(error,"text",tmpMsg);
+	    addToMap(error,"code","InvalidParameterValue");
+	  }
+	  else{
+	    addToMap(error,"message",tmpMsg);
+	  }
+	  //setMapInMaps(conf,"lenv","status_code","404 Bad Request");
+	  funcError(m,error);
+	  
+	  //errorException (m, tmpMsg, "InvalidParameterValue", "identifier");
+	  free (tmpMsg);
+	  free (*spService);
+	  freeMaps (&m);
+	  free (m);
+	  return 1;
+	}
+      }
+#ifdef META_DB
+  }
+#endif
+  return 0;
+}
 
 /**
@@ -1923,4 +2065,6 @@
       }
     addMapsToMaps(&m,m1);
+    freeMaps(&m1);
+    free(m1);
     map* pmTmp0=getMapFromMaps(m,"openapi","full_html_support");
     if(strstr(cgiQueryString,".html")==NULL && strstr(cgiAccept,"text/html")!=NULL && pmTmp0!=NULL && strncasecmp(pmTmp0->value,"true",4)==0){
@@ -1928,6 +2072,6 @@
       char* pacTmpUrl=NULL;
       if(strcmp(cgiQueryString,"/")!=0){
-	 pacTmpUrl=(char*)malloc((strlen(cgiQueryString)+strlen(pmTmpUrl->value)+6)*sizeof(char));
-	 sprintf(pacTmpUrl,"%s%s.html",pmTmpUrl->value,cgiQueryString);
+	pacTmpUrl=(char*)malloc((strlen(cgiQueryString)+strlen(pmTmpUrl->value)+6)*sizeof(char));
+	sprintf(pacTmpUrl,"%s%s.html",pmTmpUrl->value,cgiQueryString);
       }
       else{
@@ -1946,17 +2090,28 @@
     /* - Root url */
     if(cgiContentLength==1){
+      if(strncasecmp(cgiRequestMethod,"GET",3)!=0){
+	setMapInMaps(m,"lenv","status_code","405");
+	map* pamError=createMap("code","InvalidMethod");
+	const char* pccErr=_("This API does not support the method.");
+	addToMap(pamError,"message",pccErr);
+	printExceptionReportResponseJ(m,pamError);
+	// TODO: cleanup memory
+	return 1;
+      }
       map* tmpMap=getMapFromMaps(m,"main","serverAddress");
       json_object *res1=json_object_new_array();
-      const char* urls[4]={
-	"/","/api","/conformance","/processes"
-      };
+
+      map* pmVal=getMapFromMaps(m,"openapi","links");
+      char *orig=zStrdup(pmVal->value);
+      char *saveptr;
+      char *tmps = strtok_r (orig, ",", &saveptr);
       map* tmpUrl=getMapFromMaps(m,"openapi","rootUrl");
-      for(int kk=0;kk<4;kk++){
-	maps* tmpMaps=getMaps(m,urls[kk]);
+      while(tmps!=NULL){
+	maps* tmpMaps=getMaps(m,tmps);
 	if(tmpMaps!=NULL){
 	  json_object *res2;
 	  res2=mapToJson(tmpMaps->content);
-	  char* tmpStr=(char*) malloc((strlen(tmpUrl->value)+strlen(urls[kk])+2)*sizeof(char));
-	  sprintf(tmpStr,"%s%s",tmpUrl->value,urls[kk]);
+	  char* tmpStr=(char*) malloc((strlen(tmpUrl->value)+strlen(tmps)+2)*sizeof(char));
+	  sprintf(tmpStr,"%s%s",tmpUrl->value,tmps);
 	  json_object_object_add(res2,"href",json_object_new_string(tmpStr));
 	  free(tmpStr);
@@ -1967,6 +2122,6 @@
 	  if(pmTmp!=NULL)
 	    pacTitle=zStrdup(pmTmp->value);
-	  char* pacTmp=(char*) malloc((strlen(urls[kk])+6)*sizeof(char));
-	  sprintf(pacTmp,"%s.html",urls[kk]);
+	  char* pacTmp=(char*) malloc((strlen(tmps)+6)*sizeof(char));
+	  sprintf(pacTmp,"%s.html",tmps);
 	  tmpMaps=getMaps(m,pacTmp);
 	  if(tmpMaps==NULL && strncasecmp(pacTmp,"/.html",6)==0)
@@ -1982,7 +2137,7 @@
 	      tmpStr=(char*) malloc((strlen(tmpUrl->value)+12)*sizeof(char));
 	      sprintf(tmpStr,"%s/index.html",tmpUrl->value);
-	    }else{
-	      tmpStr=(char*) malloc((strlen(tmpUrl->value)+strlen(urls[kk])+6)*sizeof(char));
-	      sprintf(tmpStr,"%s%s.html",tmpUrl->value,urls[kk]);
+	    }else{map* tmpUrl=getMapFromMaps(m,"openapi","rootUrl");
+	      tmpStr=(char*) malloc((strlen(tmpUrl->value)+strlen(tmps)+6)*sizeof(char));
+	      sprintf(tmpStr,"%s%s.html",tmpUrl->value,tmps);
 	    }
 	    json_object_object_add(res3,"href",json_object_new_string(tmpStr));
@@ -1994,5 +2149,8 @@
 	    free(pacTitle);	  
 	}
+	tmps = strtok_r (NULL, ",", &saveptr);
       }
+      free(orig);
+      
       map* pmTmp=getMapFromMaps(m,"identification","title");
       if(pmTmp!=NULL)
@@ -2044,5 +2202,398 @@
       res=res3;
       //json_object_object_add(res,"processes",res3);
-    }else{
+    }
+    else if(strstr(cgiQueryString,"/processes")==NULL && (strstr(cgiQueryString,"/jobs")!=NULL || strstr(cgiQueryString,"/jobs/")!=NULL)){
+      /* - /jobs url */
+      fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+      fflush(stderr);
+      if(strncasecmp(cgiRequestMethod,"DELETE",6)==0) {
+	fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+	fflush(stderr);
+	char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6);
+	setMapInMaps(m,"lenv","gs_usid",jobId);
+	setMapInMaps(m,"lenv","file.statusFile",json_getStatusFilePath(m));
+	fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+	fflush(stderr);
+	runDismiss(m,jobId);
+	fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+	fflush(stderr);
+	map* pmError=getMapFromMaps(m,"lenv","error");
+	if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){
+	  printExceptionReportResponseJ(m,getMapFromMaps(m,"lenv","code"));
+	  return 1;
+	}
+	else{
+	  setMapInMaps(m,"lenv","gs_location","false");
+	  res=createStatus(m,SERVICE_DISMISSED);
+	}
+	fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+	fflush(stderr);
+      }
+      else if(strcasecmp(cgiRequestMethod,"get")==0){
+	/* - /jobs List (GET) */
+	if(strlen(cgiQueryString)<=6)
+	  res=printJobList(m);
+	else{
+
+	  
+	  char* tmpUrl=strstr(cgiQueryString,"/jobs/");
+	  if(tmpUrl!=NULL && strlen(tmpUrl)>6){
+	    if(strncasecmp(cgiRequestMethod,"DELETE",6)==0){
+	      char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6);
+	      setMapInMaps(m,"lenv","gs_usid",jobId);
+	      setMapInMaps(m,"lenv","file.statusFile",json_getStatusFilePath(m));
+	      runDismiss(m,jobId);
+	      map* pmError=getMapFromMaps(m,"lenv","error");
+	      if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){
+		printExceptionReportResponseJ(m,getMapFromMaps(m,"lenv","code"));
+		return 1;
+	      }
+	      else{
+		setMapInMaps(m,"lenv","gs_location","false");
+		res=createStatus(m,SERVICE_DISMISSED);
+	      }
+	    }else{
+	      char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6);
+	      if(strlen(jobId)==36){
+		res=printJobStatus(m,jobId);
+	      }else{
+
+		// In case the service has run, then forward request to target result file
+		//char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6);
+		jobId[strlen(jobId)-8]=0;
+		fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId);
+		fflush(stderr);
+		char *sid=getStatusId(m,jobId);
+		if(sid==NULL){
+		  fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId);
+		  fflush(stderr);
+		  map* error=createMap("code","NoSuchJob");
+		  addToMap(error,"message",_("The JobID from the request does not match any of the Jobs running on this server"));
+		  printExceptionReportResponseJ(m,error);
+		  return 1;
+		}else{
+		  fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId);
+		  fflush(stderr);
+		  if(isRunning(m,jobId)>0){
+		    map* error=createMap("code","ResultNotReady");
+		    addToMap(error,"message",_("The job is still running."));
+		    printExceptionReportResponseJ(m,error);
+		    return 1;
+		  }else{
+		    fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId);
+		    fflush(stderr);
+		    char *Url0=getResultPath(m,jobId);
+		    fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,Url0);
+		    fflush(stderr);
+		    //map *cIdentifier = getMapFromMaps (m, "lenv", "oIdentifier");
+		    zStatStruct f_status;
+		    int s=zStat(Url0, &f_status);
+		    if(s==0 && f_status.st_size>0){
+		      fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,Url0);
+		      fflush(stderr);
+		      
+		      if(f_status.st_size>15){
+			json_object* pjoTmp=json_readFile(m,Url0);
+			json_object* pjoCode=NULL;
+			json_object* pjoMessage=NULL;
+			if(pjoTmp!=NULL &&
+			   json_object_object_get_ex(pjoTmp,"code",&pjoCode)!=FALSE &&
+			   json_object_object_get_ex(pjoTmp,"description",&pjoMessage)!=FALSE){
+			  map* error=createMap("code",json_object_get_string(pjoCode));
+			  addToMap(error,"message",json_object_get_string(pjoMessage));
+			  printExceptionReportResponseJ(m,error);
+			  return 1;			
+			}else{
+
+			  map* tmpPath = getMapFromMaps (m, "main", "tmpUrl");
+			  Url0=(char*) realloc(Url0,(strlen(tmpPath->value)+
+						     //strlen(cIdentifier->value)+
+						     strlen(jobId)+8)*sizeof(char));
+			  sprintf(Url0,"%s/%s.json",tmpPath->value,jobId);
+			  setMapInMaps(m,"headers","Location",Url0);
+			}
+			free(Url0);
+		      }else{
+			// Service Failed
+			map* statusInfo=createMap("JobID",jobId);
+			readFinalRes(m,jobId,statusInfo);
+			{
+			  map* pmStatus=getMap(statusInfo,"status");
+			  if(pmStatus!=NULL)
+			    setMapInMaps(m,"lenv","status",pmStatus->value);
+			}
+			char* tmpStr=_getStatus(m,jobId);
+			if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){
+			  char *tmpStr1=zStrdup(tmpStr);
+			  char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1);
+			  free(tmpStr);
+			  tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0';
+			  addToMap(statusInfo,"PercentCompleted",tmpStr1);
+			  addToMap(statusInfo,"Message",tmpStr0);
+			  setMapInMaps(m,"lenv","PercentCompleted",tmpStr1);
+			  setMapInMaps(m,"lenv","Message",tmpStr0);
+			  free(tmpStr0);
+			  free(tmpStr1);
+			}
+			map* error=createMap("code","NoApplicableCode");
+			addToMap(error,"message",_("The service failed to execute."));
+			printExceptionReportResponseJ(m,error);
+			return 1;
+		      }
+
+		    }else{
+		      map* error=createMap("code","NoSuchJob");
+		      addToMap(error,"message",_("The JobID seem to be running on this server but not for this process id"));
+		      printExceptionReportResponseJ(m,error);
+		      return 1;
+		    }
+		  }
+		}
+
+		
+	      }
+	      free(jobId);
+	    }
+	  }
+	}
+	  
+      }else if(strcasecmp(cgiRequestMethod,"post")==0 && (strcmp(cgiQueryString,"/jobs")==0 || strcmp(cgiQueryString,"/jobs/")==0)){
+	/* - /jobs Execution (POST) */
+	eres = SERVICE_STARTED;
+	initAllEnvironment(m,request_inputs,ntmp,"jrequest");
+	map* req=getMapFromMaps(m,"renv","jrequest");
+	json_object *jobj = NULL;
+	const char *mystring = NULL;
+	int slen = 0;
+	enum json_tokener_error jerr;
+	struct json_tokener* tok=json_tokener_new();
+	do {
+	  mystring = req->value;  // get JSON string, e.g. read from file, etc...
+	  slen = strlen(mystring);
+	  jobj = json_tokener_parse_ex(tok, mystring, slen);
+	} while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue);
+	if (jerr != json_tokener_success) {
+	  map* pamError=createMap("code","InvalidParameterValue");
+	  const char* pcTmpErr=json_tokener_error_desc(jerr);
+	  const char* pccErr=_("ZOO-Kernel cannot parse your POST data: %s");
+	  char* pacMessage=(char*)malloc((strlen(pcTmpErr)+strlen(pccErr)+1)*sizeof(char));
+	  sprintf(pacMessage,pccErr,pcTmpErr);
+	  addToMap(pamError,"message",pacMessage);
+	  printExceptionReportResponseJ(m,pamError);
+	  fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr));
+	  return 1;
+	}
+	if (tok->char_offset < slen){
+	  map* pamError=createMap("code","InvalidParameterValue");
+	  const char* pcTmpErr="None";
+	  const char* pccErr=_("ZOO-Kernel cannot parse your POST data: %s");
+	  char* pacMessage=(char*)malloc((strlen(pcTmpErr)+strlen(pccErr)+1)*sizeof(char));
+	  sprintf(pacMessage,pccErr,pcTmpErr);
+	  addToMap(pamError,"message",pacMessage);
+	  printExceptionReportResponseJ(m,pamError);
+	  fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr));
+	  return 1;
+	}
+
+	json_object* json_io=NULL;
+	char* cIdentifier=NULL;
+	if(json_object_object_get_ex(jobj,"id",&json_io)!=FALSE){
+	  cIdentifier=zStrdup(json_object_get_string(json_io));
+	}
+	fprintf(stderr,"%s %d \n", __FILE__,__LINE__);
+	fflush(stderr);
+	fetchService(zooRegistry,m,&s1,request_inputs,ntmp,cIdentifier,printExceptionReportResponseJ);
+	fprintf(stderr,"%s %d \n", __FILE__,__LINE__);
+	fflush(stderr);	
+	//maps* inputs_real_format=NULL, *outputs_real_format= NULL;
+	parseJRequest(m,s1,jobj,request_inputs,&request_input_real_format,&request_output_real_format);
+	fprintf(stderr,"%s %d \n", __FILE__,__LINE__);
+	fflush(stderr);	
+	map* preference=getMapFromMaps(m,"renv","HTTP_PREFER");
+	map* mode=getMap(request_inputs,"mode");
+	if((preference!=NULL && strcasecmp(preference->value,"respond-async")==0) ||
+	   (mode!=NULL && strncasecmp(mode->value,"async",5)==0)) {
+	  int pid;
+#ifdef DEBUG
+	  fprintf (stderr, "\nPID : %d\n", cpid);
+#endif
+#ifndef WIN32
+	  pid = fork ();
+#else
+	  if (cgiSid == NULL)
+	    {
+	      createProcess (m, request_inputs, s1, NULL, cpid,
+			     request_input_real_format,
+			     request_output_real_format);
+	      pid = cpid;
+	    }
+	  else
+	    {
+	      pid = 0;
+	      cpid = atoi (cgiSid);
+	      updateStatus(m,0,_("Initializing"));
+	    }
+#endif
+	  if (pid > 0)
+	    {
+	      //
+	      // dady :
+	      // set status to SERVICE_ACCEPTED
+	      //
+#ifdef DEBUG
+	      fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid,
+		       zGetpid ());
+#endif
+	      eres = SERVICE_ACCEPTED;
+	      createStatusFile(m,eres);
+	      //invokeBasicCallback(m,SERVICE_ACCEPTED);
+	      printHeaders(m);
+	      printf("Status: 201 Created \r\n\r\n");
+	      return 1;
+	    }
+	  else if (pid == 0)
+	    {
+	      eres = SERVICE_STARTED;
+	      //
+	      // son : have to close the stdout, stdin and stderr to let the parent
+	      // process answer to http client.
+	      //
+	      map* oid = getMapFromMaps (m, "lenv", "oIdentifier");
+	      map* usid = getMapFromMaps (m, "lenv", "uusid");
+	      map* tmpm = getMapFromMaps (m, "lenv", "osid");
+	      int cpid = atoi (tmpm->value);
+	      pid=cpid;
+	      r_inputs = getMapFromMaps (m, "main", "tmpPath");
+	      setMapInMaps (m, "lenv", "async","true");
+	      map* r_inputs1 = createMap("ServiceName", s1->name);
+	      // Create the filename for the result file (.res)
+	      fbkpres =
+		(char *)
+		malloc ((strlen (r_inputs->value) +
+			 strlen (usid->value) + 7) * sizeof (char));                    
+	      sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value);
+	      bmap = createMaps("status");
+	      bmap->content=createMap("usid",usid->value);
+	      addToMap(bmap->content,"sid",tmpm->value);
+	      addIntToMap(bmap->content,"pid",zGetpid());
+	  
+	      // Create PID file referencing the OS process identifier
+	      fbkpid =
+		(char *)
+		malloc ((strlen (r_inputs->value) +
+			 strlen (usid->value) + 7) * sizeof (char));
+	      sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value);
+	      setMapInMaps (m, "lenv", "file.pid", fbkpid);
+
+	      f0 = freopen (fbkpid, "w+",stdout);
+	      printf("%d",zGetpid());
+	      fflush(stdout);
+
+	      // Create SID file referencing the semaphore name
+	      fbkp =
+		(char *)
+		malloc ((strlen (r_inputs->value) + strlen (oid->value) +
+			 strlen (usid->value) + 7) * sizeof (char));
+	      sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value);
+	      setMapInMaps (m, "lenv", "file.sid", fbkp);
+	      FILE* f2 = freopen (fbkp, "w+",stdout);
+	      printf("%s",tmpm->value);
+	      fflush(f2);
+	      free(fbkp);
+
+	      fbkp =
+		(char *)
+		malloc ((strlen (r_inputs->value) + 
+			 strlen (usid->value) + 7) * sizeof (char));
+	      sprintf (fbkp, "%s/%s.json", r_inputs->value, 
+		       usid->value);
+	      setMapInMaps (m, "lenv", "file.responseInit", fbkp);
+	      flog =
+		(char *)
+		malloc ((strlen (r_inputs->value) + strlen (oid->value) +
+			 strlen (usid->value) + 13) * sizeof (char));
+	      sprintf (flog, "%s/%s_%s_error.log", r_inputs->value,
+		       oid->value, usid->value);
+	      setMapInMaps (m, "lenv", "file.log", flog);
+#ifdef DEBUG
+	      fprintf (stderr, "RUN IN BACKGROUND MODE \n");
+	      fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,
+		       zGetpid ());
+	      fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);
+#endif
+	      freopen (flog, "w+", stderr);
+	      fflush (stderr);
+	      f0 = freopen (fbkp, "w+", stdout);
+	      rewind (stdout);
+#ifndef WIN32
+	      fclose (stdin);
+#endif
+#ifdef RELY_ON_DB
+	      init_sql(m);
+	      recordServiceStatus(m);
+#endif
+#ifdef USE_CALLBACK
+	      invokeCallback(m,NULL,NULL,0,0);
+#endif
+	      invokeBasicCallback(m,SERVICE_STARTED);
+	      createStatusFile(m,SERVICE_STARTED);
+	      fbkp1 =
+		(char *)
+		malloc ((strlen (r_inputs->value) + strlen (oid->value) +
+			 strlen (usid->value) + 15) * sizeof (char));
+	      sprintf (fbkp1, "%s/%s_final_%s.json", r_inputs->value,
+		       oid->value, usid->value);
+	      setMapInMaps (m, "lenv", "file.responseFinal", fbkp1);
+
+	      f1 = freopen (fbkp1, "w+", stdout);
+
+	      map* serviceTypeMap=getMap(s1->content,"serviceType");
+	      if(serviceTypeMap!=NULL)
+		setMapInMaps (m, "lenv", "serviceType", serviceTypeMap->value);
+
+	      char *flenv =
+		(char *)
+		malloc ((strlen (r_inputs->value) + 
+			 strlen (usid->value) + 12) * sizeof (char));
+	      sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value);
+	      maps* lenvMaps=getMaps(m,"lenv");
+	      dumpMapsToFile(lenvMaps,flenv,1);
+	      free(flenv);
+
+	      map* testMap=getMapFromMaps(m,"main","memory");
+	      loadHttpRequests(m,request_input_real_format);
+
+	      if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,NULL)<0)
+		return -1;
+	      loadServiceAndRun (&m, s1, request_inputs,
+				 &request_input_real_format,
+				 &request_output_real_format, &eres);
+	      setMapInMaps(m,"lenv","force","true");
+	      createStatusFile(m,eres);
+	      setMapInMaps(m,"lenv","force","false");
+	      setMapInMaps(m,"lenv","no-headers","true");
+	      fflush(stdout);
+	      rewind(stdout);
+	      res=printJResult(m,s1,request_output_real_format,eres);
+	      const char* jsonStr0=json_object_to_json_string_ext(res,JSON_C_TO_STRING_PLAIN);
+	      if(getMapFromMaps(m,"lenv","jsonStr")==NULL)
+		setMapInMaps(m,"lenv","jsonStr",jsonStr0);
+	      invokeBasicCallback(m,eres);
+	    }
+	}else{
+	  loadHttpRequests(m,request_input_real_format);
+	  if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,NULL)<0)
+	    return -1;
+	  loadServiceAndRun (&m,s1,request_inputs,
+			     &request_input_real_format,
+			     &request_output_real_format,&eres);
+	  res=printJResult(m,s1,request_output_real_format,eres);
+	}
+
+	    
+      }//else error
+    
+    }
+    else{
       service* s1=NULL;
       int t=0;
@@ -2061,7 +2612,8 @@
 	if(strstr(cgiQueryString,"/jobs")==NULL && strstr(cgiQueryString,"/jobs/")==NULL){
 	  /* - /processes/{id}/ */
-	  DIR *dirp = opendir (ntmp);
+	  //DIR *dirp = opendir (ntmp);
 	  json_object *res3=json_object_new_object();
-	  char *orig = zStrdup (strstr(cgiQueryString,"/processes/")+11);
+	  char *orig = NULL;
+	  orig = zStrdup (strstr(cgiQueryString,"/processes/")+11);
 	  if(orig[strlen(orig)-1]=='/')
 	    orig[strlen(orig)-1]=0;
@@ -2080,465 +2632,31 @@
 	  }
 	  res=json_object_get(res3);
-	}else{	
-	  char* queryString=zStrdup(cgiQueryString);
-	  int len0=strlen(strstr(cgiQueryString,"/processes/")+11);
-	  int len1=strlen(cgiQueryString)-strlen(strstr(cgiQueryString,"/job"));
-	  char* cIdentifier=(char*)malloc((len1-10)*sizeof(char));
-	  int cnt=0;
-	  for(int j=11;j<len1;j++){
-	    cIdentifier[cnt]=cgiQueryString[j];
-	    cIdentifier[cnt+1]=0;
-	    cnt++;
+	}else{
+	  char* cIdentifier=NULL;
+	  if(strstr(cgiQueryString,"/processes/")!=NULL){
+
+	    
+	    int len0=strlen(strstr(cgiQueryString,"/processes/")+11);
+	    int len1=strlen(cgiQueryString)-strlen(strstr(cgiQueryString,"/job"));
+	    cIdentifier=(char*)malloc((len1-10)*sizeof(char));
+	    int cnt=0;
+	    for(int j=11;j<len1;j++){
+	      cIdentifier[cnt]=cgiQueryString[j];
+	      cIdentifier[cnt+1]=0;
+	      cnt++;
+	    }
+
+	    fprintf(stderr,"%s %d \n", __FILE__,__LINE__);
+	    fflush(stderr);
+	    fetchService(zooRegistry,m,&s1,request_inputs,ntmp,cIdentifier,printExceptionReportResponseJ);
+	    fprintf(stderr,"%s %d \n", __FILE__,__LINE__);
+	    fflush(stderr);	
+
+
 	  }
-	  char tmps1[1024];
-	  map* import = getMapFromMaps (m, IMPORTSERVICE, cIdentifier); 
-	  if (import != NULL && import->value != NULL) { 
-	    strncpy(tmps1, import->value, 1024);
-	    setMapInMaps (m, "lenv", "Identifier", cIdentifier);
-	    setMapInMaps (m, "lenv", "oIdentifier", cIdentifier);
-	  } 
-	  else {
-	    snprintf (tmps1, 1024, "%s/%s.zcfg", ntmp, cIdentifier);
-#ifdef DEBUG
-	    fprintf (stderr, "Trying to load %s\n", tmps1);
-#endif
-	    if (strstr (cIdentifier, ".") != NULL)
-	      {
-		setMapInMaps (m, "lenv", "oIdentifier", cIdentifier);
-		char *identifier = zStrdup (cIdentifier);
-		parseIdentifier (m, ntmp, identifier, tmps1);
-		map *tmpMap = getMapFromMaps (m, "lenv", "metapath");
-		if (tmpMap != NULL)
-		  addToMap (request_inputs, "metapath", tmpMap->value);
-		free (identifier);
-	      }
-	    else
-	      {
-		setMapInMaps (m, "lenv", "oIdentifier", cIdentifier);
-		setMapInMaps (m, "lenv", "Identifier", cIdentifier);
-	      }
-	  }
-
-	  r_inputs = getMapFromMaps (m, "lenv", "Identifier");
-
-#ifdef META_DB
-	  int metadb_id=_init_sql(m,"metadb");
-	  //FAILED CONNECTING DB
-	  if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){
-	    fprintf(stderr,"ERROR CONNECTING METADB\n");
-	  }
-	  if(metadb_id>=0)
-	    s1=extractServiceFromDb(m,cIdentifier,0);
-	  if(s1!=NULL){
-	    inheritance(zooRegistry,&s1);
-#ifdef USE_HPC
-	    addNestedOutputs(&s1);
-#endif
-	    if(zooRegistry!=NULL){
-	      freeRegistry(&zooRegistry);
-	      free(zooRegistry);
-	    }
-	  }else /* Not found in MetaDB */{
-#endif
-	    s1 = createService();
-	    if (s1 == NULL)
-	      {
-		freeMaps (&m);
-		free (m);
-		if(zooRegistry!=NULL){
-		  freeRegistry(&zooRegistry);
-		  free(zooRegistry);
-		}
-		free (REQUEST);
-		free (SERVICE_URL);
-		map* error=createMap("code","InternalError");
-		addToMap(error,"message",_("Unable to allocate memory"));
-		setMapInMaps(m,"lenv","status_code","404 Bad Request");
-		printExceptionReportResponseJ(m,error);
-
-		return 1; /*errorException (m, _("Unable to allocate memory"),
-			    "InternalError", NULL);*/
-	      }
-
-	    int saved_stdout = zDup (fileno (stdout));
-	    zDup2 (fileno (stderr), fileno (stdout));
-	    t = readServiceFile (m, tmps1, &s1, cIdentifier);
-	    if(t>=0){
-	      inheritance(zooRegistry,&s1);
-#ifdef USE_HPC
-	      addNestedOutputs(&s1);
-#endif
-	    }
-	    if(zooRegistry!=NULL){
-	      freeRegistry(&zooRegistry);
-	      free(zooRegistry);
-	    }
-	    fflush(stderr);
-	    fflush (stdout);
-	    zDup2 (saved_stdout, fileno (stdout));
-	    zClose (saved_stdout);
-	    if (t < 0)
-	      {
-		r_inputs = getMapFromMaps (m, "lenv", "oIdentifier");
-		if(r_inputs!=NULL){
-		  char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value));
-		  sprintf (tmpMsg,
-			   _
-			   ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."),
-			   r_inputs->value);
-		  map* error=createMap("code","NoSuchProcess");
-		  addToMap(error,"message",tmpMsg);
-		  //setMapInMaps(conf,"lenv","status_code","404 Bad Request");
-		  printExceptionReportResponseJ(m,error);
-
-		  //errorException (m, tmpMsg, "InvalidParameterValue", "identifier");
-		  free (tmpMsg);
-		  free (s1);
-		  freeMaps (&m);
-		  free (m);
-		  free (REQUEST);
-		  free (SERVICE_URL);
-		  return 0;
-		}
-	      }
-#ifdef META_DB
-	  }
-#endif
-	  if(strstr(cgiQueryString,"/jobs/")!=NULL && strlen(strstr(cgiQueryString,"/jobs/"))>6) {
-	    /* - /jobs/{jobID} and /jobs/{jobID}/result urls */
-	    if(strstr(cgiQueryString,"/results")!=NULL){
-	      // In case the service has run, then forward request to target result file
-	      char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6);
-	      jobId[strlen(jobId)-8]=0;
-	      char *sid=getStatusId(m,jobId);
-	      if(sid==NULL){
-		map* error=createMap("code","NoSuchJob");
-		addToMap(error,"message",_("The JobID from the request does not match any of the Jobs running on this server"));
-		printExceptionReportResponseJ(m,error);
-		return 1;
-	      }else{
-		if(isRunning(m,jobId)>0){
-		  map* error=createMap("code","ResultNotReady");
-		  addToMap(error,"message",_("The job is still running."));
-		  printExceptionReportResponseJ(m,error);
-		  return 1;
-		}else{
-		  char *Url0=getResultPath(m,jobId);
-		  map *cIdentifier = getMapFromMaps (m, "lenv", "oIdentifier");
-		  zStatStruct f_status;
-		  int s=zStat(Url0, &f_status);
-		  if(s==0 && f_status.st_size>0){
-		    if(f_status.st_size>15){
-		      json_object* pjoTmp=json_readFile(m,Url0);
-		      json_object* pjoCode=NULL;
-		      json_object* pjoMessage=NULL;
-		      if(pjoTmp!=NULL &&
-			 json_object_object_get_ex(pjoTmp,"code",&pjoCode)!=FALSE &&
-			 json_object_object_get_ex(pjoTmp,"description",&pjoMessage)!=FALSE){
-			map* error=createMap("code",json_object_get_string(pjoCode));
-			addToMap(error,"message",json_object_get_string(pjoMessage));
-			printExceptionReportResponseJ(m,error);
-			return 1;			
-		      }else{
-
-			map* tmpPath = getMapFromMaps (m, "main", "tmpUrl");
-			Url0=(char*) realloc(Url0,(strlen(tmpPath->value)+
-						   strlen(cIdentifier->value)+
-						   strlen(jobId)+8)*sizeof(char));
-			sprintf(Url0,"%s/%s_%s.json",tmpPath->value,
-				cIdentifier->value,jobId);
-			setMapInMaps(m,"headers","Location",Url0);
-		      }
-		      free(Url0);
-		    }else{
-		      // Service Failed
-		      map* statusInfo=createMap("JobID",jobId);
-		      readFinalRes(m,jobId,statusInfo);
-		      {
-			map* pmStatus=getMap(statusInfo,"status");
-			if(pmStatus!=NULL)
-			  setMapInMaps(m,"lenv","status",pmStatus->value);
-		      }
-		      char* tmpStr=_getStatus(m,jobId);
-		      if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){
-			char *tmpStr1=zStrdup(tmpStr);
-			char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1);
-			free(tmpStr);
-			tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0';
-			addToMap(statusInfo,"PercentCompleted",tmpStr1);
-			addToMap(statusInfo,"Message",tmpStr0);
-			setMapInMaps(m,"lenv","PercentCompleted",tmpStr1);
-			setMapInMaps(m,"lenv","Message",tmpStr0);
-			free(tmpStr0);
-			free(tmpStr1);
-		      }
-		      map* error=createMap("code","NoApplicableCode");
-		      addToMap(error,"message",_("The service failed to execute."));
-		      printExceptionReportResponseJ(m,error);
-		      return 1;
-		    }
-
-		  }else{
-		    map* error=createMap("code","NoSuchJob");
-		    addToMap(error,"message",_("The JobID seem to be running on this server but not for this process id"));
-		    printExceptionReportResponseJ(m,error);
-		    return 1;
-		  }
-		}
-	      }
-	    }else{
-	      char* tmpUrl=strstr(cgiQueryString,"/jobs/");
-	      if(tmpUrl!=NULL && strlen(tmpUrl)>6){
-		if(strncasecmp(cgiRequestMethod,"DELETE",6)==0){
-		  char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6);
-		  setMapInMaps(m,"lenv","gs_usid",jobId);
-		  setMapInMaps(m,"lenv","file.statusFile",json_getStatusFilePath(m));
-		  runDismiss(m,jobId);
-		  map* pmError=getMapFromMaps(m,"lenv","error");
-		  if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){
-		    printExceptionReportResponseJ(m,getMapFromMaps(m,"lenv","code"));
-		    return 1;
-		  }
-		  else{
-		    setMapInMaps(m,"lenv","gs_location","false");
-		    res=createStatus(m,SERVICE_DISMISSED);
-		  }
-		}else{
-		  char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6);
-		  res=printJobStatus(m,jobId);
-		  free(jobId);
-		}
-	      }
-	    }
-	  }else{
-	    /* - /jobs url */
-	    if(strcasecmp(cgiRequestMethod,"get")==0){
-	      /* - /jobs List (GET) */
-	      res=printJobList(m);
-	    }else if(strcasecmp(cgiRequestMethod,"post")==0){
-	      /* - /jobs Execution (POST) */
-	      eres = SERVICE_STARTED;
-	      initAllEnvironment(m,request_inputs,ntmp,"jrequest");
-	      map* req=getMapFromMaps(m,"renv","jrequest");
-	      json_object *jobj = NULL;
-	      const char *mystring = NULL;
-	      int slen = 0;
-	      enum json_tokener_error jerr;
-	      struct json_tokener* tok=json_tokener_new();
-	      do {
-		mystring = req->value;  // get JSON string, e.g. read from file, etc...
-		slen = strlen(mystring);
-		jobj = json_tokener_parse_ex(tok, mystring, slen);
-	      } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue);
-	      if (jerr != json_tokener_success) {
-		map* pamError=createMap("code","InvalidParameterValue");
-		const char* pcTmpErr=json_tokener_error_desc(jerr);
-		const char* pccErr=_("ZOO-Kernel cannot parse your POST data: %s");
-		char* pacMessage=(char*)malloc((strlen(pcTmpErr)+strlen(pccErr)+1)*sizeof(char));
-		sprintf(pacMessage,pccErr,pcTmpErr);
-		addToMap(pamError,"message",pacMessage);
-		printExceptionReportResponseJ(m,pamError);
-		fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr));
-		return 1;
-	      }
-	      if (tok->char_offset < slen){
-		map* pamError=createMap("code","InvalidParameterValue");
-		const char* pcTmpErr="None";
-		const char* pccErr=_("ZOO-Kernel cannot parse your POST data: %s");
-		char* pacMessage=(char*)malloc((strlen(pcTmpErr)+strlen(pccErr)+1)*sizeof(char));
-		sprintf(pacMessage,pccErr,pcTmpErr);
-		addToMap(pamError,"message",pacMessage);
-		printExceptionReportResponseJ(m,pamError);
-		fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr));
-		return 1;
-	      }
-	      //maps* inputs_real_format=NULL, *outputs_real_format= NULL;
-	      parseJRequest(m,s1,jobj,request_inputs,&request_input_real_format,&request_output_real_format);
-	      map* preference=getMapFromMaps(m,"renv","HTTP_PREFER");
-	      map* mode=getMap(request_inputs,"mode");
-	      if((preference!=NULL && strcasecmp(preference->value,"respond-async")==0) ||
-		 (mode!=NULL && strncasecmp(mode->value,"async",5)==0)) {
-		int pid;
-#ifdef DEBUG
-		fprintf (stderr, "\nPID : %d\n", cpid);
-#endif
-#ifndef WIN32
-		pid = fork ();
-#else
-		if (cgiSid == NULL)
-		  {
-		    createProcess (m, request_inputs, s1, NULL, cpid,
-				   request_input_real_format,
-				   request_output_real_format);
-		    pid = cpid;
-		  }
-		else
-		  {
-		    pid = 0;
-		    cpid = atoi (cgiSid);
-		    updateStatus(m,0,_("Initializing"));
-		  }
-#endif
-		if (pid > 0)
-		  {
-		    //
-		    // dady :
-		    // set status to SERVICE_ACCEPTED
-		    //
-#ifdef DEBUG
-		    fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid,
-			     zGetpid ());
-#endif
-		    eres = SERVICE_ACCEPTED;
-		    createStatusFile(m,eres);
-		    //invokeBasicCallback(m,SERVICE_ACCEPTED);
-		    printHeaders(m);
-		    printf("Status: 201 Created \r\n\r\n");
-		    return 1;
-		  }
-		else if (pid == 0)
-		  {
-		    eres = SERVICE_STARTED;
-		    //
-		    // son : have to close the stdout, stdin and stderr to let the parent
-		    // process answer to http client.
-		    //
-		    map* oid = getMapFromMaps (m, "lenv", "oIdentifier");
-		    map* usid = getMapFromMaps (m, "lenv", "uusid");
-		    map* tmpm = getMapFromMaps (m, "lenv", "osid");
-		    int cpid = atoi (tmpm->value);
-		    pid=cpid;
-		    r_inputs = getMapFromMaps (m, "main", "tmpPath");
-		    setMapInMaps (m, "lenv", "async","true");
-		    map* r_inputs1 = createMap("ServiceName", s1->name);
-		    // Create the filename for the result file (.res)
-		    fbkpres =
-		      (char *)
-		      malloc ((strlen (r_inputs->value) +
-			       strlen (usid->value) + 7) * sizeof (char));                    
-		    sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value);
-		    bmap = createMaps("status");
-		    bmap->content=createMap("usid",usid->value);
-		    addToMap(bmap->content,"sid",tmpm->value);
-		    addIntToMap(bmap->content,"pid",zGetpid());
+
 	  
-		    // Create PID file referencing the OS process identifier
-		    fbkpid =
-		      (char *)
-		      malloc ((strlen (r_inputs->value) +
-			       strlen (usid->value) + 7) * sizeof (char));
-		    sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value);
-		    setMapInMaps (m, "lenv", "file.pid", fbkpid);
-
-		    f0 = freopen (fbkpid, "w+",stdout);
-		    printf("%d",zGetpid());
-		    fflush(stdout);
-
-		    // Create SID file referencing the semaphore name
-		    fbkp =
-		      (char *)
-		      malloc ((strlen (r_inputs->value) + strlen (oid->value) +
-			       strlen (usid->value) + 7) * sizeof (char));
-		    sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value);
-		    setMapInMaps (m, "lenv", "file.sid", fbkp);
-		    FILE* f2 = freopen (fbkp, "w+",stdout);
-		    printf("%s",tmpm->value);
-		    fflush(f2);
-		    free(fbkp);
-
-		    fbkp =
-		      (char *)
-		      malloc ((strlen (r_inputs->value) + strlen (oid->value) +
-			       strlen (usid->value) + 7) * sizeof (char));
-		    sprintf (fbkp, "%s/%s_%s.json", r_inputs->value, oid->value,
-			     usid->value);
-		    setMapInMaps (m, "lenv", "file.responseInit", fbkp);
-		    flog =
-		      (char *)
-		      malloc ((strlen (r_inputs->value) + strlen (oid->value) +
-			       strlen (usid->value) + 13) * sizeof (char));
-		    sprintf (flog, "%s/%s_%s_error.log", r_inputs->value,
-			     oid->value, usid->value);
-		    setMapInMaps (m, "lenv", "file.log", flog);
-#ifdef DEBUG
-		    fprintf (stderr, "RUN IN BACKGROUND MODE \n");
-		    fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,
-			     zGetpid ());
-		    fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);
-#endif
-		    freopen (flog, "w+", stderr);
-		    fflush (stderr);
-		    f0 = freopen (fbkp, "w+", stdout);
-		    rewind (stdout);
-#ifndef WIN32
-		    fclose (stdin);
-#endif
-#ifdef RELY_ON_DB
-		    init_sql(m);
-		    recordServiceStatus(m);
-#endif
-#ifdef USE_CALLBACK
-		    invokeCallback(m,NULL,NULL,0,0);
-#endif
-		    invokeBasicCallback(m,SERVICE_STARTED);
-		    createStatusFile(m,SERVICE_STARTED);
-		    fbkp1 =
-		      (char *)
-		      malloc ((strlen (r_inputs->value) + strlen (oid->value) +
-			       strlen (usid->value) + 15) * sizeof (char));
-		    sprintf (fbkp1, "%s/%s_final_%s.json", r_inputs->value,
-			     oid->value, usid->value);
-		    setMapInMaps (m, "lenv", "file.responseFinal", fbkp1);
-
-		    f1 = freopen (fbkp1, "w+", stdout);
-
-		    map* serviceTypeMap=getMap(s1->content,"serviceType");
-		    if(serviceTypeMap!=NULL)
-		      setMapInMaps (m, "lenv", "serviceType", serviceTypeMap->value);
-
-		    char *flenv =
-		      (char *)
-		      malloc ((strlen (r_inputs->value) + 
-			       strlen (usid->value) + 12) * sizeof (char));
-		    sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value);
-		    maps* lenvMaps=getMaps(m,"lenv");
-		    dumpMapsToFile(lenvMaps,flenv,1);
-		    free(flenv);
-
-		    map* testMap=getMapFromMaps(m,"main","memory");
-		    loadHttpRequests(m,request_input_real_format);
-
-		    if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,NULL)<0)
-		      return -1;
-		    loadServiceAndRun (&m, s1, request_inputs,
-				       &request_input_real_format,
-				       &request_output_real_format, &eres);
-		    setMapInMaps(m,"lenv","force","true");
-		    createStatusFile(m,eres);
-		    setMapInMaps(m,"lenv","force","false");
-		    setMapInMaps(m,"lenv","no-headers","true");
-		    fflush(stdout);
-		    rewind(stdout);
-		    res=printJResult(m,s1,request_output_real_format,eres);
-		    const char* jsonStr0=json_object_to_json_string_ext(res,JSON_C_TO_STRING_PLAIN);
-		    if(getMapFromMaps(m,"lenv","jsonStr")==NULL)
-		      setMapInMaps(m,"lenv","jsonStr",jsonStr0);
-		    invokeBasicCallback(m,eres);
-		  }
-	      }else{
-		loadHttpRequests(m,request_input_real_format);
-		if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,NULL)<0)
-		  return -1;
-		loadServiceAndRun (&m,s1,request_inputs,
-				   &request_input_real_format,
-				   &request_output_real_format,&eres);
-		res=printJResult(m,s1,request_output_real_format,eres);
-	      }
-
-	    
-	    }//else error
-	    
-	  }
 	}
+
     }
     map* pmHasPrinted=getMapFromMaps(m,"lenv","hasPrinted");
@@ -2910,6 +3028,12 @@
     }
     s1 = NULL;
- 
+
     r_inputs = getMap (request_inputs, "Identifier");
+
+    fetchService(zooRegistry,m,&s1,request_inputs,ntmp,r_inputs->value,printExceptionReportResponse);
+    /*
+    //*****************
+    // Fetch S1
+    //*****************
     map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value); 
     if (import != NULL && import->value != NULL) { 
@@ -2959,5 +3083,5 @@
 	free(zooRegistry);
       }
-    }else /* Not found in MetaDB */{
+    }else /* Not found in MetaDB /{
 #endif
       s1 = createService();
@@ -3011,4 +3135,8 @@
     }
 #endif
+    //*****************
+    // End Fetch S1
+    //*****************
+*/
   
 #ifdef DEBUG
Index: trunk/zoo-project/zoo-services/utils/open-api/static/openapi.js
===================================================================
--- trunk/zoo-project/zoo-services/utils/open-api/static/openapi.js	(revision 984)
+++ trunk/zoo-project/zoo-services/utils/open-api/static/openapi.js	(revision 985)
@@ -37,4 +37,5 @@
 function loadRequest(){
     var requestObject={
+	"id": System["JSON_STR"]["id"],
         "inputs":{},
         "outputs":{},
@@ -62,10 +63,10 @@
 		    if($('input[name="oapi_ioAsArray"]').val()=="true"){
 			cInput["input"]["format"]={
-			    "mimeType": $(this).parent().prev().find("select").val()
+			    "mediaType": $(this).parent().prev().find("select").val()
 			};
 			cInput["input"]["href"]=$(this).val();
 		    }else{
 			cInput["format"]={
-			    "mimeType": $(this).parent().prev().find("select").val()
+			    "mediaType": $(this).parent().prev().find("select").val()
 			};
 			cInput["href"]=$(this).val();
@@ -115,5 +116,5 @@
 	    var selector="select[name='format_"+cName+"']";
 	    cOutput["format"]={
-		"mimeType": $(selector).val()
+		"mediaType": $(selector).val()
 	    };
         }
Index: trunk/zoo-project/zoo-services/utils/open-api/templates/index.html
===================================================================
--- trunk/zoo-project/zoo-services/utils/open-api/templates/index.html	(revision 984)
+++ trunk/zoo-project/zoo-services/utils/open-api/templates/index.html	(revision 985)
@@ -160,5 +160,5 @@
  #set cFormats=[]
   #for j in range(len($obj["input"]["formats"]))
-  #set $cFormats+=[$obj["input"]["formats"][$j]["mimeType"]]
+  #set $cFormats+=[$obj["input"]["formats"][$j]["mediaType"]]
   #end for
   $printControl({"title": "format","type": "input_format","name": $cName,"options":$cFormats})
@@ -272,5 +272,5 @@
 	  <input type="hidden" name="oapi_ioAsArray" value="#if "io_as_array" in $openapi["openapi"]#$openapi["openapi"]["io_as_array"]#else#false#end if#" />
 	  <input type="hidden" name="oapi_wsUrl" value="$openapi["openapi"]["wsurl"]" />
-	  <input type="hidden" name="oapi_jobUrl" value="$openapi["openapi"]["rootUrl"]$(currentUrl)/jobs" />
+	  <input type="hidden" name="oapi_jobUrl" value="$openapi["openapi"]["rootUrl"]/jobs" />
 	  <input type="hidden" name="oapi_reqID" value="$cid" />
 	  <h3>Inputs</h3>
@@ -291,5 +291,5 @@
 	    #if "formats" in $cOutput["output"]
 	    #for j in range(len($cOutput["output"]["formats"]))
-	    #set cFormats+=[$cOutput["output"]["formats"][$j]["mimeType"]]
+	    #set cFormats+=[$cOutput["output"]["formats"][$j]["mediaType"]]
 	    #end for
 	    #end if
@@ -424,5 +424,5 @@
 	  * Jobs list
 	  *#
-	  #set cValue=$values[$i]["infos"]
+	  #set cValue=$values[$i]
 	  <th scope="row">
 	    #if "status" in $cValue and $cValue["status"]=="successful"
@@ -526,5 +526,5 @@
       <hr>
       <address>$openapi["openapi"]["rootUrl"]$(currentUrl).html</address>
-      <!-- hhmts start -->Last modified: Mon Mar  1 17:01:50 CET 2021 <!-- hhmts end -->
+      <!-- hhmts start -->Last modified: Thu Mar  4 10:51:46 CET 2021 <!-- hhmts end -->
     </main>
 #if $currentKey=="root"
