All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nepxion.discovery.common.util.RestUtil Maven / Gradle / Ivy

Go to download

Nepxion Discovery is a solution for Spring Cloud with blue green, gray, weight, limitation, circuit breaker, degrade, isolation, monitor, tracing, dye, failover, async agent

There is a newer version: 6.22.0
Show newest version
package com.nepxion.discovery.common.util;

/**
 * 

Title: Nepxion Discovery

*

Description: Nepxion Discovery

*

Copyright: Copyright (c) 2017-2050

*

Company: Nepxion

* @author Haojun Ren * @version 1.0 */ import org.apache.commons.lang3.StringUtils; import org.springframework.web.client.ResponseErrorHandler; import org.springframework.web.client.RestTemplate; import com.fasterxml.jackson.core.type.TypeReference; import com.nepxion.discovery.common.handler.RestErrorHandler; public class RestUtil { public static T fromJson(RestTemplate restTemplate, String result, TypeReference typeReference) { try { return JsonUtil.fromJson(result, typeReference); } catch (Exception e) { String cause = getCause(restTemplate); if (StringUtils.isNotEmpty(cause)) { throw new IllegalArgumentException(cause); } throw e; } } public static String getCause(RestTemplate restTemplate) { ResponseErrorHandler responseErrorHandler = restTemplate.getErrorHandler(); if (responseErrorHandler instanceof RestErrorHandler) { RestErrorHandler errorHandler = (RestErrorHandler) responseErrorHandler; return errorHandler.getCause(); } return null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy