Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
huankai committed Jul 17, 2018
1 parent 3f9ed57 commit cf6e332
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 229 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.hk.commons.http;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.hk.commons.util.CollectionUtils;
import com.hk.commons.util.ConverterUtils;
import com.hk.commons.util.StringUtils;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.NameValuePair;
Expand All @@ -19,9 +17,10 @@
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

import com.hk.commons.util.CollectionUtils;
import com.hk.commons.util.ConverterUtils;
import com.hk.commons.util.StringUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* 请求接口抽象实现
Expand Down Expand Up @@ -107,16 +106,19 @@ protected String generateUri(String uri, Map<String, Object> params) {
StringBuilder s = new StringBuilder(uri);
if (CollectionUtils.isNotEmpty(params)) {
List<NameValuePair> nvps = new ArrayList<>();
for (Map.Entry<String, Object> entry : params.entrySet()) {
String value = ConverterUtils.getInstance().convert(entry.getValue(), String.class);
if (StringUtils.isNotBlank(value)) {
nvps.add(new BasicNameValuePair(entry.getKey(), value));
ConverterUtils converterUtils = ConverterUtils.getInstance();
params.forEach((key, value) -> {
String _value = converterUtils.convert(value, String.class);
if (StringUtils.isNotBlank(_value)) {
nvps.add(new BasicNameValuePair(key, _value));
}
});
if (!nvps.isEmpty()) {
if (!StringUtils.endsWith(uri, "?")) {
s.append("?");
}
s.append(URLEncodedUtils.format(nvps, Consts.UTF_8));
}
if (!StringUtils.endsWith(uri, "?")) {
s.append("?");
}
s.append(URLEncodedUtils.format(nvps, Consts.UTF_8));
}
return s.toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.hk.commons.http.get;

import java.io.IOException;
import java.net.URI;
import java.util.Map;

import com.hk.commons.http.AbstractHttpExecutor;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;

import com.hk.commons.http.AbstractHttpExecutor;
import java.io.IOException;
import java.net.URI;
import java.util.Map;


/**
Expand Down Expand Up @@ -39,7 +38,7 @@ public T execute(String uri, Map<String, Object> params) throws IOException {
* @param params
* @return
*/
protected HttpGet buildHttpGet(String uri, Map<String, Object> params) {
protected final HttpGet buildHttpGet(String uri, Map<String, Object> params) {
HttpGet get = new HttpGet();
String uri_ = generateUri(uri, params);
get.setHeaders(generateHeaders());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public JsonPostHttpExecutor(CloseableHttpClient httpClient, ResponseHandler<Stri

@Override
public HttpEntity generateEntity(Object params) {
return new StringEntity(JsonUtils.toJSONString(params), Consts.UTF_8);
return new StringEntity(JsonUtils.serialize(params), Consts.UTF_8);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.hk.commons.http.post;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.hk.commons.util.CollectionUtils;
import com.hk.commons.util.ConverterUtils;
import com.hk.commons.util.StringUtils;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
Expand All @@ -12,9 +11,9 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;

import com.hk.commons.util.CollectionUtils;
import com.hk.commons.util.ConverterUtils;
import com.hk.commons.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* POST请求
Expand All @@ -34,7 +33,7 @@ public SimplePostHttpExecutor(CloseableHttpClient httpClient, ResponseHandler<St

@Override
public HttpEntity generateEntity(Map<String, Object> params) {
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
List<NameValuePair> nvps = new ArrayList<>();
if (CollectionUtils.isNotEmpty(params)) {
for (Map.Entry<String, Object> entry : params.entrySet()) {
String value = ConverterUtils.getInstance().convert(entry.getValue(), String.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
*
*/
package com.hk.commons.poi.excel.write.handler;

import com.hk.commons.poi.excel.exception.ExcelWriteException;
Expand Down Expand Up @@ -433,7 +430,7 @@ protected final void setCellValue(Cell cell, String propertyName, Object value)
cell.setCellValue(value.toString());

} else {
cell.setCellValue(JsonUtils.toJSONString(value));
cell.setCellValue(JsonUtils.serialize(value));
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions hk-commons-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
Loading

0 comments on commit cf6e332

Please sign in to comment.