Index: modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/ResponseFormatter.java
===================================================================
--- modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/ResponseFormatter.java	(revision 44733)
+++ modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/ResponseFormatter.java	(nonexistent)
@@ -1,42 +0,0 @@
-package eu.dnetlib.data.search.web.api;
-
-import org.apache.log4j.Logger;
-
-/**
- * Created by kiatrop on 28/9/2016.
- */
-public class ResponseFormatter {
-
-    private static final Logger logger = Logger.getLogger(ResponseFormatter.class);
-
-    private static final String error500Message = "{ \"status\" : \"fail\", \"code\" : \"500\", \"message\" : \"%s\", \"description\" : \"%s\" }";
-
-    private static final String metaBasic = "{\"status\": \"success\", \"code\":\"200\" }"; //TODO add self
-    private static final String countSearch = "{\"status\": \"success\", \"code\":\"200\", \"query\":\"%s\", \"total\":\"%s\"}"; //only count
-    private static final String metaSearch = "{\"status\": \"success\", \"code\":\"200\", \"query\":\"%s\", \"total\":\"%s\", \"page\":\"%s\", \"size\":\"%s\", \"_links\": %s}";
-
-    private static final String _links = "{\"first\": {\"href\":\"%s\"}, " +
-            " \"last\": {\"href\":\"%s\"}, " +
-            " \"previous\": {\"href\":\"%s\"}, " +
-            "  \"next\": {\"href\":\"%s\"}, " +
-            "  \"self\": {\"href\":\"%s\"}}";
-
-    private static final String _self = "{\"self\": {\"href\":\"%s\"}}";
-
-    private static final String result = "{%s}";
-
-    private static final String resource = "\"%s\": {%s}";
-
-    private static final String resources = "\"%s\": [{%s}]";
-
-    private static final String response = "{\"meta\": %s, \"results\" : [%s] %s %s}";
-
-    private static final String singleResponse = "{\"meta\": %s, %s }";
-
-
-    public static String compose500Message(String message, String description) { return String.format(error500Message, message, description); }
-
-    public static String createCountMeta(String query, int total) {
-        return String.format(countSearch, query, total);
-    }
-}
Index: modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/utils/vocabulary/VocabularyFactory.java
===================================================================
--- modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/utils/vocabulary/VocabularyFactory.java	(revision 44733)
+++ modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/utils/vocabulary/VocabularyFactory.java	(revision 44734)
@@ -8,6 +8,6 @@
 	 * @param vocabularyName
 	 * @return the path of the vocabulary
 	 */
-	public String createXmlVocabulary(String vocabularyName);
+	String createXmlVocabulary(String vocabularyName);
 
 }
Index: modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/utils/vocabulary/VocabularyManager.java
===================================================================
--- modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/utils/vocabulary/VocabularyManager.java	(revision 44733)
+++ modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/utils/vocabulary/VocabularyManager.java	(revision 44734)
@@ -1,11 +1,11 @@
 package eu.dnetlib.data.search.utils.vocabulary;
 
+import eu.dnetlib.domain.enabling.Vocabulary;
+
 import java.util.List;
 import java.util.Locale;
 import java.util.Set;
 
-import eu.dnetlib.domain.enabling.Vocabulary;
-
 public interface VocabularyManager {
 	
 	/**
@@ -14,9 +14,9 @@
 	 * @param locale
 	 * @return
 	 */
-	public Vocabulary getVocabulary(String vocabularyName, Locale locale);
-	public Vocabulary getVocabulary(String vocabularyName, Locale locale, boolean loadanyway);
-	public String translate(String n, String l, String e, String d);
-	public Set<String> getVocabularyNames();
-	public List<Locale> getLocales();
+	Vocabulary getVocabulary(String vocabularyName, Locale locale);
+	Vocabulary getVocabulary(String vocabularyName, Locale locale, boolean loadanyway);
+	String translate(String n, String l, String e, String d);
+	Set<String> getVocabularyNames();
+	List<Locale> getLocales();
 }
Index: modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/utils/vocabulary/VocabularyManagerImpl.java
===================================================================
--- modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/utils/vocabulary/VocabularyManagerImpl.java	(revision 44733)
+++ modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/utils/vocabulary/VocabularyManagerImpl.java	(revision 44734)
@@ -62,7 +62,7 @@
 		}
 		
 		String term = vocabulary.getEnglishName(encoding);
