我正在开发一个桥接应用程序,该应用程序将soap请求发送到Web服务Restful,并在soap中返回响应。
Restful Webservice的响应类似于
[
{
"agenzia": "string",
"allegato": [
{
"fileName": "string",
"body": "string",
"mimeType": "string"
}
]
}
]
我使用spring-boot框架来开发这个。我已经从XSD生成了java文件(获得了"RetrieveRichiesta"类(,然后我创建了一个DTO类("Retrieve Richiesta ResponseDto"类(来处理来自Web服务的响应。API类为
public RetrieveRichiestaResponse RetrieveRichiesta(RetrieveRichiestaRequest request){
//LOGGER.info("Servizio richiamato "+ url + "api/incident/retrieveincident");
// Call the API
RestTemplate restTemplate = new RestTemplate();
// Add Interceptor
restTemplate.setInterceptors(Collections.singletonList(new RequestResponseLoggingInterceptor()) );
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
final String uri = url + "/api/incident/retrieveincident";
Map<String,String> input = new HashMap<>();
input.put("id_CRM", request.getIdCRM());
input.put("tipo", request.getTipo());
input.put("fonte", request.getFonte());
HttpEntity<?> entity = new HttpEntity<>(input,headers);
RetrieveRichiestaResponseDto result = restTemplate.postForObject(
uri,
entity,
RetrieveRichiestaResponseDto.class);
// Transform response RetrieveRichiestaRequestDto to RetrieveRichiestaRequest
RetrieveRichiesta RetrieveRichiesta = new RetrieveRichiesta();
RetrieveRichiesta.setAgenzia(result.getAgenzia());
RetrieveRichiesta.setAllegato(result.getAllegatoDTO());
RetrieveRichiestaResponse response = new RetrieveRichiestaResponse();
LOGGER.info("Risposta" + response.toString());
response.setRetrieveRichiesta(RetrieveRichiesta);
return response;
}
当我通过SOAP发送请求时,我得到了这个错误作为响应
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">Error while extracting response for type [class eu.ima.app.domain.RetrieveRichiestaDto] and content type [application/json;charset=utf-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `eu.ima.app.domain.RetrieveRichiestaDto` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `eu.ima.app.domain.RetrieveRichiestaDto` out of START_ARRAY token
at [Source: (PushbackInputStream); line: 1, column: 1]</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我认为是因为它想要一个像这样的JSON对象,而不是像这样的
我也试着像这个一样更改代码
......
HttpEntity<?> entity = new HttpEntity<>(input,headers);
ResponseEntity<List<RetrieveRichiestaResponseDto>> result = restTemplate.exchange(
uri,
HttpMethod.POST,
entity,
new ParameterizedTypeReference<List<RetrieveRichiestaResponseDto>>() {});
List<RetrieveRichiestaResponseDto> rates = result.getBody();
//LOGGER.info(rates.toString());
for (int i = 0; i < rates.size(); i++) {
System.out.println(rates.get(i));
}
......
以列表形式获取,但如何将其作为列表传递给RetrieveRichiesta?错误在哪里?谢谢你的帮助!!
好的,我可以用访问列表
rates.get(0).getAgenzia
Etc.
但是如果我想像这个一样使用restTemplate.postForObject
ResponseEntity<List<RetrieveRichiestaResponseDto>> result = restTemplate.postForObject(
uri,
entity,
new ParameterizedTypeReference<List<RetrieveRichiestaResponseDto>>() {});
为什么它给我
the method is not applicable for the arguments....
在这方面需要帮助!