Skip to content

Commit

Permalink
Some bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed Apr 20, 2020
1 parent c255ac9 commit d9d489d
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 24 deletions.
9 changes: 4 additions & 5 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3363,12 +3363,11 @@ <h4 id="framework-user-manual-auth"><a class="anchor" href="#framework-user-manu
.setToken(token)
.setName(user.getName())
.setMobile(user.getPhone())
.setRoleInfo(new HashSet&lt;OptInfo.RoleInfo&gt;() {
.setRoleInfo(new HashSet&lt;&gt;() {
{
add(new OptInfo.RoleInfo()
.setCode(userDTO.getRole())
.setName("..")
.setTenantCode("")
);
}
}));
Expand Down Expand Up @@ -3443,7 +3442,7 @@ <h4 id="framework-user-manual-auth"><a class="anchor" href="#framework-user-manu
* @param &lt;E&gt; 扩展操作用户信息类型
* @return 操作用户信息
*/
default &lt;E extends OptInfo&gt; Optional&lt;E&gt; getOptInfo() {
default &lt;E extends OptInfo&lt;E&gt;&gt; Optional&lt;E&gt; getOptInfo() {
return Dew.context().optInfo();
}

Expand All @@ -3454,15 +3453,15 @@ <h4 id="framework-user-manual-auth"><a class="anchor" href="#framework-user-manu
* @param token 登录Token
* @return 操作用户信息
*/
&lt;E extends OptInfo&gt; Optional&lt;E&gt; getOptInfo(String token);
&lt;E extends OptInfo&lt;E&gt;&gt; Optional&lt;E&gt; getOptInfo(String token);

/**
* 设置操作用户信息类型.
*
* @param &lt;E&gt; 扩展操作用户信息类型
* @param optInfo 扩展操作用户信息
*/
&lt;E extends OptInfo&gt; void setOptInfo(E optInfo);
&lt;E extends OptInfo&lt;E&gt;&gt; void setOptInfo(E optInfo);

/**
* 删除当前登录的操作用户信息.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package group.idealworld.dew;

import com.ecfront.dew.common.$;
import com.ecfront.dew.common.Resp;
import com.ecfront.dew.common.StandardCode;
import com.ecfront.dew.common.exception.RTException;
import com.fasterxml.jackson.databind.SerializationFeature;
import group.idealworld.dew.core.DewConfig;
import group.idealworld.dew.core.DewContext;
Expand Down Expand Up @@ -269,7 +271,7 @@ public static class Util {
* 获取真实IP.
*
* @param request 请求信息
* @return 真实的IP
* @return 真实的IP real ip
*/
public static String getRealIP(HttpServletRequest request) {
Map<String, String> requestHeader = new HashMap<>();
Expand All @@ -286,7 +288,7 @@ public static String getRealIP(HttpServletRequest request) {
*
* @param requestHeader 请求头信息
* @param defaultRemoteAddr 缺省的IP地址
* @return 真实的IP
* @return 真实的IP real ip
*/
public static String getRealIP(Map<String, String> requestHeader, String defaultRemoteAddr) {
Map<String, String> formattedRequestHeader = new HashMap<>();
Expand Down Expand Up @@ -360,7 +362,7 @@ public static class E {
* @param <E> 上抛的异常类型
* @param code 异常编码
* @param ex 上抛的异常对象
* @return 上抛的异常对象
* @return 上抛的异常对象 e
*/
public static <E extends Throwable> E e(String code, E ex) {
return e(code, ex, -1);
Expand All @@ -375,10 +377,10 @@ public static <E extends Throwable> E e(String code, E ex) {
* @param code 异常编码
* @param ex 上抛的异常对象
* @param customHttpCode 自定义Http状态码
* @return 上抛的异常对象
* @return 上抛的异常对象 e
*/
public static <E extends Throwable> E e(String code, E ex, StandardCode customHttpCode) {
return e(code, ex, Integer.valueOf(customHttpCode.toString()));
return e(code, ex, Integer.parseInt(customHttpCode.toString()));
}

/**
Expand All @@ -390,7 +392,7 @@ public static <E extends Throwable> E e(String code, E ex, StandardCode customHt
* @param code 异常编码
* @param ex 上抛的异常对象
* @param customHttpCode 自定义Http状态码
* @return 上抛的异常对象
* @return 上抛的异常对象 e
*/
public static <E extends Throwable> E e(String code, E ex, int customHttpCode) {
$.bean.setValue(ex, "detailMessage", $.json.createObjectNode()
Expand All @@ -401,6 +403,24 @@ public static <E extends Throwable> E e(String code, E ex, int customHttpCode) {
return ex;
}

/**
* 统一异常处理.
* <p>
* 返回Http状态码为200
*
* @param resp 统一返回对象
* @return 上抛的异常对象
*/
public static RTException e(Resp<?> resp) {
var ex = new RTException(resp.getMessage());
$.bean.setValue(ex, "detailMessage", $.json.createObjectNode()
.put("code", resp.getCode())
.put("message", resp.getMessage())
.put("customHttpCode", 200)
.toString());
return ex;
}

/**
* Check not null.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public class ErrorController extends AbstractErrorController {

private static final int FALL_BACK_STATUS = 500;

private static final Pattern MESSAGE_CHECK = Pattern.compile("^\\{\"code\":\"\\w*\",\"message\":\".*\",\"customHttpCode\":.*}$");
// TODO 可能有风险
private static final Pattern MESSAGE_CHECK = Pattern.compile("^\\{\"code\":\".*?\",\"message\":\".*?\",\"customHttpCode\":.*?\\}$");

private static final String SPECIAL_ERROR_FLAG = "org.springframework.boot.web.servlet.error.DefaultErrorAttributes.ERROR";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019. the original author or authors.
* Copyright 2020. the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,10 +36,9 @@ public class MetricsTest {
/**
* Test metric.
*
* @throws IOException the io exception
* @throws InterruptedException the interrupted exception
*/
public void testMetric() throws IOException, InterruptedException {
public void testMetric() throws InterruptedException {
for (int i = 0; i < 100; i++) {
testRestTemplate.getForObject("/test/valid-method-spring/2", String.class);
Thread.sleep(5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package group.idealworld.dew.core.cluster.spi.hazelcast;

import com.ecfront.dew.common.exception.RTUnsupportedEncodingException;
import com.hazelcast.client.HazelcastClientNotActiveException;
import group.idealworld.dew.core.cluster.AbsClusterMQ;
import group.idealworld.dew.core.cluster.dto.MessageWrap;
Expand Down Expand Up @@ -45,7 +46,7 @@ public class HazelcastClusterMQ extends AbsClusterMQ {
@Override
protected boolean doPublish(String topic, String message, Optional<Map<String, Object>> header, boolean confirm) {
if (confirm) {
throw new UnsupportedOperationException("Hazelcast doesn't support confirm mode");
throw new RTUnsupportedEncodingException("Hazelcast doesn't support confirm mode");
}
hazelcastAdapter.getHazelcastInstance().getTopic(topic).publish(message);
return true;
Expand All @@ -60,7 +61,7 @@ protected void doSubscribe(String topic, Consumer<MessageWrap> consumer) {
@Override
protected boolean doRequest(String address, String message, Optional<Map<String, Object>> header, boolean confirm) {
if (confirm) {
throw new UnsupportedOperationException("Hazelcast doesn't support confirm mode");
throw new RTUnsupportedEncodingException("Hazelcast doesn't support confirm mode");
}
return hazelcastAdapter.getHazelcastInstance().getQueue(address).add(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package group.idealworld.dew.core.cluster.spi.mqtt;

import com.ecfront.dew.common.exception.RTUnsupportedEncodingException;
import group.idealworld.dew.core.cluster.AbsClusterMQ;
import group.idealworld.dew.core.cluster.dto.MessageWrap;
import org.eclipse.paho.client.mqttv3.MqttException;
Expand Down Expand Up @@ -69,12 +70,12 @@ protected void doSubscribe(String topic, Consumer<MessageWrap> consumer) {

@Override
protected boolean doRequest(String address, String message, Optional<Map<String, Object>> header, boolean confirm) {
throw new UnsupportedOperationException("MQTT doesn't support point-to-point mode");
throw new RTUnsupportedEncodingException("MQTT doesn't support point-to-point mode");
}

@Override
protected void doResponse(String address, Consumer<MessageWrap> consumer) {
throw new UnsupportedOperationException("MQTT doesn't support point-to-point mode");
throw new RTUnsupportedEncodingException("MQTT doesn't support point-to-point mode");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package group.idealworld.dew.core.cluster.spi.rabbit.tracing;

import com.ecfront.dew.common.exception.RTUnsupportedEncodingException;
import com.rabbitmq.client.AMQP;
import io.opentracing.propagation.TextMap;

Expand Down Expand Up @@ -47,6 +48,6 @@ public void put(String key, String value) {

@Override
public Iterator<Map.Entry<String, String>> iterator() {
throw new UnsupportedOperationException("iterator should never be used with Tracer.inject()");
throw new RTUnsupportedEncodingException("iterator should never be used with Tracer.inject()");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package group.idealworld.dew.core.cluster.spi.rabbit.tracing;

import com.ecfront.dew.common.exception.RTUnsupportedEncodingException;
import io.opentracing.propagation.TextMap;

import java.util.HashMap;
Expand Down Expand Up @@ -53,6 +54,6 @@ public Iterator<Map.Entry<String, String>> iterator() {

@Override
public void put(String key, String value) {
throw new UnsupportedOperationException("Should be used only with tracer#extract()");
throw new RTUnsupportedEncodingException("Should be used only with tracer#extract()");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package group.idealworld.dew.core.cluster.spi.redis;

import com.ecfront.dew.common.exception.RTUnsupportedEncodingException;
import group.idealworld.dew.core.cluster.AbsClusterMQ;
import group.idealworld.dew.core.cluster.dto.MessageWrap;
import org.springframework.data.redis.core.RedisCallback;
Expand Down Expand Up @@ -48,7 +49,7 @@ public class RedisClusterMQ extends AbsClusterMQ {
@Override
protected boolean doPublish(String topic, String message, Optional<Map<String, Object>> header, boolean confirm) {
if (confirm) {
throw new UnsupportedOperationException("Hazelcast doesn't support confirm mode");
throw new RTUnsupportedEncodingException("Hazelcast doesn't support confirm mode");
}
redisTemplate.execute((RedisCallback<Void>) connection -> {
connection.publish(topic.getBytes(), message.getBytes());
Expand All @@ -70,7 +71,7 @@ protected void doSubscribe(String topic, Consumer<MessageWrap> consumer) {
@Override
protected boolean doRequest(String address, String message, Optional<Map<String, Object>> header, boolean confirm) {
if (confirm) {
throw new UnsupportedOperationException("Hazelcast doesn't support confirm mode");
throw new RTUnsupportedEncodingException("Hazelcast doesn't support confirm mode");
}
redisTemplate.execute((RedisCallback<Void>) connection -> {
connection.lPush(address.getBytes(), message.getBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.ecfront.dew.common.$;
import com.ecfront.dew.common.HttpHelper;
import com.ecfront.dew.common.Resp;
import com.ecfront.dew.common.exception.RTUnsupportedEncodingException;

import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -81,7 +82,7 @@ protected Resp<String> innerSend(String content, String title, Set<String> recei
}
break;
default:
throw new UnsupportedOperationException("[msgType] only support text/markdown");
throw new RTUnsupportedEncodingException("[msgType] only support text/markdown");
}
HttpHelper.ResponseWrap result = $.http.postWrap(ddUrl,
"{\n"
Expand Down

0 comments on commit d9d489d

Please sign in to comment.