Java Client for HighChart Export server REST service



我一直在尝试创建一个小型的java客户端来调用Highchart Export服务器来获取pdf/jpeg等,但是在客户端使用Spring的RestTemplate并不成功> RestTemplate restTemplate = new org.springframework.web.client.RestTemplate()。我尝试了发布/获取/交换方法。但无法将所需的方法参数传递给服务器端...所需的方法在没有参数的情况下被调用,并返回其测试 JSP 页。

高图表导出服务器代码 =>

@Controller
@RequestMapping("/")
public class ExportController extends HttpServlet {
...
...
    @RequestMapping(method = {RequestMethod.POST, RequestMethod.GET})
    public HttpEntity<byte[]> exporter(
        @RequestParam(value = "svg", required = false) String svg,
        @RequestParam(value = "type", required = false) String type,
        @RequestParam(value = "filename", required = false) String filename,
        @RequestParam(value = "width", required = false) String width,
        @RequestParam(value = "scale", required = false) String scale,
        @RequestParam(value = "options", required = false) String options,
        @RequestParam(value = "globaloptions", required = false) String globalOptions,
        @RequestParam(value = "constr", required = false) String constructor,
        @RequestParam(value = "callback", required = false) String callback,
        @RequestParam(value = "callbackHC", required = false) String callbackHC,
        @RequestParam(value = "async", required = false, defaultValue = "false")  Boolean async,
        @RequestParam(value = "jsonp", required = false, defaultValue = "false") Boolean jsonp,
        HttpServletRequest request,
        HttpSession session) throws ServletException, InterruptedException, SVGConverterException, NoSuchElementException, PoolException, TimeoutException, IOException, ZeroRequestParameterException {
...
}
}

我应该调用 RestTemplate 中的什么方法以及如何从客户端传递参数,例如 JSON 格式的选项、类型等,以便使用适当的参数执行上述服务方法?感谢您的帮助。

我在org.springframework.util.LinkedMultiValueMap对象中传递值后使其工作,例如

MultiValueMap<String, String> prms = new LinkedMultiValueMap<String, String>(); 
prms.add("param1", "value1"); 
prms.add("param2", "value2");

然后打电话..

RestTemplate restTemplate = new RestTemplate();
byte[] b = restTemplate.postForObject("http://****/", prms, byte[].class);

最新更新