Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
*/
public class DivideShenyuContextDecorator implements ShenyuContextDecorator {

private static final String DEFAULT_MODULE = PluginEnum.DIVIDE.getName() + "-" + RpcTypeEnum.HTTP.getName();

@Override
public ShenyuContext decorator(final ShenyuContext shenyuContext, final MetaData metaData) {
String path = shenyuContext.getPath();
shenyuContext.setMethod(path);
shenyuContext.setRealUrl(path);
shenyuContext.setRpcType(RpcTypeEnum.HTTP.getName());
shenyuContext.setModule(Optional.ofNullable(metaData).map(MetaData::getAppName)
.orElse(String.format("%s-%s", PluginEnum.DIVIDE.getName(), shenyuContext.getRpcType())));
.orElse(DEFAULT_MODULE));
return shenyuContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.plugin.api.context.ShenyuContext;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -54,5 +55,6 @@ public void decoratorTest() {
ShenyuContext decorator = divideShenyuContextDecorator.decorator(shenyuContext, metaData);
assert MOCK_CONTEXT_PATH.equals(decorator.getMethod());
assert MOCK_CONTEXT_PATH.equals(decorator.getRealUrl());
Assertions.assertEquals("divide-http", decorator.getModule());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* The type WebSocket shenyu context decorator.
*/
public class WebSocketShenyuContextDecorator implements ShenyuContextDecorator {

private static final String DEFAULT_MODULE = PluginEnum.WEB_SOCKET.getName() + "-" + RpcTypeEnum.WEB_SOCKET.getName();

@Override
public ShenyuContext decorator(final ShenyuContext shenyuContext, final MetaData metaData) {
Expand All @@ -37,7 +39,7 @@ public ShenyuContext decorator(final ShenyuContext shenyuContext, final MetaData
shenyuContext.setRealUrl(path);
shenyuContext.setRpcType(RpcTypeEnum.WEB_SOCKET.getName());
shenyuContext.setModule(Optional.ofNullable(metaData).map(MetaData::getAppName)
.orElse(String.format("%s-%s", PluginEnum.WEB_SOCKET.getName(), shenyuContext.getRpcType())));
.orElse(DEFAULT_MODULE));
return shenyuContext;
}

Expand Down
Loading