Merge branch 'apache-3.1' into apache-3.2

# Conflicts:
#	dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/DefaultCommandExecutor.java
#	dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/api/ConnectionHandler.java
#	dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractServer.java
This commit is contained in:
Albumen Kevin 2023-01-04 17:36:49 +08:00
commit b8ea46d038
20 changed files with 141 additions and 93 deletions

View File

@ -18,7 +18,20 @@
package org.apache.dubbo.common.constants;
/**
* Constants of Error codes used in logger.
* <p>Constants of Error Codes used in logger.
*
* <p>Format: <i>[Category]-[Code]</i>, where:
* <li>[Category] is the category code which identifies the module.
* <li>[Code] is the detailed code.
* <li>Every blanks should be filled with positive number.
*
* <br /><br />
* <p>Hint:
* <li>Synchronize this file across different branches. (Use merge and cherry-pick.)
* <li>Double-check the usage in different branches before deleting any of the error code.
* <li>If applicable, use error code that already appears in this file.
* <li>If it's required to add an error code, find an error code that's marked by 'Absent', and rename it. (so that no code is wasted)
* <li>Update the corresponding file in dubbo-website repository.
*/
public interface LoggerCodeConstants {
@ -222,7 +235,10 @@ public interface LoggerCodeConstants {
String PROXY_FAILED_EXPORT_SERVICE = "3-2";
String PROXY_FAILED_JAVASSIST = "3-3";
/**
* Absent. Merged with 3-8.
*/
String PROXY_33 = "3-3";
String PROXY_TIMEOUT_REQUEST = "3-4";
@ -319,7 +335,7 @@ public interface LoggerCodeConstants {
String CONFIG_STOP_DUBBO_ERROR = "5-20";
String CONFIG_FAILED_EXECUTE_DESTORY = "5-21";
String CONFIG_FAILED_EXECUTE_DESTROY = "5-21";
String CONFIG_FAILED_INIT_CONFIG_CENTER = "5-22";
@ -366,6 +382,9 @@ public interface LoggerCodeConstants {
String TRANSPORT_FAILED_CLOSE = "6-3";
/**
* Absent. Merged to 99-0.
*/
String TRANSPORT_UNEXPECTED_EXCEPTION = "6-4";
String TRANSPORT_FAILED_DISCONNECT_PROVIDER = "6-5";

View File

@ -82,7 +82,7 @@ import static java.lang.String.format;
import static org.apache.dubbo.common.config.ConfigurationUtils.parseProperties;
import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_SPLIT_PATTERN;
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_FAILED_EXECUTE_DESTORY;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_FAILED_EXECUTE_DESTROY;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_FAILED_INIT_CONFIG_CENTER;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_FAILED_START_MODEL;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_REFRESH_INSTANCE_ERROR;
@ -1124,7 +1124,7 @@ public class DefaultApplicationDeployer extends AbstractDeployer<ApplicationMode
try {
serviceDiscovery.destroy();
} catch (Throwable ignored) {
logger.warn(CONFIG_FAILED_EXECUTE_DESTORY, "", "", ignored.getMessage(), ignored);
logger.warn(CONFIG_FAILED_EXECUTE_DESTROY, "", "", ignored.getMessage(), ignored);
}
});
if (logger.isDebugEnabled()) {

View File

@ -401,7 +401,7 @@ public class ServiceAnnotationPostProcessor implements BeanDefinitionRegistryPos
}
private Set<String> resolvePackagesToScan(Set<String> packagesToScan) {
Set<String> resolvedPackagesToScan = new LinkedHashSet<String>(packagesToScan.size());
Set<String> resolvedPackagesToScan = new LinkedHashSet<>(packagesToScan.size());
for (String packageToScan : packagesToScan) {
if (StringUtils.hasText(packageToScan)) {
String resolvedPackageToScan = environment.resolvePlaceholders(packageToScan.trim());

View File

@ -16,6 +16,8 @@
*/
package org.apache.dubbo.qos.command;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.qos.command.annotation.Cmd;
import org.apache.dubbo.qos.common.QosConstants;
import org.apache.dubbo.qos.permission.PermissionLevel;
@ -26,6 +28,7 @@ import org.apache.dubbo.qos.permission.PermissionChecker;
import org.apache.dubbo.rpc.model.FrameworkModel;
public class DefaultCommandExecutor implements CommandExecutor {
private final static Logger logger = LoggerFactory.getLogger(DefaultCommandExecutor.class);
private final FrameworkModel frameworkModel;
public DefaultCommandExecutor(FrameworkModel frameworkModel) {
@ -34,13 +37,21 @@ public class DefaultCommandExecutor implements CommandExecutor {
@Override
public String execute(CommandContext commandContext) throws NoSuchCommandException, PermissionDenyException {
String remoteAddress = Optional.ofNullable(commandContext.getRemote())
.map(Channel::remoteAddress).map(Objects::toString).orElse("unknown");
logger.info("[Dubbo QoS] Command Process start. Command: " + commandContext.getCommandName() +
", Args: " + Arrays.toString(commandContext.getArgs()) + ", Remote Address: " + remoteAddress);
BaseCommand command = null;
try {
command = frameworkModel.getExtensionLoader(BaseCommand.class).getExtension(commandContext.getCommandName());
} catch (Throwable throwable) {
//can't find command
//can't find command
}
if (command == null) {
logger.info("[Dubbo QoS] Command Not found. Command: " + commandContext.getCommandName() +
", Remote Address: " + remoteAddress);
throw new NoSuchCommandException(commandContext.getCommandName());
}
@ -57,10 +68,23 @@ public class DefaultCommandExecutor implements CommandExecutor {
final PermissionLevel cmdRequiredPermissionLevel = cmd.requiredPermissionLevel();
if (!permissionChecker.access(commandContext, cmdRequiredPermissionLevel)) {
logger.info("[Dubbo QoS] Command Deny to access. Command: " + commandContext.getCommandName() +
", Args: " + Arrays.toString(commandContext.getArgs()) + ", Required Permission Level: " + cmdRequiredPermissionLevel +
", Remote Address: " + remoteAddress);
throw new PermissionDenyException(commandContext.getCommandName());
}
}
return command.execute(commandContext, commandContext.getArgs());
}
try {
String result = command.execute(commandContext, commandContext.getArgs());
logger.info("[Dubbo QoS] Command Process success. Command: " + commandContext.getCommandName() +
", Args: " + Arrays.toString(commandContext.getArgs()) + ", Result: " + result +
", Remote Address: " + remoteAddress);
return result;
} catch (Throwable t) {
logger.info("[Dubbo QoS] Command Process Failed. Command: " + commandContext.getCommandName() +
", Args: " + Arrays.toString(commandContext.getArgs()) +
", Remote Address: " + remoteAddress, t);
throw t;
} }
}

View File

@ -46,7 +46,7 @@ import static java.util.Collections.unmodifiableCollection;
import static org.apache.dubbo.common.constants.CommonConstants.READONLY_EVENT;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_CLOSE;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_RESPONSE;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
import static org.apache.dubbo.remoting.Constants.HEARTBEAT_CHECK_TICK;
import static org.apache.dubbo.remoting.Constants.LEAST_HEARTBEAT_DURATION;
import static org.apache.dubbo.remoting.Constants.TICKS_PER_WHEEL;
@ -221,7 +221,7 @@ public class HeaderExchangeServer implements ExchangeServer {
startIdleCheckTask(url);
}
} catch (Throwable t) {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", t.getMessage(), t);
logger.error(INTERNAL_ERROR, "unknown error in remoting module", "", t.getMessage(), t);
}
}

View File

@ -23,7 +23,7 @@ import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.Client;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_RECONNECT;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
/**
* ReconnectTimerTask
@ -64,7 +64,7 @@ public class ReconnectTimerTask extends AbstractTimerTask {
}
}
} catch (Throwable t) {
logger.warn(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "Exception when reconnect to remote channel " + channel.getRemoteAddress(), t);
logger.warn(INTERNAL_ERROR, "unknown error in remoting module", "", "Exception when reconnect to remote channel " + channel.getRemoteAddress(), t);
}
}
}

View File

@ -28,7 +28,7 @@ import org.apache.dubbo.remoting.Constants;
import org.apache.dubbo.remoting.transport.codec.CodecAdapter;
import org.apache.dubbo.rpc.model.FrameworkModel;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
import static org.apache.dubbo.rpc.model.ScopeModelUtil.getFrameworkModel;
/**
@ -80,7 +80,7 @@ public abstract class AbstractEndpoint extends AbstractPeer implements Resetable
}
}
} catch (Throwable t) {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", t.getMessage(), t);
logger.error(INTERNAL_ERROR, "", "", t.getMessage(), t);
}
try {
@ -88,7 +88,7 @@ public abstract class AbstractEndpoint extends AbstractPeer implements Resetable
this.codec = getChannelCodec(url);
}
} catch (Throwable t) {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", t.getMessage(), t);
logger.error(INTERNAL_ERROR, "unknown error in remoting module", "", t.getMessage(), t);
}
}

View File

@ -36,7 +36,7 @@ import java.util.concurrent.ExecutorService;
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
import static org.apache.dubbo.config.Constants.SERVER_THREAD_POOL_NAME;
import static org.apache.dubbo.remoting.Constants.ACCEPTS_KEY;
import static org.apache.dubbo.remoting.Constants.DEFAULT_ACCEPTS;
@ -97,7 +97,7 @@ public abstract class AbstractServer extends AbstractEndpoint implements Remotin
}
}
} catch (Throwable t) {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", t.getMessage(), t);
logger.error(INTERNAL_ERROR, "unknown error in remoting module", "", t.getMessage(), t);
}
ExecutorService executor = executorRepository.createExecutorIfAbsent(ExecutorUtil.setThreadName(url, SERVER_THREAD_POOL_NAME));
@ -129,13 +129,13 @@ public abstract class AbstractServer extends AbstractEndpoint implements Remotin
try {
super.close();
} catch (Throwable e) {
logger.warn(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", e.getMessage(), e);
logger.warn(INTERNAL_ERROR, "unknown error in remoting module", "", e.getMessage(), e);
}
try {
doClose();
} catch (Throwable e) {
logger.warn(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", e.getMessage(), e);
logger.warn(INTERNAL_ERROR, "unknown error in remoting module", "", e.getMessage(), e);
}
}
@ -164,13 +164,13 @@ public abstract class AbstractServer extends AbstractEndpoint implements Remotin
public void connected(Channel ch) throws RemotingException {
// If the server has entered the shutdown process, reject any new connection
if (this.isClosing() || this.isClosed()) {
logger.warn(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "Close new channel " + ch + ", cause: server is closing or has been closed. For example, receive a new connect request while in shutdown process.");
logger.warn(INTERNAL_ERROR, "unknown error in remoting module", "", "Close new channel " + ch + ", cause: server is closing or has been closed. For example, receive a new connect request while in shutdown process.");
ch.close();
return;
}
if (accepts > 0 && getChannelsSize()> accepts) {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "Close channel " + ch + ", cause: The server " + ch.getLocalAddress() + " connections greater than max config " + accepts);
logger.error(INTERNAL_ERROR, "unknown error in remoting module", "", "Close channel " + ch + ", cause: The server " + ch.getLocalAddress() + " connections greater than max config " + accepts);
ch.close();
return;
}
@ -180,7 +180,7 @@ public abstract class AbstractServer extends AbstractEndpoint implements Remotin
@Override
public void disconnected(Channel ch) throws RemotingException {
if (getChannelsSize()==0) {
logger.warn(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "All clients has disconnected from " + ch.getLocalAddress() + ". You can graceful shutdown now.");
logger.warn(INTERNAL_ERROR, "unknown error in remoting module", "", "All clients has disconnected from " + ch.getLocalAddress() + ". You can graceful shutdown now.");
}
super.disconnected(ch);
}

View File

@ -26,7 +26,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.CopyOnWriteArraySet;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
/**
* ChannelListenerDispatcher
@ -70,7 +70,7 @@ public class ChannelHandlerDispatcher implements ChannelHandler {
try {
listener.connected(channel);
} catch (Throwable t) {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", t.getMessage(), t);
logger.error(INTERNAL_ERROR, "unknown error in remoting module", "", t.getMessage(), t);
}
}
}
@ -81,7 +81,7 @@ public class ChannelHandlerDispatcher implements ChannelHandler {
try {
listener.disconnected(channel);
} catch (Throwable t) {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", t.getMessage(), t);
logger.error(INTERNAL_ERROR, "unknown error in remoting module", "", t.getMessage(), t);
}
}
}
@ -92,7 +92,7 @@ public class ChannelHandlerDispatcher implements ChannelHandler {
try {
listener.sent(channel, message);
} catch (Throwable t) {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", t.getMessage(), t);
logger.error(INTERNAL_ERROR, "unknown error in remoting module", "", t.getMessage(), t);
}
}
}
@ -103,7 +103,7 @@ public class ChannelHandlerDispatcher implements ChannelHandler {
try {
listener.received(channel, message);
} catch (Throwable t) {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", t.getMessage(), t);
logger.error(INTERNAL_ERROR, "unknown error in remoting module", "", t.getMessage(), t);
}
}
}
@ -114,7 +114,7 @@ public class ChannelHandlerDispatcher implements ChannelHandler {
try {
listener.caught(channel, exception);
} catch (Throwable t) {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", t.getMessage(), t);
logger.error(INTERNAL_ERROR, "unknown error in remoting module", "", t.getMessage(), t);
}
}
}

View File

@ -23,7 +23,7 @@ import org.apache.dubbo.remoting.ChannelHandler;
import org.apache.dubbo.remoting.RemotingException;
import org.apache.dubbo.remoting.exchange.support.MultiMessage;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
/**
* @see MultiMessage
@ -45,11 +45,11 @@ public class MultiMessageHandler extends AbstractChannelHandlerDelegate {
try {
handler.received(channel, obj);
} catch (Throwable t) {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "MultiMessageHandler received fail.", t);
logger.error(INTERNAL_ERROR, "unknown error in remoting module", "", "MultiMessageHandler received fail.", t);
try {
handler.caught(channel, t);
} catch (Throwable t1) {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "MultiMessageHandler caught fail.", t1);
logger.error(INTERNAL_ERROR, "unknown error in remoting module", "", "MultiMessageHandler caught fail.", t1);
}
}
}

View File

@ -22,7 +22,7 @@ import org.apache.dubbo.common.threadlocal.InternalThreadLocal;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.ChannelHandler;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
public class ChannelEventRunnable implements Runnable {
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(ChannelEventRunnable.class);
@ -60,7 +60,7 @@ public class ChannelEventRunnable implements Runnable {
try {
handler.received(channel, message);
} catch (Exception e) {
logger.warn(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "ChannelEventRunnable handle " + state + " operation error, channel is " + channel
logger.warn(INTERNAL_ERROR, "unknown error in remoting module", "", "ChannelEventRunnable handle " + state + " operation error, channel is " + channel
+ ", message is " + message, e);
}
} else {
@ -69,21 +69,21 @@ public class ChannelEventRunnable implements Runnable {
try {
handler.connected(channel);
} catch (Exception e) {
logger.warn(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "ChannelEventRunnable handle " + state + " operation error, channel is " + channel, e);
logger.warn(INTERNAL_ERROR, "unknown error in remoting module", "", "ChannelEventRunnable handle " + state + " operation error, channel is " + channel, e);
}
break;
case DISCONNECTED:
try {
handler.disconnected(channel);
} catch (Exception e) {
logger.warn(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "ChannelEventRunnable handle " + state + " operation error, channel is " + channel, e);
logger.warn(INTERNAL_ERROR, "unknown error in remoting module", "", "ChannelEventRunnable handle " + state + " operation error, channel is " + channel, e);
}
break;
case SENT:
try {
handler.sent(channel, message);
} catch (Exception e) {
logger.warn(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "ChannelEventRunnable handle " + state + " operation error, channel is " + channel
logger.warn(INTERNAL_ERROR, "unknown error in remoting module", "", "ChannelEventRunnable handle " + state + " operation error, channel is " + channel
+ ", message is " + message, e);
}
break;
@ -91,12 +91,12 @@ public class ChannelEventRunnable implements Runnable {
try {
handler.caught(channel, exception);
} catch (Exception e) {
logger.warn(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "ChannelEventRunnable handle " + state + " operation error, channel is " + channel
logger.warn(INTERNAL_ERROR, "unknown error in remoting module", "", "ChannelEventRunnable handle " + state + " operation error, channel is " + channel
+ ", message is: " + message + ", exception is " + exception, e);
}
break;
default:
logger.warn(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "unknown state: " + state + ", message is " + message);
logger.warn(INTERNAL_ERROR, "unknown error in remoting module", "", "unknown state: " + state + ", message is " + message);
}
}
InternalThreadLocal.removeAll();

View File

@ -23,7 +23,7 @@ import org.jboss.netty.logging.AbstractInternalLogger;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
final class NettyHelper {
@ -44,6 +44,7 @@ final class NettyHelper {
static class DubboLogger extends AbstractInternalLogger {
public static final String LOGGER_CAUSE_STRING = "unknown error in remoting-netty module";
private ErrorTypeAwareLogger logger;
DubboLogger(ErrorTypeAwareLogger logger) {
@ -92,22 +93,22 @@ final class NettyHelper {
@Override
public void warn(String msg) {
logger.warn(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", msg);
logger.warn(INTERNAL_ERROR, LOGGER_CAUSE_STRING, "", msg);
}
@Override
public void warn(String msg, Throwable cause) {
logger.warn(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", msg, cause);
logger.warn(INTERNAL_ERROR, LOGGER_CAUSE_STRING, "", msg, cause);
}
@Override
public void error(String msg) {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", msg);
logger.error(INTERNAL_ERROR, LOGGER_CAUSE_STRING, "", msg);
}
@Override
public void error(String msg, Throwable cause) {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", msg, cause);
logger.error(INTERNAL_ERROR, LOGGER_CAUSE_STRING, "", msg, cause);
}
@Override

View File

@ -39,7 +39,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
public class NettyPortUnificationServerHandler extends ByteToMessageDecoder {
@ -71,7 +71,7 @@ public class NettyPortUnificationServerHandler extends ByteToMessageDecoder {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
LOGGER.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "Unexpected exception from downstream before protocol detected.", cause);
LOGGER.error(INTERNAL_ERROR, "unknown error in remoting module", "", "Unexpected exception from downstream before protocol detected.", cause);
}
@Override
@ -125,7 +125,7 @@ public class NettyPortUnificationServerHandler extends ByteToMessageDecoder {
Set<String> supported = url.getApplicationModel()
.getExtensionLoader(WireProtocol.class)
.getSupportedExtensions();
LOGGER.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", String.format("Can not recognize protocol from downstream=%s . "
LOGGER.error(INTERNAL_ERROR, "unknown error in remoting module", "", String.format("Can not recognize protocol from downstream=%s . "
+ "preface=%s protocols=%s", ctx.channel().remoteAddress(),
Bytes.bytes2hex(preface),
supported));

View File

@ -29,7 +29,7 @@ import io.netty.handler.ssl.SslHandshakeCompletionEvent;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSession;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
public class SslClientTlsHandler extends ChannelInboundHandlerAdapter {
@ -61,7 +61,7 @@ public class SslClientTlsHandler extends ChannelInboundHandlerAdapter {
logger.info("TLS negotiation succeed with session: " + session);
ctx.pipeline().remove(this);
} else {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "TLS negotiation failed when trying to accept new connection.", handshakeEvent.cause());
logger.error(INTERNAL_ERROR, "unknown error in remoting module", "", "TLS negotiation failed when trying to accept new connection.", handshakeEvent.cause());
ctx.fireExceptionCaught(handshakeEvent.cause());
}
}

View File

@ -31,7 +31,7 @@ import io.netty.handler.ssl.SslHandshakeCompletionEvent;
import javax.net.ssl.SSLSession;
import java.util.List;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
public class SslServerTlsHandler extends ByteToMessageDecoder {
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(SslServerTlsHandler.class);
@ -59,7 +59,7 @@ public class SslServerTlsHandler extends ByteToMessageDecoder {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "TLS negotiation failed when trying to accept new connection.", cause);
logger.error(INTERNAL_ERROR, "unknown error in remoting module", "", "TLS negotiation failed when trying to accept new connection.", cause);
}
@Override
@ -72,7 +72,7 @@ public class SslServerTlsHandler extends ByteToMessageDecoder {
// Remove after handshake success.
ctx.pipeline().remove(this);
} else {
logger.error(TRANSPORT_UNEXPECTED_EXCEPTION, "", "", "TLS negotiation failed when trying to accept new connection.", handshakeEvent.cause());
logger.error(INTERNAL_ERROR, "", "", "TLS negotiation failed when trying to accept new connection.", handshakeEvent.cause());
ctx.close();
}
}

View File

@ -29,7 +29,7 @@ import org.apache.dubbo.rpc.proxy.jdk.JdkProxyFactory;
import java.util.Arrays;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROXY_FAILED_JAVASSIST;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROXY_FAILED;
/**
* JavassistRpcProxyFactory
@ -47,13 +47,13 @@ public class JavassistProxyFactory extends AbstractProxyFactory {
// try fall back to JDK proxy factory
try {
T proxy = jdkProxyFactory.getProxy(invoker, interfaces);
logger.error(PROXY_FAILED_JAVASSIST, "", "", "Failed to generate proxy by Javassist failed. Fallback to use JDK proxy success. " +
logger.error(PROXY_FAILED, "", "", "Failed to generate proxy by Javassist failed. Fallback to use JDK proxy success. " +
"Interfaces: " + Arrays.toString(interfaces), fromJavassist);
return proxy;
} catch (Throwable fromJdk) {
logger.error(PROXY_FAILED_JAVASSIST, "", "", "Failed to generate proxy by Javassist failed. Fallback to use JDK proxy is also failed. " +
logger.error(PROXY_FAILED, "", "", "Failed to generate proxy by Javassist failed. Fallback to use JDK proxy is also failed. " +
"Interfaces: " + Arrays.toString(interfaces) + " Javassist Error.", fromJavassist);
logger.error(PROXY_FAILED_JAVASSIST, "", "", "Failed to generate proxy by Javassist failed. Fallback to use JDK proxy is also failed. " +
logger.error(PROXY_FAILED, "", "", "Failed to generate proxy by Javassist failed. Fallback to use JDK proxy is also failed. " +
"Interfaces: " + Arrays.toString(interfaces) + " JDK Error.", fromJdk);
throw fromJavassist;
}
@ -77,14 +77,14 @@ public class JavassistProxyFactory extends AbstractProxyFactory {
// try fall back to JDK proxy factory
try {
Invoker<T> invoker = jdkProxyFactory.getInvoker(proxy, type, url);
logger.error(PROXY_FAILED_JAVASSIST, "", "", "Failed to generate invoker by Javassist failed. Fallback to use JDK proxy success. " +
logger.error(PROXY_FAILED, "", "", "Failed to generate invoker by Javassist failed. Fallback to use JDK proxy success. " +
"Interfaces: " + type, fromJavassist);
// log out error
return invoker;
} catch (Throwable fromJdk) {
logger.error(PROXY_FAILED_JAVASSIST, "", "", "Failed to generate invoker by Javassist failed. Fallback to use JDK proxy is also failed. " +
logger.error(PROXY_FAILED, "", "", "Failed to generate invoker by Javassist failed. Fallback to use JDK proxy is also failed. " +
"Interfaces: " + type + " Javassist Error.", fromJavassist);
logger.error(PROXY_FAILED_JAVASSIST, "", "", "Failed to generate invoker by Javassist failed. Fallback to use JDK proxy is also failed. " +
logger.error(PROXY_FAILED, "", "", "Failed to generate invoker by Javassist failed. Fallback to use JDK proxy is also failed. " +
"Interfaces: " + type + " JDK Error.", fromJdk);
throw fromJavassist;
}

View File

@ -19,7 +19,6 @@ package org.apache.dubbo.rpc.protocol.tri.stream;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.rpc.TriRpcStatus;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.protocol.tri.TripleHeaderEnum;
@ -56,8 +55,6 @@ import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.concurrent.Executor;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_REFLECTIVE_OPERATION_FAILED;
/**
* ClientStream is an abstraction for bi-directional messaging. It maintains a {@link WriteQueue} to
@ -236,29 +233,10 @@ public class TripleClientStream extends AbstractStream implements ClientStream {
halfClosed = true;
final Map<String, String> reserved = filterReservedHeaders(trailers);
final Map<String, Object> attachments = headersToMap(trailers);
final Map<String, Object> finalAttachments = convertNoLowerCaseHeader(attachments);
listener.onComplete(status, finalAttachments, reserved);
}
private Map<String, Object> convertNoLowerCaseHeader(Map<String, Object> attachments) {
Object obj = attachments.remove(TripleHeaderEnum.TRI_HEADER_CONVERT.getHeader());
if (obj == null) {
return attachments;
}
if (obj instanceof String) {
String json = TriRpcStatus.decodeMessage((String) obj);
Map<String, String> map = JsonUtils.getJson().toJavaObject(json, Map.class);
map.forEach((originalKey, lowerCaseKey) -> {
Object val = attachments.remove(lowerCaseKey);
if (val != null) {
attachments.put(originalKey, val);
}
});
} else {
LOGGER.error(COMMON_REFLECTIVE_OPERATION_FAILED, "", "", "Triple convertNoLowerCaseHeader error, obj is not String");
}
return attachments;
final Map<String, Object> attachments = headersToMap(trailers, () -> {
return reserved.get(TripleHeaderEnum.TRI_HEADER_CONVERT.getHeader());
});
listener.onComplete(status, attachments, reserved);
}
private TriRpcStatus validateHeaderStatus(Http2Headers headers) {

View File

@ -402,7 +402,11 @@ public class TripleServerStream extends AbstractStream implements ServerStream {
}
}
Map<String, Object> requestMetadata = headersToMap(headers);
Map<String, Object> requestMetadata = headersToMap(headers, () -> {
return Optional.ofNullable(headers.get(TripleHeaderEnum.TRI_HEADER_CONVERT.getHeader()))
.map(CharSequence::toString)
.orElse(null);
});
boolean hasStub = pathResolver.hasNativeStub(path);
if (hasStub) {
listener = new StubAbstractServerCall(invoker, TripleServerStream.this,

View File

@ -19,6 +19,8 @@ package org.apache.dubbo.rpc.protocol.tri.transport;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.rpc.TriRpcStatus;
import org.apache.dubbo.rpc.protocol.tri.TripleConstant;
import org.apache.dubbo.rpc.protocol.tri.TripleHeaderEnum;
import org.apache.dubbo.rpc.protocol.tri.stream.StreamUtils;
@ -28,7 +30,9 @@ import io.netty.handler.codec.http2.Http2Headers;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_PARSE;
public abstract class AbstractH2TransportListener implements H2TransportListener {
@ -41,7 +45,7 @@ public abstract class AbstractH2TransportListener implements H2TransportListener
* @param trailers the metadata from remote
* @return KV pairs map
*/
protected Map<String, Object> headersToMap(Http2Headers trailers) {
protected Map<String, Object> headersToMap(Http2Headers trailers, Supplier<Object> convertUpperHeaderSupplier) {
if (trailers == null) {
return Collections.emptyMap();
}
@ -62,6 +66,27 @@ public abstract class AbstractH2TransportListener implements H2TransportListener
attachments.put(key, header.getValue().toString());
}
}
// try converting upper key
Object obj = convertUpperHeaderSupplier.get();
if (obj == null) {
return attachments;
}
if (obj instanceof String) {
String json = TriRpcStatus.decodeMessage((String) obj);
Map<String, String> map = JsonUtils.getJson().toJavaObject(json, Map.class);
for (Map.Entry<String, String> entry : map.entrySet()) {
Object val = attachments.remove(entry.getKey());
if (val != null) {
attachments.put(entry.getValue(), val);
}
}
} else {
// If convertUpperHeaderSupplier does not return String, just fail...
// Internal invocation, use INTERNAL_ERROR instead.
LOGGER.error(INTERNAL_ERROR, "wrong internal invocation", "", "Triple convertNoLowerCaseHeader error, obj is not String");
}
return attachments;
}
@ -73,9 +98,6 @@ public abstract class AbstractH2TransportListener implements H2TransportListener
Map<String, String> excludeHeaders = new HashMap<>(trailers.size());
for (Map.Entry<CharSequence, CharSequence> header : trailers) {
String key = header.getKey().toString();
if (Http2Headers.PseudoHeaderName.isPseudoHeader(key)) {
excludeHeaders.put(key, trailers.getAndRemove(key).toString());
}
if (TripleHeaderEnum.containsExcludeAttachments(key)) {
excludeHeaders.put(key, trailers.getAndRemove(key).toString());
}

View File

@ -50,10 +50,10 @@ class AbstractH2TransportListenerTest {
};
DefaultHttp2Headers headers = new DefaultHttp2Headers();
headers.scheme(HTTPS.name())
.path("/foo.bar")
.method(HttpMethod.POST.asciiName());
.path("/foo.bar")
.method(HttpMethod.POST.asciiName());
headers.set("foo", "bar");
final Map<String, Object> map = listener.headersToMap(headers);
final Map<String, Object> map = listener.headersToMap(headers, () -> null);
Assertions.assertEquals(4, map.size());
}