java.lang.IllegalArgumentExceptionMap在SpringRestful服务中没有“orderId”的值

wyyhbhjk  于 2023-06-28  发布在  Java
关注(0)|答案(3)|浏览(97)

我正在做一个与支付相关的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”的值。

qc6wkl3g

qc6wkl3g1#

UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url).queryParam("criterion", criterion);
Product product = restTemplate.getForObject(builder.build().toUri(), Product.class);
q43xntqr

q43xntqr2#

我也面临着同样的问题。在我例子中,如果我像这样给一个变量分配一个键值对:
别这样
int getString(“String”,String);
那样做
“); return(“fromValue”,“fromValue”);
在HashMap类型中,关键字必须始终与我要使用的url中的动态变量相同。无法读取值。
代码示例

@GetMapping("/currency-conversion/from/{fromValue}/to/{toValue}/quantity/{quantity}")
  public CurrencyConversion calculateCurrencyConversion(@PathVariable String fromValue,
      @PathVariable String toValue, @PathVariable BigDecimal quantity) {

    HashMap<String, String> uriVariables = new HashMap<>();
    uriVariables.put("fromValue", fromValue);
    uriVariables.put("toValue", toValue);
    ResponseEntity<CurrencyConversion> responseEntity = new RestTemplate().getForEntity(
        "http://localhost:8000/currency-exchange/from/{fromValue}/to/{toValue}",
        CurrencyConversion.class, uriVariables);

    CurrencyConversion currencyConversion = responseEntity.getBody();

    return new CurrencyConversion(currencyConversion.getId(), fromValue, toValue,
        currencyConversion.getConversionMultiple(), quantity,
        quantity.multiply(currencyConversion.getConversionMultiple()),
        currencyConversion.getEnvironment());
  };
gev0vcfq

gev0vcfq3#

1.检查orderId的排印错误
1.如果在属性文件中声明动态值,请将name与属性Ex进行比较:{orderId}

相关问题