我正在做一个与支付相关的Restful服务。当我尝试调用API时,发生了一个名为java.lang.IllegalArgumentException
map的异常,其中orderId
没有值
作为背景,我创建了HttpHeaders和LinkedMultiValueMap,并将值放入其中并调用API。
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
LinkedMultiValueMap<String, String> uriVars = new LinkedMultiValueMap<>();
uriVars.add("merchantId", _paymentInstrument.getAcquirerMid());
uriVars.add("orderId", _paymentInstrument.getOrderId().toString());
uriVars.add("transactionId", _paymentInstrument.getTransactionId().toString());
VoidRequest voidRequest = createVoidRequest(_paymentInstrument.getTargetTransactionId());
HttpEntity<VoidRequest> requestEntity = new HttpEntity<>(voidRequest, headers);
TransactionResponse voidResponse = null;
try {
ResponseEntity<TransactionResponse> responseEntity = restTemplate.exchange(getEnvironment().getProperty(IPG_TRANSACTION_URL),
HttpMethod.PUT, requestEntity, TransactionResponse.class, uriVars);
voidResponse = responseEntity.getBody();
log.info(LogSupport.PG_LOGS_CARGILLS_VOID_TRX + "[AcquirerMID ={};TransactionId ={};ResponseCode={};ResponseText={}]", _paymentInstrument.getAcquirerMid(),
_paymentInstrument.getTransactionId(), voidResponse.getResponse().getAcquirerCode(), voidResponse.getResponse().getAcquirerMessage());
} catch (ResourceAccessException rae) {
throw rae;
} catch (Exception e) {
voidResponse = new TransactionResponse();
voidResponse.setResult("ERROR");
ErrorResponse error = new ErrorResponse();
error.setCause("EXCEPTION");
error.setExplanation(e.getMessage());
}
这会发生一个异常java.lang.IllegalArgumentExceptionMap没有“orderId”的值。
3条答案
按热度按时间qc6wkl3g1#
q43xntqr2#
我也面临着同样的问题。在我例子中,如果我像这样给一个变量分配一个键值对:
别这样
int getString(“String”,String);
那样做
“); return(“fromValue”,“fromValue”);
在HashMap类型中,关键字必须始终与我要使用的url中的动态变量相同。无法读取值。
代码示例
gev0vcfq3#
1.检查
orderId
的排印错误1.如果在属性文件中声明动态值,请将name与属性Ex进行比较:
{orderId}