本文為博主原創,未經允許不得轉載:
在項目中會用到各種類型的http請求,包含put,get,post,delete,formData等各種請求方式,在這里總結一下
用過比較好的請求工具,使用service方法封裝。
代碼如下:
1.依賴的maven
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
2.封裝請求返回的實體類
@Setter @Getter public class ApacheHttpClientResult { /** 狀態碼 **/ private int statusCode; /** 響應內容 **/ private String responseContent; }
3.封裝各類型請求的方法
import java.util.Map; import org.apache.http.entity.mime.MultipartEntityBuilder; import com.vo.ApacheHttpClientResult; public interface ApacheHttpClientService { public ApacheHttpClientResult postForJson(String uri, String param) throws CustomException; public ApacheHttpClientResult postForJson(String uri, MultipartEntityBuilder param)throws CustomException; public ApacheHttpClientResult getForObject(String uri)throws CustomException; public ApacheHttpClientResult putForJson(String uri, String param)throws CustomException; public ApacheHttpClientResult deleteForJson(String uri, String param)throws CustomException; public ApacheHttpClientResult postForJson(String uri, String param, Map<String, String> headers)throws CustomException; public ApacheHttpClientResult getForObject(String uri, Map<String, String> headers)throws CustomException; public ApacheHttpClientResult putForJson(String uri, String param, Map<String, String> headers)throws CustomException; public ApacheHttpClientResult deleteForJson(String uri, String param, Map<String, String> headers)throws CustomException; public ApacheHttpClientResult getForObjectCloud(String uri, Map<String, String> headers) throws CustomException; public ApacheHttpClientResult getForObjectCloud(String uri) throws CustomException; public ApacheHttpClientResult postForJsonNoProxy(String uri, String param) throws CustomException; public ApacheHttpClientResult postForJson(String uri, String param, Map<String, String> headers, Map<String, String> resultHeaders); public ApacheHttpClientResult putForJson(String uri, String param, Map<String, String> headers, Map<String, String> resultHeaders); }
4.實現類
import java.io.Closeable; import java.io.IOException; import java.net.Proxy; import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig.Builder; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.StringEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import com.common.CustomException; import com.common.HttpDeleteWithBody; import com.intf.service.common.ApacheHttpClientService; import com.vo.ApacheHttpClientResult; @Service("apacheHttpClientService12") public class Test implements ApacheHttpClientService{ private final static Boolean enabled = false; private final static String host = "127.0.0.1"; private final static Integer port = 8080; private final static int timeOut=20000; private final static Boolean proxyEnabled= false; private static final Logger LOGGER = LoggerFactory.getLogger(ApacheHttpClientServiceImpl.class); /** * * 功能描述: <br> * 創建默認Builder * * @return * @see [相關類/方法](可選) * @since [產品/模塊版本](可選) */ private Builder createBuilder() { // init Builder and init TIME_OUT return RequestConfig.custom().setSocketTimeout(timeOut).setConnectTimeout(timeOut) .setConnectionRequestTimeout(timeOut); } @Override public ApacheHttpClientResult postForJson(String uri, String param) throws CustomException { // 定義返回 ApacheHttpClientResult result = new ApacheHttpClientResult(); // 定義httpClient和response CloseableHttpClient httpClient = HttpClientBuilder.create().build();; CloseableHttpResponse response = null; try { // 定義Post請求 HttpPost httpPost = new HttpPost(uri); // 設置配置 Builder builder = createBuilder(); RequestConfig config = null; // 是否開啟代理模式訪問 if (enabled) { HttpHost proxy = new HttpHost(host, port, Proxy.Type.HTTP.toString()); config = builder.setProxy(proxy).build(); } else { config = builder.build(); } httpPost.setConfig(config); // 設置請求頭 httpPost.setHeader("Accept", MediaType.APPLICATION_JSON_VALUE); httpPost.setHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE); // 發送請求得到返回數據 httpPost.setEntity(new StringEntity(param, "UTF-8")); // 得到響應 response = httpClient.execute(httpPost); // 狀態碼 result.setStatusCode(response.getStatusLine().getStatusCode()); // 響應內容 HttpEntity entity = response.getEntity(); // 響應內容 String responseContent = EntityUtils.toString(entity); result.setResponseContent(responseContent); } catch (Exception e) { throw new CustomException(e); } finally { // 關閉流 closeStream(response); closeStream(httpClient); } return result; } @Override public ApacheHttpClientResult getForObject(String uri) throws CustomException { // 定義返回 ApacheHttpClientResult result = new ApacheHttpClientResult(); // 定義httpClient和response CloseableHttpClient httpClient = HttpClientBuilder.create().build();; CloseableHttpResponse response = null; try { // HttpGet HttpGet httpGet = new HttpGet(uri); // 設置配置 Builder builder = createBuilder(); RequestConfig config = null; // 是否開啟代理模式訪問 if (enabled) { HttpHost proxy = new HttpHost(host, port, Proxy.Type.HTTP.toString()); config = builder.setProxy(proxy).build(); } else { config = builder.build(); } httpGet.setConfig(config); // 發送請求得到返回數據 response = httpClient.execute(httpGet); // 狀態碼 result.setStatusCode(response.getStatusLine().getStatusCode()); // 響應內容 HttpEntity entity = response.getEntity(); // 響應內容 String responseContent = EntityUtils.toString(entity, "UTF-8"); result.setResponseContent(responseContent); } catch (Exception e) { throw new CustomException(e); } finally { // 關閉流 closeStream(response); closeStream(httpClient); } return result; } @Override public ApacheHttpClientResult putForJson(String uri, String param) throws CustomException { // 定義返回 ApacheHttpClientResult result = new ApacheHttpClientResult(); // 定義httpClient和response CloseableHttpClient httpClient = HttpClientBuilder.create().build();; CloseableHttpResponse response = null; try { // HttpPut HttpPut httpPut = new HttpPut(uri); // 設置配置 Builder builder = createBuilder(); RequestConfig config = null; // 是否開啟代理模式訪問 if (enabled) { HttpHost proxy = new HttpHost(host, port, Proxy.Type.HTTP.toString()); config = builder.setProxy(proxy).build(); } else { config = builder.build(); } httpPut.setConfig(config); // 設置請求頭 httpPut.setHeader("Accept", MediaType.APPLICATION_JSON_VALUE); httpPut.setHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE); // 發送請求得到返回數據 httpPut.setEntity(new StringEntity(param, "UTF-8")); // 得到響應 response = httpClient.execute(httpPut); // 狀態碼 result.setStatusCode(response.getStatusLine().getStatusCode()); // 響應內容 HttpEntity entity = response.getEntity(); // 響應內容 String responseContent = EntityUtils.toString(entity); result.setResponseContent(responseContent); } catch (Exception e) { throw new CustomException(e); } finally { // 關閉流 closeStream(response); closeStream(httpClient); } return result; } @Override public ApacheHttpClientResult deleteForJson(String uri, String param) throws CustomException { // 定義返回 ApacheHttpClientResult result = new ApacheHttpClientResult(); // 定義httpClient和response CloseableHttpClient httpClient = HttpClientBuilder.create().build();; CloseableHttpResponse response = null; try { // HttpDelete HttpDeleteWithBody httpDelete = new HttpDeleteWithBody(uri); // 設置配置 Builder builder = createBuilder(); RequestConfig config = null; // 是否開啟代理模式訪問 if (enabled) { HttpHost proxy = new HttpHost(host, port, Proxy.Type.HTTP.toString()); config = builder.setProxy(proxy).build(); } else { config = builder.build(); } httpDelete.setConfig(config); // 設置請求頭 httpDelete.setHeader("Accept", MediaType.APPLICATION_JSON_VALUE); httpDelete.setHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE); // 發送請求得到返回數據 httpDelete.setEntity(new StringEntity(param, "UTF-8")); // 得到響應 response = httpClient.execute(httpDelete); // 狀態碼 result.setStatusCode(response.getStatusLine().getStatusCode()); // 響應內容 HttpEntity entity = response.getEntity(); // 響應內容 String responseContent = EntityUtils.toString(entity); result.setResponseContent(responseContent); } catch (Exception e) { throw new CustomException(e); } finally { // 關閉流 closeStream(response); closeStream(httpClient); } return result; } @Override public ApacheHttpClientResult postForJson(String uri, String param, Map<String, String> headers) throws CustomException { // 定義返回 ApacheHttpClientResult result = new ApacheHttpClientResult(); // 定義httpClient和response CloseableHttpClient httpClient = HttpClientBuilder.create().build();; CloseableHttpResponse response = null; try { // 定義Post請求 HttpPost httpPost = new HttpPost(uri); // 設置配置 Builder builder = createBuilder(); RequestConfig config = null; // 是否開啟代理模式訪問 if (enabled) { HttpHost proxy = new HttpHost(host, port, Proxy.Type.HTTP.toString()); config = builder.setProxy(proxy).build(); } else { config = builder.build(); } httpPost.setConfig(config); // 設置請求頭 httpPost.setHeader("Accept", MediaType.APPLICATION_JSON_VALUE); httpPost.setHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE); if (headers != null) { for (Map.Entry<String, String> entry : headers.entrySet()) { httpPost.setHeader(entry.getKey(), entry.getValue()); } } // 發送請求得到返回數據 httpPost.setEntity(new StringEntity(param, "UTF-8")); // 得到響應 response = httpClient.execute(httpPost); // 狀態碼 result.setStatusCode(response.getStatusLine().getStatusCode()); // 響應內容 HttpEntity entity = response.getEntity(); // 響應內容 String responseContent = EntityUtils.toString(entity); result.setResponseContent(responseContent); } catch (Exception e) { throw new CustomException(e); } finally { // 關閉流 closeStream(response); closeStream(httpClient); } return result; } @Override public ApacheHttpClientResult getForObject(String uri, Map<String, String> headers) throws CustomException { // 定義返回 ApacheHttpClientResult result = new ApacheHttpClientResult(); // 定義httpClient和response CloseableHttpClient httpClient = HttpClientBuilder.create().build();; CloseableHttpResponse response = null; try { // HttpGet HttpGet httpGet = new HttpGet(uri); // 設置配置 Builder builder = createBuilder(); RequestConfig config = null; // 是否開啟代理模式訪問 if (enabled) { HttpHost proxy = new HttpHost(host, port, Proxy.Type.HTTP.toString()); config = builder.setProxy(proxy).build(); } else { config = builder.build(); } httpGet.setConfig(config); // 設置請求頭 if (headers != null) { for (Map.Entry<String, String> entry : headers.entrySet()) { httpGet.setHeader(entry.getKey(), entry.getValue()); } } // 發送請求得到返回數據 response = httpClient.execute(httpGet); // 狀態碼 result.setStatusCode(response.getStatusLine().getStatusCode()); // 響應內容 HttpEntity entity = response.getEntity(); // 響應內容 String responseContent = EntityUtils.toString(entity); result.setResponseContent(responseContent); LOGGER.info(uri + "&&&&&" + response.toString() + "&&&&&" + responseContent); } catch (Exception e) { throw new CustomException(e); } finally { // 關閉流 closeStream(response); closeStream(httpClient); } return result; } @Override public ApacheHttpClientResult putForJson(String uri, String param, Map<String, String> headers) throws CustomException { // 定義返回 ApacheHttpClientResult result = new ApacheHttpClientResult(); // 定義httpClient和response CloseableHttpClient httpClient = HttpClientBuilder.create().build();; CloseableHttpResponse response = null; try { // HttpPut HttpPut httpPut = new HttpPut(uri); // 設置配置 Builder builder = createBuilder(); RequestConfig config = null; // 是否開啟代理模式訪問 if (enabled) { HttpHost proxy = new HttpHost(host, port, Proxy.Type.HTTP.toString()); config = builder.setProxy(proxy).build(); } else { config = builder.build(); } httpPut.setConfig(config); // 設置請求頭 httpPut.setHeader("Accept", MediaType.APPLICATION_JSON_VALUE); httpPut.setHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE); if (headers != null) { for (Map.Entry<String, String> entry : headers.entrySet()) { httpPut.setHeader(entry.getKey(), entry.getValue()); } } // 發送請求得到返回數據 httpPut.setEntity(new StringEntity(param, "UTF-8")); // 得到響應 response = httpClient.execute(httpPut); // 狀態碼 result.setStatusCode(response.getStatusLine().getStatusCode()); // 響應內容 HttpEntity entity = response.getEntity(); // 響應內容 String responseContent = EntityUtils.toString(entity); result.setResponseContent(responseContent); LOGGER.info(uri + "&&&&&" + response.toString() + "&&&&&" + param); } catch (Exception e) { throw new CustomException(e); } finally { // 關閉流 closeStream(response); closeStream(httpClient); } return result; } @Override public ApacheHttpClientResult deleteForJson(String uri, String param, Map<String, String> headers) throws CustomException { // 定義返回 ApacheHttpClientResult result = new ApacheHttpClientResult(); // 定義httpClient和response CloseableHttpClient httpClient = HttpClientBuilder.create().build();; CloseableHttpResponse response = null; try { // HttpDelete HttpDeleteWithBody httpDelete = new HttpDeleteWithBody(uri); // 設置配置 Builder builder = createBuilder(); RequestConfig config = null; // 是否開啟代理模式訪問 if (enabled) { HttpHost proxy = new HttpHost(host, port, Proxy.Type.HTTP.toString()); config = builder.setProxy(proxy).build(); } else { config = builder.build(); } httpDelete.setConfig(config); // 設置請求頭 httpDelete.setHeader("Accept", MediaType.APPLICATION_JSON_VALUE); httpDelete.setHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE); if (headers != null) { for (Map.Entry<String, String> entry : headers.entrySet()) { httpDelete.setHeader(entry.getKey(), entry.getValue()); } } // 發送請求得到返回數據 httpDelete.setEntity(new StringEntity(param, "UTF-8")); // 得到響應 response = httpClient.execute(httpDelete); // 狀態碼 result.setStatusCode(response.getStatusLine().getStatusCode()); // 響應內容 HttpEntity entity = response.getEntity(); // 響應內容 String responseContent = EntityUtils.toString(entity); result.setResponseContent(responseContent); } catch (Exception e) { throw new CustomException(e); } finally { // 關閉流 closeStream(response); closeStream(httpClient); } return result; } @Override public ApacheHttpClientResult getForObjectCloud(String uri, Map<String, String> headers) throws CustomException { // 定義返回 ApacheHttpClientResult result = new ApacheHttpClientResult(); // 定義httpClient和response CloseableHttpClient httpClient = HttpClientBuilder.create().build();; CloseableHttpResponse response = null; try { // HttpGet HttpGet httpGet = new HttpGet(uri); // 設置配置 Builder builder = createBuilder(); RequestConfig config = null; // 是否開啟代理模式訪問 if (proxyEnabled) { HttpHost proxy = new HttpHost(host, port, Proxy.Type.HTTP.toString()); config = builder.setProxy(proxy).build(); } else { config = builder.build(); } httpGet.setConfig(config); // 設置請求頭 if (headers != null) { for (Map.Entry<String, String> entry : headers.entrySet()) { httpGet.setHeader(entry.getKey(), entry.getValue()); } } // 發送請求得到返回數據 response = httpClient.execute(httpGet); // 狀態碼 result.setStatusCode(response.getStatusLine().getStatusCode()); // 響應內容 HttpEntity entity = response.getEntity(); // 響應內容 String responseContent = EntityUtils.toString(entity); result.setResponseContent(responseContent); } catch (Exception e) { throw new CustomException(e); } finally { // 關閉流 closeStream(response); closeStream(httpClient); } return result; } @Override public ApacheHttpClientResult getForObjectCloud(String uri) throws CustomException { // 定義返回 ApacheHttpClientResult result = new ApacheHttpClientResult(); // 定義httpClient和response CloseableHttpClient httpClient = HttpClientBuilder.create().build();; CloseableHttpResponse response = null; try { // HttpGet HttpGet httpGet = new HttpGet(uri); // 設置配置 Builder builder = createBuilder(); RequestConfig config = null; // 是否開啟代理模式訪問 if (proxyEnabled) { HttpHost proxy = new HttpHost(host, port, Proxy.Type.HTTP.toString()); config = builder.setProxy(proxy).build(); } else { config = builder.build(); } httpGet.setConfig(config); // 發送請求得到返回數據 response = httpClient.execute(httpGet); // 狀態碼 result.setStatusCode(response.getStatusLine().getStatusCode()); // 響應內容 HttpEntity entity = response.getEntity(); // 響應內容 String responseContent = EntityUtils.toString(entity, "UTF-8"); result.setResponseContent(responseContent); } catch (Exception e) { throw new CustomException(e); } finally { // 關閉流 closeStream(response); closeStream(httpClient); } return result; } @Override public ApacheHttpClientResult postForJsonNoProxy(String uri, String param) throws CustomException { // 定義返回 ApacheHttpClientResult result = new ApacheHttpClientResult(); // 定義httpClient和response CloseableHttpClient httpClient = HttpClientBuilder.create().build();; CloseableHttpResponse response = null; try { // 創建默認的httpClient實例 httpClient = HttpClients.createDefault(); // 定義Post請求 HttpPost httpPost = new HttpPost(uri); // 設置配置 Builder builder = createBuilder(); RequestConfig config = builder.build(); httpPost.setConfig(config); // 設置請求頭 httpPost.setHeader("Accept", MediaType.APPLICATION_JSON_VALUE); httpPost.setHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE); // 發送請求得到返回數據 httpPost.setEntity(new StringEntity(param, "UTF-8")); // 得到響應 response = httpClient.execute(httpPost); // 狀態碼 result.setStatusCode(response.getStatusLine().getStatusCode()); // 響應內容 HttpEntity entity = response.getEntity(); // 響應內容 String responseContent = EntityUtils.toString(entity); result.setResponseContent(responseContent); } catch (Exception e) { throw new CustomException(e); } finally { // 關閉流 closeStream(response); closeStream(httpClient); } return result; } @Override public ApacheHttpClientResult postForJson(String uri, MultipartEntityBuilder fileBuilder) throws CustomException { // 定義返回 ApacheHttpClientResult result = new ApacheHttpClientResult(); // 定義httpClient和response CloseableHttpClient httpClient = HttpClientBuilder.create().build();; CloseableHttpResponse response = null; try { // 定義Post請求 HttpPost httpPost = new HttpPost(uri); // 設置配置 Builder builder = createBuilder(); RequestConfig config = null; // 是否開啟代理模式訪問 if (enabled) { HttpHost proxy = new HttpHost(host, port, Proxy.Type.HTTP.toString()); config = builder.setProxy(proxy).build(); } else { config = builder.build(); } httpPost.setConfig(config); // 設置請求頭 //httpPost.setHeader("Content-Type", "multipart/form-data"); // 發送請求得到返回數據 httpPost.setEntity(fileBuilder.build()); // 得到響應 response = httpClient.execute(httpPost); // 狀態碼 result.setStatusCode(response.getStatusLine().getStatusCode()); // 響應內容 HttpEntity entity = response.getEntity(); // 響應內容 String responseContent = EntityUtils.toString(entity); result.setResponseContent(responseContent); } catch (Exception e) { throw new CustomException(e); } finally { // 關閉流 closeStream(response); closeStream(httpClient); } return result; } @Override public ApacheHttpClientResult postForJson(String uri, String param, Map<String, String> headers, Map<String, String> resultHeaders) throws CustomException { // 定義返回 ApacheHttpClientResult result = new ApacheHttpClientResult(); // 定義httpClient和response CloseableHttpClient httpClient = HttpClientBuilder.create().build();; CloseableHttpResponse response = null; try { // 定義Post請求 HttpPost httpPost = new HttpPost(uri); // 設置配置 Builder builder = createBuilder(); RequestConfig config = null; // 是否開啟代理模式訪問 if (enabled) { HttpHost proxy = new HttpHost(host, port, Proxy.Type.HTTP.toString()); config = builder.setProxy(proxy).build(); } else { config = builder.build(); } httpPost.setConfig(config); // 設置請求頭 httpPost.setHeader("Accept", MediaType.APPLICATION_JSON_VALUE); httpPost.setHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE); if (headers != null) { for (Map.Entry<String, String> entry : headers.entrySet()) { httpPost.setHeader(entry.getKey(), entry.getValue()); } } // 發送請求得到返回數據 httpPost.setEntity(new StringEntity(param, "UTF-8")); // 得到響應 response = httpClient.execute(httpPost); // 狀態碼 result.setStatusCode(response.getStatusLine().getStatusCode()); // 響應內容 HttpEntity entity = response.getEntity(); Header header = response.getFirstHeader("Location"); if (header != null && StringUtils.isNotBlank(header.getValue())) { String location = header.getValue(); String maCertificateId = location.substring(header.getValue().lastIndexOf('/') + 1, location.length()); resultHeaders.put("Location", maCertificateId); } // 響應內容 String responseContent = EntityUtils.toString(entity); result.setResponseContent(responseContent); } catch (Exception e) { throw new CustomException(e); } finally { // 關閉流 closeStream(response); closeStream(httpClient); } return result; } @Override public ApacheHttpClientResult putForJson(String uri, String param, Map<String, String> headers, Map<String, String> resultHeaders) throws CustomException { // 定義返回 ApacheHttpClientResult result = new ApacheHttpClientResult(); // 定義httpClient和response CloseableHttpClient httpClient = HttpClientBuilder.create().build();; CloseableHttpResponse response = null; try { // HttpPut HttpPut httpPut = new HttpPut(uri); // 設置配置 Builder builder = createBuilder(); RequestConfig config = null; // 是否開啟代理模式訪問 if (enabled) { HttpHost proxy = new HttpHost(host, port, Proxy.Type.HTTP.toString()); config = builder.setProxy(proxy).build(); } else { config = builder.build(); } httpPut.setConfig(config); // 設置請求頭 httpPut.setHeader("Accept", MediaType.APPLICATION_JSON_VALUE); httpPut.setHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE); if (headers != null) { for (Map.Entry<String, String> entry : headers.entrySet()) { httpPut.setHeader(entry.getKey(), entry.getValue()); } } // 發送請求得到返回數據 httpPut.setEntity(new StringEntity(param, "UTF-8")); // 得到響應 response = httpClient.execute(httpPut); // 狀態碼 result.setStatusCode(response.getStatusLine().getStatusCode()); // 響應內容 HttpEntity entity = response.getEntity(); // 響應內容 String responseContent = EntityUtils.toString(entity); result.setResponseContent(responseContent); Header header = response.getFirstHeader("Location"); if (header != null && StringUtils.isNotBlank(header.getValue())) { String location = header.getValue(); String maCertificateId = location.substring(header.getValue().lastIndexOf('/') + 1, location.length()); resultHeaders.put("Location", maCertificateId); } LOGGER.info(uri + "&&&&&" + response.toString() + "&&&&&" + param); } catch (Exception e) { throw new CustomException(e); } finally { // 關閉流 closeStream(response); closeStream(httpClient); } return result; } public static void closeStream(Closeable c) { // 流不為空 if (c != null) { try { // 流關閉 c.close(); } catch (IOException ex) { LOGGER.error("closeStream failed", ex); } } } }
5.依賴的類:
@NotThreadSafe public class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase { private static final String METHOD_NAME = "DELETE"; /** * 獲取方法(必須重載) * * @return */ @Override public String getMethod() { return METHOD_NAME; } public HttpDeleteWithBody(final String uri) { super(); setURI(URI.create(uri)); } public HttpDeleteWithBody(final URI uri) { super(); setURI(uri); } public HttpDeleteWithBody() { super(); } }
public class CustomException extends Exception { private static final long serialVersionUID = 8984728932846627819L; public CustomException() { super(); } public CustomException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } /** public CustomException(String message, Throwable cause) { super(message, cause); } public CustomException(String message) { super(message); } public CustomException(Throwable cause) { super(cause); } }
