Project

General

Profile

« Previous | Next » 

Revision 61031

REST plugin accepts optional Request Headers parameters as json map, e.g. {Accept:application/json}. This is useful to support PostgREST endpoints: they need a param in the header to return proper json. request headers must also be exploited for the pagination (not implemented in this commit). More details on PostgREST at https://postgrest.org/en/stable/api.html.
This commit also include minor refactoring

View differences:

RestCollectorPlugin.java
3 3
 */
4 4
package eu.dnetlib.data.collector.plugins.rest;
5 5

  
6
import com.google.gson.Gson;
6 7
import eu.dnetlib.data.collector.plugin.AbstractCollectorPlugin;
7 8
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
8 9
import eu.dnetlib.data.collector.rmi.InterfaceDescriptor;
9 10
import org.apache.commons.lang3.StringUtils;
11
import org.json.JSONObject;
10 12

  
13
import java.util.Map;
14

  
11 15
/**
12 16
 * @author 	js, Andreas Czerniak
13 17
 * @date 	2020-04-09
......
31 35
		final String entityXpath = ifDescriptor.getParams().get("entityXpath");
32 36
		final String authMethod = ifDescriptor.getParams().get("authMethod");
33 37
		final String authToken = ifDescriptor.getParams().get("authToken");
38
		final String requestHeaderMap = ifDescriptor.getParams().get("requestHeaderMap");
39
		Gson gson = new Gson();
40
		Map<String, String> requestHeaders = gson.fromJson(requestHeaderMap, Map.class);
34 41

  
42

  
35 43
		if (StringUtils.isBlank(baseUrl)) {throw new CollectorServiceException("Param 'baseUrl' is null or empty");}
36 44
		if (StringUtils.isBlank(resumptionType)) {throw new CollectorServiceException("Param 'resumptionType' is null or empty");}
37 45
		if (StringUtils.isBlank(resumptionParam)) {throw new CollectorServiceException("Param 'resumptionParam' is null or empty");}
......
64 72
				entityXpath,
65 73
				authMethod,
66 74
				authToken,
67
				resultOutputFormat);
75
				resultOutputFormat, requestHeaders);
68 76
	}
69 77

  
70 78
}

Also available in: Unified diff