Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
huankai committed Mar 12, 2019
1 parent 6e8e407 commit 638d560
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 65 deletions.
7 changes: 0 additions & 7 deletions hk-commons-httpclient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,18 @@
<version>2.1.2.RELEASE</version>
</parent>

<properties>
<httpclient.version>4.5.6</httpclient.version>
</properties>

<dependencies>
<dependency>
<groupId>com.hk</groupId>
<artifactId>hk-commons-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>${httpclient.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.hk.commons.util.StringUtils;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpHeaders;
import org.apache.http.NameValuePair;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.config.RequestConfig;
Expand All @@ -15,7 +16,6 @@
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -92,7 +92,7 @@ public void setHttpClient(CloseableHttpClient httpClient) {
* @return
*/
protected Header[] generateHeaders() {
return new Header[]{new BasicHeader(HTTP.CONTENT_ENCODING, Consts.UTF_8.name())};
return new Header[]{new BasicHeader(HttpHeaders.CONTENT_ENCODING, Consts.UTF_8.name())};
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
package com.hk.commons.http.post;

import com.hk.commons.util.JsonUtils;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.client.ResponseHandler;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;

import com.hk.commons.util.JsonUtils;


/**
* JsonPost请求
*
* @author kevin
* @date 2017年9月28日上午9:31:24
*/
public class JsonPostHttpExecutor extends AbstractPostHttpExecutor<String,Object> {

public JsonPostHttpExecutor() {
super(BASIC_HANDLER);
}
public JsonPostHttpExecutor(CloseableHttpClient httpClient, ResponseHandler<String> responseHandler) {
super(httpClient, responseHandler);
}

@Override
public HttpEntity generateEntity(Object params) {
return new StringEntity(JsonUtils.serialize(params), Consts.UTF_8);
}
@Override
protected Header[] generateHeaders() {
return new Header[]{
new BasicHeader(HTTP.CONTENT_ENCODING, Consts.UTF_8.name()),
new BasicHeader(HTTP.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString())
public class JsonPostHttpExecutor extends AbstractPostHttpExecutor<String, Object> {

public JsonPostHttpExecutor() {
super(BASIC_HANDLER);
}

public JsonPostHttpExecutor(CloseableHttpClient httpClient, ResponseHandler<String> responseHandler) {
super(httpClient, responseHandler);
}

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

@Override
protected Header[] generateHeaders() {
return new Header[]{
new BasicHeader(HttpHeaders.CONTENT_ENCODING, Consts.UTF_8.name()),
new BasicHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString())
};
}
}

}
1 change: 0 additions & 1 deletion hk-commons-poi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<dependency>
<groupId>com.hk</groupId>
<artifactId>hk-commons-validator</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
Expand Down
18 changes: 0 additions & 18 deletions hk-commons-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +14,42 @@
<version>2.1.2.RELEASE</version>
</parent>

<properties>
<spring.version>5.1.4.RELEASE</spring.version>
<jackson.version>2.9.8</jackson.version>
<comons.lang.version>3.8.1</comons.lang.version>
<comons.io.version>2.6</comons.io.version>
<slf4j.version>1.7.25</slf4j.version>
<lombok.version>1.18.4</lombok.version>
<commons.text.version>1.6</commons.text.version>
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${comons.lang.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${commons.text.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.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>
<version>${comons.io.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.hk.commons.util.AssertUtils;
import com.hk.commons.util.ObjectUtils;
import com.hk.commons.util.StringUtils;
import lombok.Getter;
import lombok.Setter;
import org.springframework.core.convert.ConversionFailedException;
Expand Down Expand Up @@ -56,7 +55,7 @@ public T convert(Object source, TypeDescriptor sourceType, TypeDescriptor target
return defaultValue;
}
try {
return doConvert(StringUtils.trimWhitespace(source.toString()));
return doConvert(source.toString().trim());
} catch (Exception e) {
throw new ConversionFailedException(TypeDescriptor.forObject(source),
TypeDescriptor.valueOf(this.targetType), source, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.hk.commons.sms;

import com.hk.commons.asyn.Asyn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hk.commons.asyn.Asyn;

/**
* @author kevin
* @date 2018-07-27 08:53
*/
public class DefaultSmsCodeSender implements SmsCodeSender {
public class LoggerSmsCodeSender implements SmsCodeSender {

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSmsCodeSender.class);
private static final Logger LOGGER = LoggerFactory.getLogger(LoggerSmsCodeSender.class);

@Override
public void send(String mobile, String code, int expireSecond) {
Expand Down
7 changes: 0 additions & 7 deletions hk-commons-validator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,15 @@
<version>2.1.2.RELEASE</version>
</parent>

<properties>
<hibrenate.validator.version>6.0.14.Final</hibrenate.validator.version>
</properties>

<dependencies>
<dependency>
<groupId>com.hk</groupId>
<artifactId>hk-commons-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibrenate.validator.version}</version>
</dependency>
</dependencies>


</project>
15 changes: 13 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,24 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.hk</groupId>
<artifactId>hk-core-spring-boot-dependencies</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<modules>
<module>hk-commons-util</module>
<module>hk-commons-poi</module>
<module>hk-commons-validator</module>
<module>hk-commons-httpclient</module>
</modules>

<!--发布到 私服 地址-->
<distributionManagement>
<repository>
Expand Down Expand Up @@ -100,6 +111,6 @@
<version>2.5.2</version>
</plugin>

</plugins>
</plugins>
</build>
</project>

0 comments on commit 638d560

Please sign in to comment.