| | |
| | | package com.lf.server.helper; |
| | | |
| | | import com.lf.server.entity.all.StaticData; |
| | | import io.swagger.models.HttpMethod; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.apache.http.HttpEntity; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取错误信息 |
| | | * |
| | | * @param uri Uri地址 |
| | | * @param ex 异常 |
| | | * @return 错误信息 |
| | | */ |
| | | public static String getErrorInfo(String uri, Exception ex) { |
| | | Map<String, Object> map = new LinkedHashMap<>(); |
| | | map.put("result", null); |
| | | map.put("message", ex.getMessage()); |
| | | map.put("code", 400); |
| | | map.put("uri", uri); |
| | | //map.put("tag", StaticData.CACHE_PREFIX) |
| | | |
| | | return map.toString(); |
| | | } |
| | | |
| | | /** |
| | | * GET请求(REST) |
| | | */ |
| | | public static String getForRest(String uri) { |
| | | RestTemplate rest = getRestTemplate(); |
| | | |
| | | return rest.getForObject(uri, String.class); |
| | | } |
| | | |
| | | /** |
| | | * GET请求(REST) |
| | | */ |
| | | public static <T> T getForRest(String uri, Class<T> clazz) { |
| | | RestTemplate rest = getRestTemplate(); |
| | | |
| | | return rest.getForObject(uri, clazz); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取错误信息 |
| | | * |
| | | * @param uri Uri地址 |
| | | * @param ex 异常 |
| | | * @return 错误信息 |
| | | * POST请求(REST) |
| | | */ |
| | | public static String getErrorInfo(String uri, Exception ex) { |
| | | Map<String, Object> map = new LinkedHashMap<>(); |
| | | map.put("result", null); |
| | | map.put("message", ex.getMessage()); |
| | | map.put("code", 400); |
| | | map.put("uri", uri); |
| | | //map.put("tag", StaticData.CACHE_PREFIX) |
| | | public static <T> String postForRest(String uri, T t) { |
| | | RestTemplate rest = getRestTemplate(); |
| | | |
| | | return map.toString(); |
| | | return rest.postForObject(uri, t, String.class); |
| | | } |
| | | |
| | | /** |
| | | * DELETE请求(REST) |
| | | */ |
| | | public static void deleteForRest(String uri) { |
| | | RestTemplate rest = getRestTemplate(); |
| | | |
| | | rest.delete(uri); |
| | | } |
| | | } |