-		if(term != null && term != "") {
+		if(term != null && !term.trim().isEmpty()) {
 			return term;
 		}
 		
@@ -73,7 +73,7 @@
 		}
 		term = vocabulary.getEnglishName(encoding);
 
-		if(term != null && term != ""){
+		if(term != null && !term.trim().isEmpty()) {
 			return term;
 		}
 			
Index: modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/Transformer.java
===================================================================
--- modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/Transformer.java	(revision 44733)
+++ modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/Transformer.java	(revision 44734)
@@ -8,5 +8,5 @@
 	 * @param input The string to be transformed
 	 * @return The string after the transformation 
 	 */
-	public abstract String transform(String input) throws TransformerException;
+	String transform(String input) throws TransformerException;
 }
Index: modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/formatter/Formatter.java
===================================================================
--- modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/formatter/Formatter.java	(revision 44733)
+++ modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/formatter/Formatter.java	(revision 44734)
@@ -3,7 +3,5 @@
 import eu.dnetlib.domain.data.SearchResult;
 
 public interface Formatter {
-	
-	public abstract String format(SearchResult result) throws Exception;
-
+	String format(SearchResult result) throws Exception;
 }
Index: modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/formatter/FormatterFactory.java
===================================================================
--- modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/formatter/FormatterFactory.java	(revision 44733)
+++ modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/formatter/FormatterFactory.java	(revision 44734)
@@ -1,7 +1,5 @@
 package eu.dnetlib.data.search.transform.formatter;
 
 public interface FormatterFactory {
-
-	public abstract Formatter getFormatter(String formatterName);
-	
+	Formatter getFormatter(String formatterName);
 }
Index: modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/config/ConfigurationFactory.java
===================================================================
--- modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/config/ConfigurationFactory.java	(revision 44733)
+++ modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/config/ConfigurationFactory.java	(revision 44734)
@@ -5,7 +5,6 @@
 import eu.dnetlib.data.search.utils.vocabulary.IndexVocabulary;
 import eu.dnetlib.data.search.utils.vocabulary.LocalVocabulary;
 import eu.dnetlib.data.search.utils.vocabulary.Vocabulary;
-import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.log4j.Logger;
 import org.springframework.core.io.Resource;
@@ -14,7 +13,10 @@
 import org.xml.sax.InputSource;
 
 import javax.xml.xpath.*;
-import java.io.*;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
@@ -67,7 +69,7 @@
 		XPathFactory factory = XPathFactory.newInstance();
 		XPath xPath = factory.newXPath();
 		  
-		try {
+		/*try {
 			//clean vocabularies folder
 			FileUtils.deleteDirectory(new File(vocabulariesPath));
 			
@@ -76,7 +78,7 @@
 		
 		} finally {		
 			new File(vocabulariesPath).mkdir();
-		}
+		}*/
 		
 		try {
 			readLocales(xPath, configuration);
Index: modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/TransformerRegistry.java
===================================================================
--- modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/TransformerRegistry.java	(revision 44733)
+++ modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/TransformerRegistry.java	(revision 44734)
@@ -15,5 +15,5 @@
 	 * @param name The name of the {@link Transformer}.
 	 * @return {@link Transformer}
 	 */
-	public Transformer getTransformer(String name, Locale locale);
+	Transformer getTransformer(String name, Locale locale);
 }
Index: modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/FormatterRegistry.java
===================================================================
--- modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/FormatterRegistry.java	(revision 44733)
+++ modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/transform/FormatterRegistry.java	(revision 44734)
@@ -14,5 +14,5 @@
 	 * @param name
 	 * @return
 	 */
-	public Formatter getFormatter(String name);
+	Formatter getFormatter(String name);
 }
Index: modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/SearchApiService.java
===================================================================
--- modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/SearchApiService.java	(revision 44733)
+++ modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/SearchApiService.java	(revision 44734)
@@ -41,23 +41,9 @@
                                       @QueryParam("format") final String format,
                                       @Context final HttpServletRequest request) {
 
-        String responseType = extractResponseFormat(format);
-        if(query == null || query.isEmpty()) {
-            return Response.status(Response.Status.BAD_REQUEST).
-                    entity(APIResponseFormatter.compose400Message(responseType, "The 'query' parameter is required")).
-                    type(responseType).build();
-        }
-        
-        return getResponseByEntity(query, RequestResponseHandler.Entity.NONE, offset, limit, responseType, request, refine, fields, fieldQueries, responseType);
+        return getResponseByEntity(query, RequestResponseHandler.Entity.NONE, offset, limit, format, request, refine, fields, fieldQueries);
     }
 
-    private String extractResponseFormat(String format) {
-        if (format != null && !format.isEmpty() && format.equalsIgnoreCase("json")) {
-            return MediaType.APPLICATION_JSON;
-        }
-        return MediaType.APPLICATION_XML;
-    }
-
     @GET
     @Path("/api/publications")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@@ -69,87 +55,21 @@
                                       @QueryParam("fq") final List<String> fieldQueries,
                                       @QueryParam("format") final String format,
                                       @Context final HttpServletRequest request) {
-        String responseType = extractResponseFormat(format);
+
         String simpleQuery = buildSimpleSearchQuery(RequestResponseHandler.Entity.PUBLICATION, keywords);
-            return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.PUBLICATION, offset, limit, responseType, request, refine, fields, fieldQueries, responseType);
+        return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.PUBLICATION, offset, limit, format, request, refine, fields, fieldQueries);
 
     }
 
-    private String buildSimpleSearchQuery(RequestResponseHandler.Entity entity, String keywords) {
-        StringBuilder queryBuilder = new StringBuilder();
-        enhanceQueryWithEntityType(queryBuilder,entity);
-        enhanceQueryWithKeywords(queryBuilder, keywords);
-        return queryBuilder.toString();
-    }
-/*
-    private void enhanceQueryWithKeywords(StringBuilder queryBuilder, String keywords) {
-        queryBuilder.append(' ').append(CQLQueryGeneration.Operator.AND).append(' ').append(keywords);
-    }
 
-    private String builtFullQuery(List<String> keywords, List<String> keywordOperators, RequestResponseHandler.Entity entity, HttpServletRequest request) {
-        Map<String, String[]> parameterMap = request.getParameterMap();
-
-        Map<String, String[]> operators = new HashMap<String, String[]>();
-        Map<String, String[]> parameters = new HashMap<String, String[]>();
-        extractParameterNOperatorsValues(parameterMap, operators, parameters, entity);
-
-        return enhanceQuery(keywords, keywordOperators, operators, parameters, entity);
-    }
-
-/*    public static void buildFq(RequestResponseHandler.Entity entity, HttpServletRequest request, List<String> fields, List<FieldQuery> fieldQueries) {
-        Map<String, String[]> parameterMap = request.getParameterMap();
-
-        Map<String, String> indexParameterMap = entity.geIndexParameterMap();
-        Map<String, String> parameterOperatorMap = entity.getParameterOperatorMap();
-        //logger.debug(parameterOperatorMap.keySet());
-
-        for (String field:fields) {
-            logger.debug("field: " + field);
-            String parameter = indexParameterMap.get(field);
-            logger.debug("parameter: " + parameter);
-            if (indexParameterMap.get(field) != null  ) {
-                String[] refineValues = request.getParameterValues(parameter);
-                String operatorParameter = parameterOperatorMap.get(parameter);
-                String operatorValue = null;
-                if (operatorParameter != null && !operatorParameter.trim().isEmpty()) {
-                    operatorValue = request.getParameter(operatorParameter);
-                    if (operatorValue == null || operatorValue.trim().isEmpty()) {
-                        operatorValue = "AND";
-                    }
-                    fieldQueries.add(new FieldQuery(field, operatorValue, refineValues));
-
-                } else {
-                    //TODO throw exception?
-                }
-            }
-        }
-    }
-*/
-
-    /*
-
-    public static String createFqParameter(List<FieldQuery> fieldQueries) {
-        StringBuilder fq = new StringBuilder();
-        for (FieldQuery fieldQuery:fieldQueries) {
-            fq.append(fieldQuery.getIndexField());
-            if(fieldQuery.getValues() != null && fieldQuery.getValues().length == 0) {
-                for(int i=0; i< fieldQuery.getValues().length; i++) {
-                    fq.append(":").append(fieldQuery.getValues()[i] + " ");
-                    if(i < fieldQuery.getValues().length-1) {
-                        fq.append(" " + fieldQuery.getOperator() + " ");
-                    }
-                }
-            }
-        }
-        return fq.toString();
-    }
-*/
     @GET
     @Path("/api/publications/count")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
-    public Response fetchPublicationsCount(@QueryParam("q") String query) {
+    public Response fetchPublicationsCount(@QueryParam("q") String query,
+                                           @QueryParam("format") final String format,
+                                           @Context final HttpServletRequest request)  {
         String fullQuery = builtQueryByEntity(query, RequestResponseHandler.Entity.PUBLICATION);
-        return getCount(fullQuery);
+        return getCount(request, fullQuery, format);
     }
 
 
@@ -159,48 +79,51 @@
     public Response fetchPublicationsById(@PathParam("publicationid") String publicationid,
                                           @QueryParam("format") final String format,
                                           @Context final HttpServletRequest request) {
-        String responseType = extractResponseFormat(format);
-        return getResponseByEntityId(request, RequestResponseHandler.Entity.PUBLICATION, publicationid, responseType);
+        return getResponseByEntityId(request, RequestResponseHandler.Entity.PUBLICATION, publicationid, format);
     }
 
-/*
+
     @GET
     @Path("/api/datasets")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
-    public Response fetchDatasets(@QueryParam("q") List<String> keywords,
-                                  @QueryParam("op") final List<String> keywordOperators,
+    public Response fetchDatasets(@QueryParam("q") String keywords,
                                   @DefaultValue("1") @QueryParam("page") int offset,
                                   @DefaultValue("10") @QueryParam("size") int limit,
                                   @QueryParam("refine") @DefaultValue("false") boolean refine,
                                   @QueryParam("fields") final List<String> fields,
+                                  @QueryParam("fq") final List<String> fieldQueries,
                                   @QueryParam("format") final String format,
                                   @Context HttpServletRequest request) {
 
-        String fullQuery = builtFullQuery(keywords, keywordOperators, RequestResponseHandler.Entity.PUBLICATION, request);
-        return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.DATASET, offset, limit, format, request, refine, fields);
+        String simpleQuery = buildSimpleSearchQuery(RequestResponseHandler.Entity.DATASET, keywords);
+        return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.DATASET, offset, limit, format, request, refine, fields, fieldQueries);
     }
 
     @GET
     @Path("/api/datasets/count")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
-    public Response fetchDatesetsCount(@QueryParam("q") String query) {
+    public Response fetchDatesetsCount(@QueryParam("q") String query,
+                                       @QueryParam("format") final String format,
+                                       @Context final HttpServletRequest request)  {
         String fullQuery = builtQueryByEntity(query, RequestResponseHandler.Entity.DATASET);
-        return getCount(fullQuery);
+        return getCount(request, fullQuery, format);
     }
 
+
     @GET
     @Path("/api/datasets/{datasetid}")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
-    public Response fetchDatasets(@PathParam("datasetid") String datasetid) {
-        return getResponseByEntityId(RequestResponseHandler.Entity.DATASET, datasetid);
+    public Response fetchDatasets(@PathParam("datasetid") String datasetid,
+                                  @QueryParam("format") final String format,
+                                  @Context final HttpServletRequest request) {
+        return getResponseByEntityId(request, RequestResponseHandler.Entity.DATASET, datasetid, format);
     }
 
-
+/*
     @GET
     @Path("/api/projects")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
-    public Response fetchProjects(@QueryParam("q") List<String> keywords,
-                                  @QueryParam("op") final List<String> keywordOperators,
+    public Response fetchProjects(@QueryParam("q") String keywords,
                                   @DefaultValue("1") @QueryParam("page") final int offset,
                                   @DefaultValue("10") @QueryParam("size") final int limit,
                                   @QueryParam("refine") @DefaultValue("false") final boolean refine,
@@ -208,7 +131,7 @@
                                   @QueryParam("fields") final List<String> fields,
                                   @Context final HttpServletRequest request)  {
 
-        String fullQuery = builtFullQuery(keywords, keywordOperators, RequestResponseHandler.Entity.PROJECT, request);
+        String fullQuery = buildSimpleSearchQuery(RequestResponseHandler.Entity.PROJECT, keywords);
         return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.PROJECT, offset, limit, format, request, refine, fields);
     }
 
@@ -273,8 +196,8 @@
         return getCount(fullQuery);
     }
 
+/*
 
-
     @GET
     @Path("/api/datasources")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@@ -481,6 +404,20 @@
     }
 */
 
+    private String extractResponseFormat(String format) {
+        if (format != null && !format.isEmpty() && format.equalsIgnoreCase("json")) {
+            return MediaType.APPLICATION_JSON;
+        }
+        return MediaType.APPLICATION_XML;
+    }
+
+    private String buildSimpleSearchQuery(RequestResponseHandler.Entity entity, String keywords) {
+        StringBuilder queryBuilder = new StringBuilder();
+        enhanceQueryWithEntityType(queryBuilder,entity);
+        enhanceQueryWithKeywords(queryBuilder, keywords);
+        return queryBuilder.toString();
+    }
+
     private void enhanceQueryWithKeywords(StringBuilder queryBuilder, String keywords) {
         CQLQueryGeneration.appendKeywords(queryBuilder,keywords);
     }
@@ -521,22 +458,31 @@
         return queryBuilder.toString();
     }
 
