我有一个端点,该端点检查数据库中是否存在标识符并返回状态。一个USSD API,它将调用此端点。当我使用不存在的标识符(EcNumber)发出请求时,响应将按预期返回消息消息。我需要使用isEmpty()/ null中的任何一个来实现相同的目的:
ClientEndpoint.java
@Endpoint
public class ClientEndpoint {
private static final String NAMESPACE_URI = "http://www.onewallet.org/webservices/disburse";
@Autowired
private IClientService clientService;
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getClientByEcNumRequest")
@ResponsePayload
public GetClienttByEcNumResponse getClient(@RequestPayload GetClientByEcNumRequest request) {
GetClienttByEcNumResponse response = new GetClienttByEcNumResponse();
ServiceStatus serviceStatus = new ServiceStatus();
ClientInfo clientInfo = new ClientInfo();
if ( clientInfo==null || clientInfo.getEcNumber()==null ){
serviceStatus.setMessage("EC# not registered with MCP");
} else {
BeanUtils.copyProperties(clientService.getClientByEcNumber(request.getEcNumber() ), clientInfo);
serviceStatus.setMessage("Welcome to MCP MobileLoans");
}
response.setServiceStatus(serviceStatus);
return response;
当我通过下面的请求以提供有效的EcNumber时:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dis="http://www.onewallet.org/webservices/disburse">
<soapenv:Header/>
<soapenv:Body>
<dis:getClientByEcNumRequest>
<dis:ecNumber>5501900T</dis:ecNumber>
</dis:getClientByEcNumRequest>
</soapenv:Body>
</soapenv:Envelope>
我得到回应:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns2:getClienttByEcNumResponse xmlns:ns2="http://www.onewallet.org/webservices/disburse">
<ns2:serviceStatus>
<ns2:message>EC# not registered with MCP</ns2:message>
</ns2:serviceStatus>
</ns2:getClienttByEcNumResponse>
答案 0 :(得分:0)
知道了。我为检查传递了不正确的对象。应该使用 entity 实例而不是 complexType 的实例(来自架构定义):
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getClientByEcNumRequest")
@ResponsePayload
public GetClienttByEcNumResponse getClient(@RequestPayload GetClientByEcNumRequest request) {
GetClienttByEcNumResponse response = new GetClienttByEcNumResponse();
ServiceStatus serviceStatus = new ServiceStatus();
**Client client=clientService.getClientByEcNumber(request.getEcNumber));**
ClientInfo clientInfo = new ClientInfo();
if ( client=null){
serviceStatus.setMessage("EC# not registered with MCP");
} else {
BeanUtils.copyProperties(clientService.getClientByEcNumber(request.getEcNumber() ), clientInfo);
serviceStatus.setMessage("Welcome to MCP MobileLoans");
}
response.setServiceStatus(serviceStatus);
response.setClientInfo(clientInfo)
return response;