没有为响应类型[类java.io.InputStream]和内容类型[application / octet-stream]找到合适的HttpMessageConverter

时间:2015-05-12 13:00:16

标签: java spring rest

我想从我的程序中调用一个webservice,它接受字符串数据并返回inputstream。但是当我编写了客户端代码时,我发现响应类型HttpMessageConverter和内容类型class java.io.InputStream找不到合适的application/octet-stream。所以请帮帮我。

这是我的客户代码

public InputStream zipFolderWithSubsequestFolder(String folderToBeZipped, String transactionId) {

    LOGGER.debug("DataShareServiceClient :: zipFolder() : Calling  zipFolderWithSubsequestFolder Service -> folderToBeZipped: "
                + folderToBeZipped);
    String header = getServiceName();

    // RestTemplate restTemplate = new RestTemplate();
    url = url + "/" + "rest" + "/"
            + "DataShareService" + "/"
            + "zipFolderWithSubsequestFolder";


    RestTemplate restTemplate = new RestTemplate();

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM));
    restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
    restTemplate.getMessageConverters().add(new StringHttpMessageConverter());


    HttpEntity<String> requestEntity = new HttpEntity<String>(folderToBeZipped, headers);

    InputStream response = restTemplate.postForObject(url, requestEntity, InputStream.class);
    // Make the HTTP POST request, marshaling the request to JSON, and the response to a String
    //ResponseEntity<InputStream> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, InputStream.class);
    //InputStream result = response.getBody();
    return response;

}

0 个答案:

没有答案