-    private Response getCount(String query) {
+    private Response getCount(HttpServletRequest request, String query, String format) {
+        String responseType = extractResponseFormat(format);
         try {
-            SearchResult searchResult = searchService.search(query, null, Locale.getDefault().toString(), 0, 0);
-            return Response.status(Response.Status.OK).entity(ResponseFormatter.createCountMeta(query.replace("\"", "\\\""), searchResult.getTotal())).build();
+            SearchResult searchResult = searchService.newSearch(query, Locale.getDefault().toString(), null, null, 0, 0, responseType);
+            return Response.status(Response.Status.OK).entity(APIResponseFormatter.createCountMeta(request, query, searchResult.getTotal(), responseType)).type(responseType).build();
 
         } catch (SearchServiceException sse) {
-            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ResponseFormatter.compose500Message("Fail to fetch count for query " + query.replace("\"", "\\\"") + ".", sse.getMessage())).build();
+            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(APIResponseFormatter.compose500Message(responseType, "Fail to fetch count for query " + query + ".", sse.getMessage())).build();
         }
     }
 
-    private Response getResponseByEntityId(HttpServletRequest request, RequestResponseHandler.Entity entity, String entityId, String responseType) {
+    private Response getResponseByEntityId(HttpServletRequest request, RequestResponseHandler.Entity entity, String entityId, String format) {
+        String responseType = extractResponseFormat(format);
+
         try {
             StringBuilder queryBuilder = new StringBuilder();
             builtEntityIdQuery(queryBuilder, entity, entityId);
             String fullQuery = queryBuilder.toString();
 
+            if(fullQuery == null || fullQuery.isEmpty()) {
+                return Response.status(Response.Status.BAD_REQUEST).
+                        entity(APIResponseFormatter.compose400Message(format, "The 'query' parameter is required")).
+                        type(responseType).build();
+            }
+
             SearchResult searchResult = searchService.newSearch(fullQuery, Locale.getDefault().toString(), null, null, 0, 1, responseType);
 
             if (searchResult.getSearchResults() == null || searchResult.getSearchResults().isEmpty() ||
@@ -553,9 +499,17 @@
         }
     }
 
-    private Response getResponseByEntity(String fullQuery, RequestResponseHandler.Entity entity, int offset, int limit, String format, HttpServletRequest request, boolean refine, List<String> refineFields, List<String> fieldQueries, String responseType) {
+    private Response getResponseByEntity(String fullQuery, RequestResponseHandler.Entity entity, int offset, int limit, String format, HttpServletRequest request, boolean refine, List<String> refineFields, List<String> fieldQueries) {
+        String responseType = extractResponseFormat(format);
+
+        if(fullQuery == null || fullQuery.isEmpty()) {
+            return Response.status(Response.Status.BAD_REQUEST).
+                    entity(APIResponseFormatter.compose400Message(responseType, "The 'query' parameter is required")).
+                    type(responseType).build();
+        }
+
         try {
-            SearchResult solrResults = searchService.newSearch(fullQuery, Locale.getDefault().toString(), refineFields, fieldQueries, offset, limit, format);
+            SearchResult solrResults = searchService.newSearch(fullQuery, Locale.getDefault().toString(), refineFields, fieldQueries, offset, limit, responseType);
             return Response.status(Response.Status.OK).entity(APIResponseFormatter.createEntitiesResponse(request, entity, fullQuery, fieldQueries, solrResults, refine, responseType)).type(responseType).build();
 
         } catch (SearchServiceException sse) {
@@ -566,20 +520,7 @@
     }
 
 
-    /* TODO remove?
-    private Response getCountByEntity2EntityRelation(String query, RequestResponseHandler.Entity entity, String relationfield, String entityId) {
-        String fullQuery =  builtEntity2EntityRelationQuery(entity, relationfield, entityId);
 
-        try {
-            SearchResult searchResult = searchService.search(fullQuery, null, Locale.getDefault().toString(), 0, 0);
-            return Response.status(Response.Status.OK).entity(ResponseFormatter.createCountMeta(fullQuery.replace("\"", "\\\""), searchResult.getTotal())).build();
-
-        } catch (SearchServiceException sse) {
-            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ResponseFormatter.compose500Message("Fail to fetch count for query " + fullQuery.replace("\"", "\\\"") + ".", sse.getMessage())).build();
-        }
-    } */
-
-
 /*
     public static void main(String[] args) {
         String json = " {\"result\":{\"xmlns:oaf\":\"http://namespace.openaire.eu/oaf\",\"xmlns:xsi\":\"http://www.w3.o" +
Index: modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/XMLResponseFormat.java
===================================================================
--- modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/XMLResponseFormat.java	(revision 44733)
+++ modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/XMLResponseFormat.java	(revision 44734)
@@ -9,7 +9,7 @@
     public static final String error400Message = "<response><status>error</status><code>400</code><message>%s</message></response>";
     public static final String error500Message = "<response><status>fail</status><code>500</code><message>%s</message><description>%s</description></response>";
 
-    public static final String countSearch = "<response><status>success/status><code>200</code><query>%s</query><total>%s</total><links>%s</links></response>";
+    public static final String countSearch = "<response><status>success</status><code>200</code><query>%s</query><total>%s</total><links>%s</links></response>";
 
     public static final String singleValueResponse = "<response><meta>%s</meta>%s</response>";
     public static final String response = "<response><meta>%s</meta><results>%s</results>%s</response>";
Index: modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/APIResponseFormatter.java
===================================================================
--- modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/APIResponseFormatter.java	(revision 44733)
+++ modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/APIResponseFormatter.java	(revision 44734)
@@ -19,23 +19,23 @@
 
     public static String compose404Message(String type, String message) {
         if(type.equals(MediaType.APPLICATION_JSON)) {
-           return String.format(JSONResponseFormat.error404Message, message);
+           return String.format(JSONResponseFormat.error404Message, StringEscapeUtils.escapeJson(message));
         }
-        return String.format(XMLResponseFormat.error404Message, message);
+        return String.format(XMLResponseFormat.error404Message, StringEscapeUtils.escapeXml10(message));
     }
 
     public static String compose400Message(String type, String message) {
          if(type.equals(MediaType.APPLICATION_JSON)) {
-            return String.format(JSONResponseFormat.error400Message, message);
+            return String.format(JSONResponseFormat.error400Message, StringEscapeUtils.escapeJson(message));
         }
-        return String.format(XMLResponseFormat.error400Message, message);
+        return String.format(XMLResponseFormat.error400Message, StringEscapeUtils.escapeXml10(message));
     }
 
     public static String compose500Message(String type, String message, String description) {
         if(type.equals(MediaType.APPLICATION_JSON)) {
-            return String.format(JSONResponseFormat.error500Message, message, description);
+            return String.format(JSONResponseFormat.error500Message, StringEscapeUtils.escapeJson(message), StringEscapeUtils.escapeJson(description));
         }
-        return String.format(XMLResponseFormat.error500Message, message, description);
+        return String.format(XMLResponseFormat.error500Message, StringEscapeUtils.escapeXml10(message), StringEscapeUtils.escapeXml10(description));
     }
 
     public static String createCountMeta(HttpServletRequest request, String query, int total, String type) {
@@ -42,10 +42,10 @@
         String selfPageUrl = pageUrlCreation(request);
 
         if  (type.equals(MediaType.APPLICATION_JSON)) {
-            return String.format(JSONResponseFormat.countSearch, StringEscapeUtils.escapeJson(query), formatSelfPaging(type, selfPageUrl));
+            return String.format(JSONResponseFormat.countSearch, StringEscapeUtils.escapeJson(query), total, formatSelfPaging(type, selfPageUrl));
         }
 
-        return String.format(XMLResponseFormat.countSearch, StringEscapeUtils.escapeXml10(query), formatSelfPaging(type, selfPageUrl));
+        return String.format(XMLResponseFormat.countSearch, StringEscapeUtils.escapeXml10(query), total, formatSelfPaging(type, selfPageUrl));
     }
 
     public static String createEntityResponse(HttpServletRequest request, RequestResponseHandler.Entity entityType, String entity, String type) {
