Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.7.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	build.gradle
  • Loading branch information
li-xunhuan committed Dec 25, 2023
2 parents bff7496 + f26992d commit 697118c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion mica-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies {
api "org.springframework:spring-context"
api "com.fasterxml.jackson.core:jackson-databind"
implementation "org.springframework:spring-context"
compileOnly "org.springframework:spring-web"
compileOnly "jakarta.validation:jakarta.validation-api"
compileOnly "io.swagger:swagger-annotations"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.fasterxml.jackson.databind.type.MapType;
import net.dreamlu.mica.core.function.CheckedConsumer;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -220,7 +219,7 @@ public static JsonNode readTree(JsonParser jsonParser) {
*/
@Nullable
public static <T> T readValue(@Nullable byte[] content, Class<T> valueType) {
if (ObjectUtils.isEmpty(content)) {
if (content == null || content.length == 0) {
return null;
}
try {
Expand Down Expand Up @@ -301,7 +300,7 @@ public static <T> T readValue(@Nullable Reader reader, Class<T> valueType) {
*/
@Nullable
public static <T> T readValue(@Nullable byte[] content, TypeReference<T> typeReference) {
if (ObjectUtils.isEmpty(content)) {
if (content == null || content.length == 0) {
return null;
}
try {
Expand Down Expand Up @@ -381,7 +380,7 @@ public static <T> T readValue(@Nullable Reader reader, TypeReference<T> typeRefe
*/
@Nullable
public static <T> T readValue(@Nullable byte[] content, JavaType javaType) {
if (ObjectUtils.isEmpty(content)) {
if (content == null || content.length == 0) {
return null;
}
try {
Expand Down Expand Up @@ -531,7 +530,7 @@ public static JavaType getParametricType(Class<?> parametrized, JavaType... para
* @return 集合
*/
public static <T> List<T> readList(@Nullable byte[] content, Class<T> elementClass) {
if (ObjectUtils.isEmpty(content)) {
if (content == null || content.length == 0) {
return Collections.emptyList();
}
try {
Expand Down Expand Up @@ -697,7 +696,7 @@ public static <V> Map<String, V> readMap(@Nullable String content, Class<?> valu
* @return 集合
*/
public static <K, V> Map<K, V> readMap(@Nullable byte[] content, Class<?> keyClass, Class<?> valueClass) {
if (ObjectUtils.isEmpty(content)) {
if (content == null || content.length == 0) {
return Collections.emptyMap();
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void log(@Nonnull String message) {
@Override
public void log(@Nonnull String message) {
// 统一添加前缀,方便在茫茫日志中查看
System.out.printf("HttpLogger: %s\n", message);
System.out.println("HttpLogger: " + message);
}
};

Expand Down
6 changes: 5 additions & 1 deletion mica-http/src/test/java/net/dreamlu/HttpRequestDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package net.dreamlu;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.extern.slf4j.Slf4j;
import net.dreamlu.mica.core.utils.Base64Util;
import net.dreamlu.mica.http.HttpLogger;
import net.dreamlu.mica.http.HttpRequest;
Expand All @@ -33,17 +34,20 @@
*
* @author L.cm
*/
@Slf4j
public class HttpRequestDemo {

public void doc() {
// 设定全局日志级别 NONE,BASIC,HEADERS,BODY, 默认:NONE 和 self4
HttpRequest.setGlobalLog(LogLevel.BODY);
// 设置控制台日志,用于没有日志依赖的 sdk 开发时使用
HttpRequest.setGlobalLog(HttpLogger.Console, LogLevel.BODY);
// 设置为自己的日志,避免需要配置 net.dreamlu.mica.http 包日志等级
HttpRequest.setGlobalLog(log::info);

// 同步请求 url,方法支持 get、post、patch、put、delete
HttpRequest.get("https://www.baidu.com")
.useSlf4jLog() //使用 Slf4j 日志,同类的有 .useConsoleLog(),日志级别为 BODY
.useSlf4jLog() //使用 Slf4j 日志,同类的有 .useConsoleLog(),.useLog(log::info),日志级别为 BODY
.addHeader("x-account-id", "mica001") // 添加 header
.addCookie(new Cookie.Builder() // 添加 cookie
.name("sid")
Expand Down

0 comments on commit 697118c

Please sign in to comment.