【发布时间】:2020-04-21 14:56:55
【问题描述】:
我一直在尝试使用 restful 网络服务来代替传统的肥皂网络服务,而不改变请求的用户部分。我想知道这是否可以实现。以下是演示该问题的示例代码:
肥皂请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sch="https://www.flopradalley.com/xml/school">
<soapenv:Header/>
<soapenv:Body>
<sch:StudentDetailsRequest>
<sch:name>Arun</sch:name>
</sch:StudentDetailsRequest>
</soapenv:Body>
</soapenv:Envelope>
这是我的休息控制器,它应该能够响应来自 SoapUI 的请求:
@RestController
@RequestMapping(value = "/restservice")
public class KenRestController {
@RequestMapping(value = "/details", method = RequestMethod.POST,
produces = MediaType.TEXT_XML_VALUE, consumes = MediaType.TEXT_XML_VALUE
)
public StudentDetailsResponse execute(HttpServletRequest request)
{
StudentDetailsRequest objectFromBody = null;// unmarshall the object from soap request and store it here
StringBuffer sb = new StringBuffer();
try {
BufferedReader reader = request.getReader();
String lineStr = null;
while ((lineStr = reader.readLine()) != null) {
sb.append(lineStr);
}catch(IOException ex) {
ex.printStackTrace();
}
/* other code */
return ---;
}
}
我只能将soap请求作为文本获取并将其存储在字符串缓冲区中。我知道如果可以使用休息来处理肥皂请求,这不是远程应该完成的方式。我知道rest是一种架构,与soap有很大的不同,看起来至少没有直接的方法可以使用rest来处理soap请求。
除了这个示例代码,我应该能够从请求中提取 SoapMessage、MessageContext、Soapheader、SoapBody。这让我想到了最初的问题,这是否可能?
【问题讨论】:
标签: java spring rest web-services soap