repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyServer.java
dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyServer.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.transport.netty; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.ChannelHandler; import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.remoting.RemotingException; import org.apache.dubbo.remoting.RemotingServer; import org.apache.dubbo.remoting.transport.AbstractServer; import org.apache.dubbo.remoting.transport.dispatcher.ChannelHandlers; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Collection; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.ChannelFactory; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipelineFactory; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; import static org.apache.dubbo.common.constants.CommonConstants.BACKLOG_KEY; import static org.apache.dubbo.common.constants.CommonConstants.IO_THREADS_KEY; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_CLOSE; import static org.apache.dubbo.remoting.Constants.EVENT_LOOP_BOSS_POOL_NAME; import static org.apache.dubbo.remoting.Constants.EVENT_LOOP_WORKER_POOL_NAME; public class NettyServer extends AbstractServer implements RemotingServer { private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(NettyServer.class); // <ip:port, channel> private Map<String, Channel> channels; private ServerBootstrap bootstrap; private org.jboss.netty.channel.Channel channel; public NettyServer(URL url, ChannelHandler handler) throws RemotingException { super(url, ChannelHandlers.wrap(handler, url)); } @Override protected void doOpen() throws Throwable { NettyHelper.setNettyLoggerFactory(); ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory(EVENT_LOOP_BOSS_POOL_NAME, true)); ExecutorService worker = Executors.newCachedThreadPool(new NamedThreadFactory(EVENT_LOOP_WORKER_POOL_NAME, true)); ChannelFactory channelFactory = new NioServerSocketChannelFactory( boss, worker, getUrl().getPositiveParameter(IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS)); bootstrap = new ServerBootstrap(channelFactory); final NettyHandler nettyHandler = new NettyHandler(getUrl(), this); // set channels channels = nettyHandler.getChannels(); // https://issues.jboss.org/browse/NETTY-365 // https://issues.jboss.org/browse/NETTY-379 // final Timer timer = new HashedWheelTimer(new NamedThreadFactory("NettyIdleTimer", true)); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("backlog", getUrl().getPositiveParameter(BACKLOG_KEY, Constants.DEFAULT_BACKLOG)); bootstrap.setOption("reuseAddress", true); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() { NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyServer.this); ChannelPipeline pipeline = Channels.pipeline(); /*int idleTimeout = getIdleTimeout(); if (idleTimeout > 10000) { pipeline.addLast("timer", new IdleStateHandler(timer, idleTimeout / 1000, 0, 0)); }*/ pipeline.addLast("decoder", adapter.getDecoder()); pipeline.addLast("encoder", adapter.getEncoder()); pipeline.addLast("handler", nettyHandler); return pipeline; } }); // bind channel = bootstrap.bind(getBindAddress()); } @Override protected void doClose() throws Throwable { try { if (channel != null) { // unbind. channel.close(); } } catch (Throwable e) { logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e); } try { Collection<org.apache.dubbo.remoting.Channel> channels = getChannels(); if (CollectionUtils.isNotEmpty(channels)) { for (org.apache.dubbo.remoting.Channel channel : channels) { try { channel.close(); } catch (Throwable e) { logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e); } } } } catch (Throwable e) { logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e); } try { if (bootstrap != null) { // release external resource. bootstrap.releaseExternalResources(); } } catch (Throwable e) { logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e); } try { if (channels != null) { channels.clear(); } } catch (Throwable e) { logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e); } } @Override protected int getChannelsSize() { return channels.size(); } @Override public Collection<Channel> getChannels() { Collection<Channel> chs = new ArrayList<>(this.channels.size()); // pick channels from NettyServerHandler ( needless to check connectivity ) chs.addAll(this.channels.values()); return chs; } @Override public Channel getChannel(InetSocketAddress remoteAddress) { return channels.get(NetUtils.toAddressString(remoteAddress)); } @Override public boolean isBound() { return channel.isBound(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyClient.java
dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyClient.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.transport.netty; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.Version; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.remoting.ChannelHandler; import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.remoting.RemotingException; import org.apache.dubbo.remoting.transport.AbstractClient; import java.net.InetSocketAddress; import java.nio.channels.ClosedChannelException; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import org.jboss.netty.bootstrap.ClientBootstrap; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelFactory; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipelineFactory; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_CLIENT_CONNECT_TIMEOUT; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_CONNECT_PROVIDER; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_DISCONNECT_PROVIDER; /** * NettyClient. */ public class NettyClient extends AbstractClient { // ChannelFactory's closure has a DirectMemory leak, using static to avoid // https://issues.jboss.org/browse/NETTY-424 private static final ChannelFactory CHANNEL_FACTORY = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(new NamedThreadFactory("NettyClientBoss", true)), Executors.newCachedThreadPool(new NamedThreadFactory("NettyClientWorker", true)), Constants.DEFAULT_IO_THREADS); private ClientBootstrap bootstrap; private volatile Channel channel; // volatile, please copy reference to use public NettyClient(final URL url, final ChannelHandler handler) throws RemotingException { super(url, wrapChannelHandler(url, handler)); } @Override protected void doOpen() throws Throwable { NettyHelper.setNettyLoggerFactory(); bootstrap = new ClientBootstrap(CHANNEL_FACTORY); // config // @see org.jboss.netty.channel.socket.SocketChannelConfig bootstrap.setOption("keepAlive", true); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("connectTimeoutMillis", getConnectTimeout()); final NettyHandler nettyHandler = new NettyHandler(getUrl(), this); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() { NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this); ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("decoder", adapter.getDecoder()); pipeline.addLast("encoder", adapter.getEncoder()); pipeline.addLast("handler", nettyHandler); return pipeline; } }); } @Override protected void doConnect() throws Throwable { long start = System.currentTimeMillis(); InetSocketAddress connectAddress = getConnectAddress(); ChannelFuture future = bootstrap.connect(connectAddress); long connectTimeout = getConnectTimeout(); long deadline = start + connectTimeout; try { while (true) { boolean ret = future.awaitUninterruptibly(connectTimeout, TimeUnit.MILLISECONDS); if (ret && future.isSuccess()) { Channel newChannel = future.getChannel(); newChannel.setInterestOps(Channel.OP_READ_WRITE); try { // copy reference Channel oldChannel = NettyClient.this.channel; if (oldChannel != null) { try { if (logger.isInfoEnabled()) { logger.info("Close old netty channel " + oldChannel + " on create new netty channel " + newChannel); } // Close old channel oldChannel.close(); } finally { NettyChannel.removeChannelIfDisconnected(oldChannel); } } } finally { if (NettyClient.this.isClosed()) { try { if (logger.isInfoEnabled()) { logger.info( "Close new netty channel " + newChannel + ", because the client closed."); } newChannel.close(); } finally { NettyClient.this.channel = null; NettyChannel.removeChannelIfDisconnected(newChannel); } } else { NettyClient.this.channel = newChannel; } } break; } else if (future.getCause() != null) { Throwable cause = future.getCause(); if (cause instanceof ClosedChannelException) { // Netty3.2.10 ClosedChannelException issue, see https://github.com/netty/netty/issues/138 connectTimeout = deadline - System.currentTimeMillis(); if (connectTimeout > 0) { // 6-1 - Retry connect to provider server by Netty3.2.10 ClosedChannelException issue#138. logger.warn( TRANSPORT_FAILED_CONNECT_PROVIDER, "Netty3.2.10 ClosedChannelException issue#138", "", "Retry connect to provider server."); future = bootstrap.connect(connectAddress); continue; } } RemotingException remotingException = new RemotingException( this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + ", error message is:" + cause.getMessage(), cause); // 6-1 - Failed to connect to provider server by other reason. logger.error( TRANSPORT_FAILED_CONNECT_PROVIDER, "network disconnected", "", "Failed to connect to provider server by other reason.", cause); throw remotingException; } else { RemotingException remotingException = new RemotingException( this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + " client-side timeout " + getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + "ms) from netty client " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion()); // 6-2 - Client-side timeout. logger.error( TRANSPORT_CLIENT_CONNECT_TIMEOUT, "provider crash", "", "Client-side timeout.", remotingException); throw remotingException; } } } finally { if (!isConnected()) { future.cancel(); } } } @Override protected void doDisConnect() throws Throwable { try { NettyChannel.removeChannelIfDisconnected(channel); } catch (Throwable t) { logger.warn(TRANSPORT_FAILED_DISCONNECT_PROVIDER, "", "", t.getMessage()); } } @Override protected void doClose() throws Throwable { /*try { bootstrap.releaseExternalResources(); } catch (Throwable t) { logger.warn(t.getMessage()); }*/ } @Override protected org.apache.dubbo.remoting.Channel getChannel() { Channel c = channel; if (c == null || !c.isConnected()) { return null; } return NettyChannel.getOrAddChannel(c, getUrl(), this); } Channel getNettyChannel() { return channel; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyPortUnificationTransporter.java
dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyPortUnificationTransporter.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.transport.netty; import org.apache.dubbo.common.URL; import org.apache.dubbo.remoting.ChannelHandler; import org.apache.dubbo.remoting.RemotingException; import org.apache.dubbo.remoting.api.connection.AbstractConnectionClient; import org.apache.dubbo.remoting.api.pu.AbstractPortUnificationServer; import org.apache.dubbo.remoting.api.pu.PortUnificationTransporter; public class NettyPortUnificationTransporter implements PortUnificationTransporter { public static final String NAME = "netty3"; @Override public AbstractPortUnificationServer bind(URL url, ChannelHandler handler) throws RemotingException { return new NettyPortUnificationServer(url, handler); } @Override public AbstractConnectionClient connect(URL url, ChannelHandler handler) throws RemotingException { throw new RemotingException(url.toInetSocketAddress(), null, "connectionManager for netty3 spi not found."); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyTransporter.java
dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyTransporter.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.transport.netty; import org.apache.dubbo.common.URL; import org.apache.dubbo.remoting.ChannelHandler; import org.apache.dubbo.remoting.Client; import org.apache.dubbo.remoting.RemotingException; import org.apache.dubbo.remoting.RemotingServer; import org.apache.dubbo.remoting.Transporter; public class NettyTransporter implements Transporter { public static final String NAME = "netty3"; @Override public RemotingServer bind(URL url, ChannelHandler handler) throws RemotingException { return new NettyServer(url, handler); } @Override public Client connect(URL url, ChannelHandler handler) throws RemotingException { return new NettyClient(url, handler); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHelper.java
dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHelper.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.transport.netty; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; 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.INTERNAL_ERROR; final class NettyHelper { public static void setNettyLoggerFactory() { InternalLoggerFactory factory = InternalLoggerFactory.getDefaultFactory(); if (!(factory instanceof DubboLoggerFactory)) { InternalLoggerFactory.setDefaultFactory(new DubboLoggerFactory()); } } static class DubboLoggerFactory extends InternalLoggerFactory { @Override public InternalLogger newInstance(String name) { return new DubboLogger(LoggerFactory.getErrorTypeAwareLogger(name)); } } static class DubboLogger extends AbstractInternalLogger { public static final String LOGGER_CAUSE_STRING = "unknown error in remoting-netty module"; private ErrorTypeAwareLogger logger; DubboLogger(ErrorTypeAwareLogger logger) { this.logger = logger; } @Override public boolean isDebugEnabled() { return logger.isDebugEnabled(); } @Override public boolean isInfoEnabled() { return logger.isInfoEnabled(); } @Override public boolean isWarnEnabled() { return logger.isWarnEnabled(); } @Override public boolean isErrorEnabled() { return logger.isErrorEnabled(); } @Override public void debug(String msg) { logger.debug(msg); } @Override public void debug(String msg, Throwable cause) { logger.debug(msg, cause); } @Override public void info(String msg) { logger.info(msg); } @Override public void info(String msg, Throwable cause) { logger.info(msg, cause); } @Override public void warn(String msg) { logger.warn(INTERNAL_ERROR, LOGGER_CAUSE_STRING, "", msg); } @Override public void warn(String msg, Throwable cause) { logger.warn(INTERNAL_ERROR, LOGGER_CAUSE_STRING, "", msg, cause); } @Override public void error(String msg) { logger.error(INTERNAL_ERROR, LOGGER_CAUSE_STRING, "", msg); } @Override public void error(String msg, Throwable cause) { logger.error(INTERNAL_ERROR, LOGGER_CAUSE_STRING, "", msg, cause); } @Override public String toString() { return logger.toString(); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyBackedChannelBufferFactory.java
dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyBackedChannelBufferFactory.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.transport.netty; import org.apache.dubbo.remoting.buffer.ChannelBuffer; import org.apache.dubbo.remoting.buffer.ChannelBufferFactory; import java.nio.ByteBuffer; import org.jboss.netty.buffer.ChannelBuffers; /** * Wrap netty dynamic channel buffer. */ public class NettyBackedChannelBufferFactory implements ChannelBufferFactory { private static final NettyBackedChannelBufferFactory INSTANCE = new NettyBackedChannelBufferFactory(); public static ChannelBufferFactory getInstance() { return INSTANCE; } @Override public ChannelBuffer getBuffer(int capacity) { return new NettyBackedChannelBuffer(ChannelBuffers.dynamicBuffer(capacity)); } @Override public ChannelBuffer getBuffer(byte[] array, int offset, int length) { org.jboss.netty.buffer.ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(length); buffer.writeBytes(array, offset, length); return new NettyBackedChannelBuffer(buffer); } @Override public ChannelBuffer getBuffer(ByteBuffer nioBuffer) { return new NettyBackedChannelBuffer(ChannelBuffers.wrappedBuffer(nioBuffer)); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHandler.java
dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHandler.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.transport.netty; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.ChannelHandler; import java.net.InetSocketAddress; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.jboss.netty.channel.ChannelHandler.Sharable; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.ExceptionEvent; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION; @Sharable public class NettyHandler extends SimpleChannelHandler { private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(NettyHandler.class); private final Map<String, Channel> channels = new ConcurrentHashMap<>(); // <ip:port, channel> private final URL url; private final ChannelHandler handler; public NettyHandler(URL url, ChannelHandler handler) { if (url == null) { throw new IllegalArgumentException("url == null"); } if (handler == null) { throw new IllegalArgumentException("handler == null"); } this.url = url; this.handler = handler; } public Map<String, Channel> getChannels() { return channels; } @Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { org.jboss.netty.channel.Channel ch = ctx.getChannel(); NettyChannel channel = NettyChannel.getOrAddChannel(ch, url, handler); try { if (channel != null) { channels.put(NetUtils.toAddressString((InetSocketAddress) ch.getRemoteAddress()), channel); } handler.connected(channel); } finally { NettyChannel.removeChannelIfDisconnected(ch); } if (logger.isInfoEnabled() && channel != null) { logger.info( "The connection {} between {} and {} is established.", ch, channel.getRemoteAddress(), channel.getLocalAddress()); } } @Override public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { org.jboss.netty.channel.Channel ch = ctx.getChannel(); NettyChannel channel = NettyChannel.getOrAddChannel(ch, url, handler); try { channels.remove(NetUtils.toAddressString((InetSocketAddress) ch.getRemoteAddress())); handler.disconnected(channel); } finally { NettyChannel.removeChannelIfDisconnected(ch); } if (logger.isInfoEnabled()) { logger.info( "The connection {} between {} and {} is disconnected.", ch, channel.getRemoteAddress(), channel.getLocalAddress()); } } @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler); try { handler.received(channel, e.getMessage()); } finally { NettyChannel.removeChannelIfDisconnected(ctx.getChannel()); } } @Override public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception { super.writeRequested(ctx, e); NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler); try { handler.sent(channel, e.getMessage()); } finally { NettyChannel.removeChannelIfDisconnected(ctx.getChannel()); } } @Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { org.jboss.netty.channel.Channel ch = ctx.getChannel(); NettyChannel channel = NettyChannel.getOrAddChannel(ch, url, handler); try { handler.caught(channel, e.getCause()); } finally { NettyChannel.removeChannelIfDisconnected(ch); } if (logger.isWarnEnabled()) { logger.warn( TRANSPORT_UNEXPECTED_EXCEPTION, "", "", channel == null ? String.format("The connection %s has exception.", ch) : String.format( "The connection %s between %s and %s has exception.", ch, channel.getRemoteAddress(), channel.getLocalAddress()), e.getCause()); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyChannel.java
dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyChannel.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.transport.netty; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.remoting.ChannelHandler; import org.apache.dubbo.remoting.RemotingException; import org.apache.dubbo.remoting.transport.AbstractChannel; import org.apache.dubbo.remoting.utils.PayloadDropper; import java.net.InetSocketAddress; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.jboss.netty.channel.ChannelFuture; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_CLOSE; /** * NettyChannel. */ final class NettyChannel extends AbstractChannel { private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(NettyChannel.class); private static final ConcurrentMap<org.jboss.netty.channel.Channel, NettyChannel> CHANNEL_MAP = new ConcurrentHashMap<>(); private final org.jboss.netty.channel.Channel channel; private final Map<String, Object> attributes = new ConcurrentHashMap<>(); private NettyChannel(org.jboss.netty.channel.Channel channel, URL url, ChannelHandler handler) { super(url, handler); if (channel == null) { throw new IllegalArgumentException("netty channel == null;"); } this.channel = channel; } static NettyChannel getOrAddChannel(org.jboss.netty.channel.Channel ch, URL url, ChannelHandler handler) { if (ch == null) { return null; } NettyChannel ret = CHANNEL_MAP.get(ch); if (ret == null) { NettyChannel nc = new NettyChannel(ch, url, handler); if (ch.isConnected()) { ret = CHANNEL_MAP.putIfAbsent(ch, nc); } if (ret == null) { ret = nc; } } return ret; } static void removeChannelIfDisconnected(org.jboss.netty.channel.Channel ch) { if (ch != null && !ch.isConnected()) { CHANNEL_MAP.remove(ch); } } @Override public InetSocketAddress getLocalAddress() { return (InetSocketAddress) channel.getLocalAddress(); } @Override public InetSocketAddress getRemoteAddress() { return (InetSocketAddress) channel.getRemoteAddress(); } @Override public boolean isConnected() { return channel.isConnected(); } @Override public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); boolean success = true; int timeout = 0; try { ChannelFuture future = channel.write(message); if (sent) { timeout = getUrl().getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT); success = future.await(timeout); } Throwable cause = future.getCause(); if (cause != null) { throw cause; } } catch (Throwable e) { throw new RemotingException( this, "Failed to send message " + PayloadDropper.getRequestWithoutData(message) + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } if (!success) { throw new RemotingException( this, "Failed to send message " + PayloadDropper.getRequestWithoutData(message) + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit"); } } @Override public void close() { try { super.close(); } catch (Exception e) { logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e); } try { removeChannelIfDisconnected(channel); } catch (Exception e) { logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e); } try { attributes.clear(); } catch (Exception e) { logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e); } try { if (logger.isInfoEnabled()) { logger.info("Close netty channel " + channel); } channel.close(); } catch (Exception e) { logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e); } } @Override public boolean hasAttribute(String key) { return attributes.containsKey(key); } @Override public Object getAttribute(String key) { return attributes.get(key); } @Override public void setAttribute(String key, Object value) { if (value == null) { // The null value unallowed in the ConcurrentHashMap. attributes.remove(key); } else { attributes.put(key, value); } } @Override public void removeAttribute(String key) { attributes.remove(key); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((channel == null) ? 0 : channel.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } // FIXME: a hack to make org.apache.dubbo.remoting.exchange.support.DefaultFuture.closeChannel work if (obj instanceof NettyClient) { NettyClient client = (NettyClient) obj; return channel.equals(client.getNettyChannel()); } if (getClass() != obj.getClass()) { return false; } NettyChannel other = (NettyChannel) obj; if (channel == null) { if (other.channel != null) { return false; } } else if (!channel.equals(other.channel)) { return false; } return true; } @Override public String toString() { return "NettyChannel [channel=" + channel + "]"; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/Http3SslContexts.java
dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/Http3SslContexts.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http3; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.ssl.AuthPolicy; import org.apache.dubbo.common.ssl.Cert; import org.apache.dubbo.common.ssl.CertManager; import org.apache.dubbo.common.ssl.ProviderCert; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLSessionContext; import java.io.InputStream; import java.util.List; import io.netty.buffer.ByteBufAllocator; import io.netty.handler.codec.http3.Http3; import io.netty.handler.codec.quic.QuicSslContext; import io.netty.handler.codec.quic.QuicSslContextBuilder; import io.netty.handler.ssl.ApplicationProtocolNegotiator; import io.netty.handler.ssl.ClientAuth; import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import io.netty.handler.ssl.util.SelfSignedCertificate; public final class Http3SslContexts extends SslContext { private static final ErrorTypeAwareLogger LOGGER = LoggerFactory.getErrorTypeAwareLogger(Http3SslContexts.class); private Http3SslContexts() {} public static QuicSslContext buildServerSslContext(URL url) { CertManager certManager = getCertManager(url); ProviderCert cert = certManager.getProviderConnectionConfig(url, url.toInetSocketAddress()); if (cert == null) { return buildSelfSignedServerSslContext(url); } QuicSslContextBuilder builder; try { try (InputStream privateKeyIn = cert.getPrivateKeyInputStream(); InputStream keyCertChainIn = cert.getKeyCertChainInputStream()) { if (keyCertChainIn == null || privateKeyIn == null) { return buildSelfSignedServerSslContext(url); } builder = QuicSslContextBuilder.forServer( toPrivateKey(privateKeyIn, cert.getPassword()), cert.getPassword(), toX509Certificates(keyCertChainIn)); try (InputStream trustCertIn = cert.getTrustCertInputStream()) { if (trustCertIn != null) { ClientAuth clientAuth = cert.getAuthPolicy() == AuthPolicy.CLIENT_AUTH ? ClientAuth.REQUIRE : ClientAuth.OPTIONAL; builder.trustManager(toX509Certificates(trustCertIn)).clientAuth(clientAuth); } } } } catch (IllegalStateException t) { throw t; } catch (Throwable t) { throw new IllegalArgumentException("Could not find certificate file or the certificate is invalid.", t); } try { return builder.applicationProtocols(Http3.supportedApplicationProtocols()) .build(); } catch (Throwable t) { throw new IllegalStateException("Build SslSession failed.", t); } } @SuppressWarnings("DataFlowIssue") private static QuicSslContext buildSelfSignedServerSslContext(URL url) { LOGGER.info("Provider cert not configured, build self signed sslContext, url=[{}]", url.toString("")); SelfSignedCertificate certificate; try { certificate = new SelfSignedCertificate(); } catch (Throwable e) { throw new IllegalStateException("Failed to create self signed certificate, Please import bcpkix jar", e); } return QuicSslContextBuilder.forServer(certificate.privateKey(), null, certificate.certificate()) .applicationProtocols(Http3.supportedApplicationProtocols()) .build(); } public static QuicSslContext buildClientSslContext(URL url) { CertManager certManager = getCertManager(url); Cert cert = certManager.getConsumerConnectionConfig(url); QuicSslContextBuilder builder = QuicSslContextBuilder.forClient(); try { if (cert == null) { LOGGER.info("Consumer cert not configured, build insecure sslContext, url=[{}]", url.toString("")); builder.trustManager(InsecureTrustManagerFactory.INSTANCE); } else { try (InputStream trustCertIn = cert.getTrustCertInputStream(); InputStream privateKeyIn = cert.getPrivateKeyInputStream(); InputStream keyCertChainIn = cert.getKeyCertChainInputStream()) { if (trustCertIn != null) { builder.trustManager(toX509Certificates(trustCertIn)); } builder.keyManager( toPrivateKey(privateKeyIn, cert.getPassword()), cert.getPassword(), toX509Certificates(keyCertChainIn)); } } } catch (Throwable t) { throw new IllegalArgumentException("Could not find certificate file or the certificate is invalid.", t); } try { return builder.applicationProtocols(Http3.supportedApplicationProtocols()) .build(); } catch (Throwable t) { throw new IllegalStateException("Build SslSession failed.", t); } } private static CertManager getCertManager(URL url) { return url.getOrDefaultFrameworkModel().getBeanFactory().getBean(CertManager.class); } @Override public boolean isClient() { throw new UnsupportedOperationException(); } @Override public List<String> cipherSuites() { throw new UnsupportedOperationException(); } @Override @SuppressWarnings("deprecation") public ApplicationProtocolNegotiator applicationProtocolNegotiator() { throw new UnsupportedOperationException(); } @Override public SSLEngine newEngine(ByteBufAllocator alloc) { throw new UnsupportedOperationException(); } @Override public SSLEngine newEngine(ByteBufAllocator alloc, String peerHost, int peerPort) { throw new UnsupportedOperationException(); } @Override public SSLSessionContext sessionContext() { throw new UnsupportedOperationException(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/Http3TransportListener.java
dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/Http3TransportListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http3; import org.apache.dubbo.remoting.http12.h2.Http2TransportListener; public interface Http3TransportListener extends Http2TransportListener {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/Http3ServerTransportListenerFactory.java
dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/Http3ServerTransportListenerFactory.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http3; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionScope; import org.apache.dubbo.common.extension.SPI; import org.apache.dubbo.remoting.http12.h2.H2StreamChannel; import org.apache.dubbo.rpc.model.FrameworkModel; @SPI(scope = ExtensionScope.FRAMEWORK) public interface Http3ServerTransportListenerFactory { Http3TransportListener newInstance(H2StreamChannel streamChannel, URL url, FrameworkModel frameworkModel); boolean supportContentType(String contentType); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/netty4/NettyHttp3ProtocolSelectorHandler.java
dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/netty4/NettyHttp3ProtocolSelectorHandler.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http3.netty4; import org.apache.dubbo.common.URL; import org.apache.dubbo.remoting.http12.HttpMetadata; import org.apache.dubbo.remoting.http12.command.HttpWriteQueue; import org.apache.dubbo.remoting.http12.exception.UnsupportedMediaTypeException; import org.apache.dubbo.remoting.http12.h2.H2StreamChannel; import org.apache.dubbo.remoting.http12.h2.command.Http2WriteQueueChannel; import org.apache.dubbo.remoting.http12.netty4.HttpWriteQueueHandler; import org.apache.dubbo.remoting.http12.netty4.h2.NettyHttp2FrameHandler; import org.apache.dubbo.remoting.http3.Http3ServerTransportListenerFactory; import org.apache.dubbo.rpc.model.FrameworkModel; import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPipeline; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.quic.QuicStreamChannel; @Sharable public class NettyHttp3ProtocolSelectorHandler extends SimpleChannelInboundHandler<HttpMetadata> { private final URL url; private final FrameworkModel frameworkModel; public NettyHttp3ProtocolSelectorHandler(URL url, FrameworkModel frameworkModel) { this.url = url; this.frameworkModel = frameworkModel; } @Override protected void channelRead0(ChannelHandlerContext ctx, HttpMetadata metadata) { String contentType = metadata.contentType(); Http3ServerTransportListenerFactory factory = determineHttp3ServerTransportListenerFactory(contentType); if (factory == null) { throw new UnsupportedMediaTypeException(contentType); } H2StreamChannel streamChannel = new NettyHttp3StreamChannel((QuicStreamChannel) ctx.channel()); HttpWriteQueueHandler writeQueueHandler = ctx.channel().pipeline().get(HttpWriteQueueHandler.class); if (writeQueueHandler != null) { HttpWriteQueue writeQueue = writeQueueHandler.getWriteQueue(); streamChannel = new Http2WriteQueueChannel(streamChannel, writeQueue); } ChannelPipeline pipeline = ctx.pipeline(); pipeline.addLast( new NettyHttp2FrameHandler(streamChannel, factory.newInstance(streamChannel, url, frameworkModel))); pipeline.remove(this); ctx.fireChannelRead(metadata); } private Http3ServerTransportListenerFactory determineHttp3ServerTransportListenerFactory(String contentType) { for (Http3ServerTransportListenerFactory factory : frameworkModel.getActivateExtensions(Http3ServerTransportListenerFactory.class)) { if (factory.supportContentType(contentType)) { return factory; } } return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/netty4/Http3HeadersAdapter.java
dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/netty4/Http3HeadersAdapter.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http3.netty4; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; import java.util.Set; import java.util.Spliterator; import java.util.function.Consumer; import io.netty.handler.codec.Headers; import io.netty.handler.codec.http2.Http2Headers; import io.netty.handler.codec.http3.Http3Headers; public final class Http3HeadersAdapter implements Http3Headers { private final Http2Headers headers; public Http3HeadersAdapter(Http2Headers headers) { this.headers = headers; } @Override public Iterator<Entry<CharSequence, CharSequence>> iterator() { return headers.iterator(); } @Override public Iterator<CharSequence> valueIterator(CharSequence name) { return headers.valueIterator(name); } @Override public Http3Headers method(CharSequence value) { headers.method(value); return this; } @Override public Http3Headers scheme(CharSequence value) { headers.scheme(value); return this; } @Override public Http3Headers authority(CharSequence value) { headers.authority(value); return this; } @Override public Http3Headers path(CharSequence value) { headers.path(value); return this; } @Override public Http3Headers status(CharSequence value) { headers.status(value); return this; } @Override public CharSequence method() { return headers.method(); } @Override public CharSequence scheme() { return headers.scheme(); } @Override public CharSequence authority() { return headers.authority(); } @Override public CharSequence path() { return headers.path(); } @Override public CharSequence status() { return headers.status(); } @Override public boolean contains(CharSequence name, CharSequence value, boolean caseInsensitive) { return headers.contains(name, value, caseInsensitive); } @Override public CharSequence get(CharSequence charSequence) { return headers.get(charSequence); } @Override public CharSequence get(CharSequence charSequence, CharSequence charSequence2) { return headers.get(charSequence, charSequence2); } @Override public CharSequence getAndRemove(CharSequence charSequence) { return headers.getAndRemove(charSequence); } @Override public CharSequence getAndRemove(CharSequence charSequence, CharSequence charSequence2) { return headers.getAndRemove(charSequence, charSequence2); } @Override public List<CharSequence> getAll(CharSequence charSequence) { return headers.getAll(charSequence); } @Override public List<CharSequence> getAllAndRemove(CharSequence charSequence) { return headers.getAllAndRemove(charSequence); } @Override public Boolean getBoolean(CharSequence charSequence) { return headers.getBoolean(charSequence); } @Override public boolean getBoolean(CharSequence charSequence, boolean b) { return headers.getBoolean(charSequence, b); } @Override public Byte getByte(CharSequence charSequence) { return headers.getByte(charSequence); } @Override public byte getByte(CharSequence charSequence, byte b) { return headers.getByte(charSequence, b); } @Override public Character getChar(CharSequence charSequence) { return headers.getChar(charSequence); } @Override public char getChar(CharSequence charSequence, char c) { return headers.getChar(charSequence, c); } @Override public Short getShort(CharSequence charSequence) { return headers.getShort(charSequence); } @Override public short getShort(CharSequence charSequence, short i) { return headers.getShort(charSequence, i); } @Override public Integer getInt(CharSequence charSequence) { return headers.getInt(charSequence); } @Override public int getInt(CharSequence charSequence, int i) { return headers.getInt(charSequence, i); } @Override public Long getLong(CharSequence charSequence) { return headers.getLong(charSequence); } @Override public long getLong(CharSequence charSequence, long l) { return headers.getLong(charSequence, l); } @Override public Float getFloat(CharSequence charSequence) { return headers.getFloat(charSequence); } @Override public float getFloat(CharSequence charSequence, float v) { return headers.getFloat(charSequence, v); } @Override public Double getDouble(CharSequence charSequence) { return headers.getDouble(charSequence); } @Override public double getDouble(CharSequence charSequence, double v) { return headers.getDouble(charSequence, v); } @Override public Long getTimeMillis(CharSequence charSequence) { return headers.getTimeMillis(charSequence); } @Override public long getTimeMillis(CharSequence charSequence, long l) { return headers.getTimeMillis(charSequence, l); } @Override public Boolean getBooleanAndRemove(CharSequence charSequence) { return headers.getBooleanAndRemove(charSequence); } @Override public boolean getBooleanAndRemove(CharSequence charSequence, boolean b) { return headers.getBooleanAndRemove(charSequence, b); } @Override public Byte getByteAndRemove(CharSequence charSequence) { return headers.getByteAndRemove(charSequence); } @Override public byte getByteAndRemove(CharSequence charSequence, byte b) { return headers.getByteAndRemove(charSequence, b); } @Override public Character getCharAndRemove(CharSequence charSequence) { return headers.getCharAndRemove(charSequence); } @Override public char getCharAndRemove(CharSequence charSequence, char c) { return headers.getCharAndRemove(charSequence, c); } @Override public Short getShortAndRemove(CharSequence charSequence) { return headers.getShortAndRemove(charSequence); } @Override public short getShortAndRemove(CharSequence charSequence, short i) { return headers.getShortAndRemove(charSequence, i); } @Override public Integer getIntAndRemove(CharSequence charSequence) { return headers.getIntAndRemove(charSequence); } @Override public int getIntAndRemove(CharSequence charSequence, int i) { return headers.getIntAndRemove(charSequence, i); } @Override public Long getLongAndRemove(CharSequence charSequence) { return headers.getLongAndRemove(charSequence); } @Override public long getLongAndRemove(CharSequence charSequence, long l) { return headers.getLongAndRemove(charSequence, l); } @Override public Float getFloatAndRemove(CharSequence charSequence) { return headers.getFloatAndRemove(charSequence); } @Override public float getFloatAndRemove(CharSequence charSequence, float v) { return headers.getFloatAndRemove(charSequence, v); } @Override public Double getDoubleAndRemove(CharSequence charSequence) { return headers.getDoubleAndRemove(charSequence); } @Override public double getDoubleAndRemove(CharSequence charSequence, double v) { return headers.getDoubleAndRemove(charSequence, v); } @Override public Long getTimeMillisAndRemove(CharSequence charSequence) { return headers.getTimeMillisAndRemove(charSequence); } @Override public long getTimeMillisAndRemove(CharSequence charSequence, long l) { return headers.getTimeMillisAndRemove(charSequence, l); } @Override public boolean contains(CharSequence charSequence) { return headers.contains(charSequence); } @Override public boolean contains(CharSequence charSequence, CharSequence charSequence2) { return headers.contains(charSequence, charSequence2); } @Override public boolean containsObject(CharSequence charSequence, Object o) { return headers.containsObject(charSequence, o); } @Override public boolean containsBoolean(CharSequence charSequence, boolean b) { return headers.containsBoolean(charSequence, b); } @Override public boolean containsByte(CharSequence charSequence, byte b) { return headers.containsByte(charSequence, b); } @Override public boolean containsChar(CharSequence charSequence, char c) { return headers.containsChar(charSequence, c); } @Override public boolean containsShort(CharSequence charSequence, short i) { return headers.containsShort(charSequence, i); } @Override public boolean containsInt(CharSequence charSequence, int i) { return headers.containsInt(charSequence, i); } @Override public boolean containsLong(CharSequence charSequence, long l) { return headers.containsLong(charSequence, l); } @Override public boolean containsFloat(CharSequence charSequence, float v) { return headers.containsFloat(charSequence, v); } @Override public boolean containsDouble(CharSequence charSequence, double v) { return headers.containsDouble(charSequence, v); } @Override public boolean containsTimeMillis(CharSequence charSequence, long l) { return headers.containsTimeMillis(charSequence, l); } @Override public int size() { return headers.size(); } @Override public boolean isEmpty() { return headers.isEmpty(); } @Override public Set<CharSequence> names() { return headers.names(); } @Override public Http3Headers add(CharSequence charSequence, CharSequence charSequence2) { headers.add(charSequence, charSequence2); return this; } @Override public Http3Headers add(CharSequence charSequence, Iterable<? extends CharSequence> iterable) { headers.add(charSequence, iterable); return this; } @Override public Http3Headers add(CharSequence charSequence, CharSequence... charSequences) { headers.add(charSequence, charSequences); return this; } @Override public Http3Headers addObject(CharSequence charSequence, Object o) { headers.addObject(charSequence, o); return this; } @Override public Http3Headers addObject(CharSequence charSequence, Iterable<?> iterable) { headers.addObject(charSequence, iterable); return this; } @Override public Http3Headers addObject(CharSequence charSequence, Object... objects) { headers.addObject(charSequence, objects); return this; } @Override public Http3Headers addBoolean(CharSequence charSequence, boolean b) { headers.addBoolean(charSequence, b); return this; } @Override public Http3Headers addByte(CharSequence charSequence, byte b) { headers.addByte(charSequence, b); return this; } @Override public Http3Headers addChar(CharSequence charSequence, char c) { headers.addChar(charSequence, c); return this; } @Override public Http3Headers addShort(CharSequence charSequence, short i) { headers.addShort(charSequence, i); return this; } @Override public Http3Headers addInt(CharSequence charSequence, int i) { headers.addInt(charSequence, i); return this; } @Override public Http3Headers addLong(CharSequence charSequence, long l) { headers.addLong(charSequence, l); return this; } @Override public Http3Headers addFloat(CharSequence charSequence, float v) { headers.addFloat(charSequence, v); return this; } @Override public Http3Headers addDouble(CharSequence charSequence, double v) { headers.addDouble(charSequence, v); return this; } @Override public Http3Headers addTimeMillis(CharSequence charSequence, long l) { headers.addTimeMillis(charSequence, l); return this; } @Override public Http3Headers add(Headers<? extends CharSequence, ? extends CharSequence, ?> headers) { this.headers.add(headers); return this; } @Override public Http3Headers set(CharSequence charSequence, CharSequence charSequence2) { headers.set(charSequence, charSequence2); return this; } @Override public Http3Headers set(CharSequence charSequence, Iterable<? extends CharSequence> iterable) { headers.set(charSequence, iterable); return this; } @Override public Http3Headers set(CharSequence charSequence, CharSequence... charSequences) { headers.set(charSequence, charSequences); return this; } @Override public Http3Headers setObject(CharSequence charSequence, Object o) { headers.setObject(charSequence, o); return this; } @Override public Http3Headers setObject(CharSequence charSequence, Iterable<?> iterable) { headers.setObject(charSequence, iterable); return this; } @Override public Http3Headers setObject(CharSequence charSequence, Object... objects) { headers.setObject(charSequence, objects); return this; } @Override public Http3Headers setBoolean(CharSequence charSequence, boolean b) { headers.setBoolean(charSequence, b); return this; } @Override public Http3Headers setByte(CharSequence charSequence, byte b) { headers.setByte(charSequence, b); return this; } @Override public Http3Headers setChar(CharSequence charSequence, char c) { headers.setChar(charSequence, c); return this; } @Override public Http3Headers setShort(CharSequence charSequence, short i) { headers.setShort(charSequence, i); return this; } @Override public Http3Headers setInt(CharSequence charSequence, int i) { headers.setInt(charSequence, i); return this; } @Override public Http3Headers setLong(CharSequence charSequence, long l) { headers.setLong(charSequence, l); return this; } @Override public Http3Headers setFloat(CharSequence charSequence, float v) { headers.setFloat(charSequence, v); return this; } @Override public Http3Headers setDouble(CharSequence charSequence, double v) { headers.setDouble(charSequence, v); return this; } @Override public Http3Headers setTimeMillis(CharSequence charSequence, long l) { headers.setTimeMillis(charSequence, l); return this; } @Override public Http3Headers set(Headers<? extends CharSequence, ? extends CharSequence, ?> headers) { this.headers.set(headers); return this; } @Override public Http3Headers setAll(Headers<? extends CharSequence, ? extends CharSequence, ?> headers) { this.headers.setAll(headers); return this; } @Override public boolean remove(CharSequence charSequence) { return headers.remove(charSequence); } @Override public Http3Headers clear() { headers.clear(); return this; } @Override public void forEach(Consumer<? super Entry<CharSequence, CharSequence>> action) { headers.forEach(action); } @Override public Spliterator<Entry<CharSequence, CharSequence>> spliterator() { return headers.spliterator(); } @Override public int hashCode() { return headers.hashCode(); } @Override public boolean equals(Object obj) { return this == obj || obj instanceof Http3Headers && headers.equals(obj); } @Override public String toString() { return "Http3HeadersAdapter{headers=" + headers + '}'; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/netty4/Http2HeadersAdapter.java
dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/netty4/Http2HeadersAdapter.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http3.netty4; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; import java.util.Set; import java.util.Spliterator; import java.util.function.Consumer; import io.netty.handler.codec.Headers; import io.netty.handler.codec.http2.Http2Headers; import io.netty.handler.codec.http3.Http3Headers; public final class Http2HeadersAdapter implements Http2Headers { private final Http3Headers headers; public Http2HeadersAdapter(Http3Headers headers) { this.headers = headers; } @Override public Iterator<Entry<CharSequence, CharSequence>> iterator() { return headers.iterator(); } @Override public Iterator<CharSequence> valueIterator(CharSequence name) { return headers.valueIterator(name); } @Override public Http2Headers method(CharSequence value) { headers.method(value); return this; } @Override public Http2Headers scheme(CharSequence value) { headers.scheme(value); return this; } @Override public Http2Headers authority(CharSequence value) { headers.authority(value); return this; } @Override public Http2Headers path(CharSequence value) { headers.path(value); return this; } @Override public Http2Headers status(CharSequence value) { headers.status(value); return this; } @Override public CharSequence method() { return headers.method(); } @Override public CharSequence scheme() { return headers.scheme(); } @Override public CharSequence authority() { return headers.authority(); } @Override public CharSequence path() { return headers.path(); } @Override public CharSequence status() { return headers.status(); } @Override public boolean contains(CharSequence name, CharSequence value, boolean caseInsensitive) { return headers.contains(name, value, caseInsensitive); } @Override public CharSequence get(CharSequence charSequence) { return headers.get(charSequence); } @Override public CharSequence get(CharSequence charSequence, CharSequence charSequence2) { return headers.get(charSequence, charSequence2); } @Override public CharSequence getAndRemove(CharSequence charSequence) { return headers.getAndRemove(charSequence); } @Override public CharSequence getAndRemove(CharSequence charSequence, CharSequence charSequence2) { return headers.getAndRemove(charSequence, charSequence2); } @Override public List<CharSequence> getAll(CharSequence charSequence) { return headers.getAll(charSequence); } @Override public List<CharSequence> getAllAndRemove(CharSequence charSequence) { return headers.getAllAndRemove(charSequence); } @Override public Boolean getBoolean(CharSequence charSequence) { return headers.getBoolean(charSequence); } @Override public boolean getBoolean(CharSequence charSequence, boolean b) { return headers.getBoolean(charSequence, b); } @Override public Byte getByte(CharSequence charSequence) { return headers.getByte(charSequence); } @Override public byte getByte(CharSequence charSequence, byte b) { return headers.getByte(charSequence, b); } @Override public Character getChar(CharSequence charSequence) { return headers.getChar(charSequence); } @Override public char getChar(CharSequence charSequence, char c) { return headers.getChar(charSequence, c); } @Override public Short getShort(CharSequence charSequence) { return headers.getShort(charSequence); } @Override public short getShort(CharSequence charSequence, short i) { return headers.getShort(charSequence, i); } @Override public Integer getInt(CharSequence charSequence) { return headers.getInt(charSequence); } @Override public int getInt(CharSequence charSequence, int i) { return headers.getInt(charSequence, i); } @Override public Long getLong(CharSequence charSequence) { return headers.getLong(charSequence); } @Override public long getLong(CharSequence charSequence, long l) { return headers.getLong(charSequence, l); } @Override public Float getFloat(CharSequence charSequence) { return headers.getFloat(charSequence); } @Override public float getFloat(CharSequence charSequence, float v) { return headers.getFloat(charSequence, v); } @Override public Double getDouble(CharSequence charSequence) { return headers.getDouble(charSequence); } @Override public double getDouble(CharSequence charSequence, double v) { return headers.getDouble(charSequence, v); } @Override public Long getTimeMillis(CharSequence charSequence) { return headers.getTimeMillis(charSequence); } @Override public long getTimeMillis(CharSequence charSequence, long l) { return headers.getTimeMillis(charSequence, l); } @Override public Boolean getBooleanAndRemove(CharSequence charSequence) { return headers.getBooleanAndRemove(charSequence); } @Override public boolean getBooleanAndRemove(CharSequence charSequence, boolean b) { return headers.getBooleanAndRemove(charSequence, b); } @Override public Byte getByteAndRemove(CharSequence charSequence) { return headers.getByteAndRemove(charSequence); } @Override public byte getByteAndRemove(CharSequence charSequence, byte b) { return headers.getByteAndRemove(charSequence, b); } @Override public Character getCharAndRemove(CharSequence charSequence) { return headers.getCharAndRemove(charSequence); } @Override public char getCharAndRemove(CharSequence charSequence, char c) { return headers.getCharAndRemove(charSequence, c); } @Override public Short getShortAndRemove(CharSequence charSequence) { return headers.getShortAndRemove(charSequence); } @Override public short getShortAndRemove(CharSequence charSequence, short i) { return headers.getShortAndRemove(charSequence, i); } @Override public Integer getIntAndRemove(CharSequence charSequence) { return headers.getIntAndRemove(charSequence); } @Override public int getIntAndRemove(CharSequence charSequence, int i) { return headers.getIntAndRemove(charSequence, i); } @Override public Long getLongAndRemove(CharSequence charSequence) { return headers.getLongAndRemove(charSequence); } @Override public long getLongAndRemove(CharSequence charSequence, long l) { return headers.getLongAndRemove(charSequence, l); } @Override public Float getFloatAndRemove(CharSequence charSequence) { return headers.getFloatAndRemove(charSequence); } @Override public float getFloatAndRemove(CharSequence charSequence, float v) { return headers.getFloatAndRemove(charSequence, v); } @Override public Double getDoubleAndRemove(CharSequence charSequence) { return headers.getDoubleAndRemove(charSequence); } @Override public double getDoubleAndRemove(CharSequence charSequence, double v) { return headers.getDoubleAndRemove(charSequence, v); } @Override public Long getTimeMillisAndRemove(CharSequence charSequence) { return headers.getTimeMillisAndRemove(charSequence); } @Override public long getTimeMillisAndRemove(CharSequence charSequence, long l) { return headers.getTimeMillisAndRemove(charSequence, l); } @Override public boolean contains(CharSequence charSequence) { return headers.contains(charSequence); } @Override public boolean contains(CharSequence charSequence, CharSequence charSequence2) { return headers.contains(charSequence, charSequence2); } @Override public boolean containsObject(CharSequence charSequence, Object o) { return headers.containsObject(charSequence, o); } @Override public boolean containsBoolean(CharSequence charSequence, boolean b) { return headers.containsBoolean(charSequence, b); } @Override public boolean containsByte(CharSequence charSequence, byte b) { return headers.containsByte(charSequence, b); } @Override public boolean containsChar(CharSequence charSequence, char c) { return headers.containsChar(charSequence, c); } @Override public boolean containsShort(CharSequence charSequence, short i) { return headers.containsShort(charSequence, i); } @Override public boolean containsInt(CharSequence charSequence, int i) { return headers.containsInt(charSequence, i); } @Override public boolean containsLong(CharSequence charSequence, long l) { return headers.containsLong(charSequence, l); } @Override public boolean containsFloat(CharSequence charSequence, float v) { return headers.containsFloat(charSequence, v); } @Override public boolean containsDouble(CharSequence charSequence, double v) { return headers.containsDouble(charSequence, v); } @Override public boolean containsTimeMillis(CharSequence charSequence, long l) { return headers.containsTimeMillis(charSequence, l); } @Override public int size() { return headers.size(); } @Override public boolean isEmpty() { return headers.isEmpty(); } @Override public Set<CharSequence> names() { return headers.names(); } @Override public Http2Headers add(CharSequence charSequence, CharSequence charSequence2) { headers.add(charSequence, charSequence2); return this; } @Override public Http2Headers add(CharSequence charSequence, Iterable<? extends CharSequence> iterable) { headers.add(charSequence, iterable); return this; } @Override public Http2Headers add(CharSequence charSequence, CharSequence... charSequences) { headers.add(charSequence, charSequences); return this; } @Override public Http2Headers addObject(CharSequence charSequence, Object o) { headers.addObject(charSequence, o); return this; } @Override public Http2Headers addObject(CharSequence charSequence, Iterable<?> iterable) { headers.addObject(charSequence, iterable); return this; } @Override public Http2Headers addObject(CharSequence charSequence, Object... objects) { headers.addObject(charSequence, objects); return this; } @Override public Http2Headers addBoolean(CharSequence charSequence, boolean b) { headers.addBoolean(charSequence, b); return this; } @Override public Http2Headers addByte(CharSequence charSequence, byte b) { headers.addByte(charSequence, b); return this; } @Override public Http2Headers addChar(CharSequence charSequence, char c) { headers.addChar(charSequence, c); return this; } @Override public Http2Headers addShort(CharSequence charSequence, short i) { headers.addShort(charSequence, i); return this; } @Override public Http2Headers addInt(CharSequence charSequence, int i) { headers.addInt(charSequence, i); return this; } @Override public Http2Headers addLong(CharSequence charSequence, long l) { headers.addLong(charSequence, l); return this; } @Override public Http2Headers addFloat(CharSequence charSequence, float v) { headers.addFloat(charSequence, v); return this; } @Override public Http2Headers addDouble(CharSequence charSequence, double v) { headers.addDouble(charSequence, v); return this; } @Override public Http2Headers addTimeMillis(CharSequence charSequence, long l) { headers.addTimeMillis(charSequence, l); return this; } @Override public Http2Headers add(Headers<? extends CharSequence, ? extends CharSequence, ?> headers) { this.headers.add(headers); return this; } @Override public Http2Headers set(CharSequence charSequence, CharSequence charSequence2) { headers.set(charSequence, charSequence2); return this; } @Override public Http2Headers set(CharSequence charSequence, Iterable<? extends CharSequence> iterable) { headers.set(charSequence, iterable); return this; } @Override public Http2Headers set(CharSequence charSequence, CharSequence... charSequences) { headers.set(charSequence, charSequences); return this; } @Override public Http2Headers setObject(CharSequence charSequence, Object o) { headers.setObject(charSequence, o); return this; } @Override public Http2Headers setObject(CharSequence charSequence, Iterable<?> iterable) { headers.setObject(charSequence, iterable); return this; } @Override public Http2Headers setObject(CharSequence charSequence, Object... objects) { headers.setObject(charSequence, objects); return this; } @Override public Http2Headers setBoolean(CharSequence charSequence, boolean b) { headers.setBoolean(charSequence, b); return this; } @Override public Http2Headers setByte(CharSequence charSequence, byte b) { headers.setByte(charSequence, b); return this; } @Override public Http2Headers setChar(CharSequence charSequence, char c) { headers.setChar(charSequence, c); return this; } @Override public Http2Headers setShort(CharSequence charSequence, short i) { headers.setShort(charSequence, i); return this; } @Override public Http2Headers setInt(CharSequence charSequence, int i) { headers.setInt(charSequence, i); return this; } @Override public Http2Headers setLong(CharSequence charSequence, long l) { headers.setLong(charSequence, l); return this; } @Override public Http2Headers setFloat(CharSequence charSequence, float v) { headers.setFloat(charSequence, v); return this; } @Override public Http2Headers setDouble(CharSequence charSequence, double v) { headers.setDouble(charSequence, v); return this; } @Override public Http2Headers setTimeMillis(CharSequence charSequence, long l) { headers.setTimeMillis(charSequence, l); return this; } @Override public Http2Headers set(Headers<? extends CharSequence, ? extends CharSequence, ?> headers) { this.headers.set(headers); return this; } @Override public Http2Headers setAll(Headers<? extends CharSequence, ? extends CharSequence, ?> headers) { this.headers.setAll(headers); return this; } @Override public boolean remove(CharSequence charSequence) { return headers.remove(charSequence); } @Override public Http2Headers clear() { headers.clear(); return this; } @Override public void forEach(Consumer<? super Entry<CharSequence, CharSequence>> action) { headers.forEach(action); } @Override public Spliterator<Entry<CharSequence, CharSequence>> spliterator() { return headers.spliterator(); } @Override public int hashCode() { return headers.hashCode(); } @Override public boolean equals(Object obj) { return this == obj || obj instanceof Http2Headers && headers.equals(obj); } @Override public String toString() { return "Http2HeadersAdapter{headers=" + headers + '}'; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/netty4/NettyHttp3FrameCodec.java
dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/netty4/NettyHttp3FrameCodec.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http3.netty4; import org.apache.dubbo.common.io.StreamUtils; import org.apache.dubbo.remoting.http12.HttpStatus; import org.apache.dubbo.remoting.http12.h2.Http2Header; import org.apache.dubbo.remoting.http12.h2.Http2InputMessageFrame; import org.apache.dubbo.remoting.http12.h2.Http2MetadataFrame; import org.apache.dubbo.remoting.http12.h2.Http2OutputMessage; import org.apache.dubbo.remoting.http12.message.DefaultHttpHeaders; import org.apache.dubbo.remoting.http12.netty4.NettyHttpHeaders; import java.io.OutputStream; import java.net.SocketAddress; import io.netty.buffer.ByteBufInputStream; import io.netty.buffer.ByteBufOutputStream; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelOutboundHandler; import io.netty.channel.ChannelPromise; import io.netty.handler.codec.http2.Http2Headers.PseudoHeaderName; import io.netty.handler.codec.http3.DefaultHttp3DataFrame; import io.netty.handler.codec.http3.DefaultHttp3Headers; import io.netty.handler.codec.http3.DefaultHttp3HeadersFrame; import io.netty.handler.codec.http3.Http3DataFrame; import io.netty.handler.codec.http3.Http3Headers; import io.netty.handler.codec.http3.Http3HeadersFrame; import io.netty.handler.codec.http3.Http3RequestStreamInboundHandler; import io.netty.handler.codec.quic.QuicStreamChannel; import static org.apache.dubbo.remoting.http3.netty4.Constants.TRI_PING; @Sharable public class NettyHttp3FrameCodec extends Http3RequestStreamInboundHandler implements ChannelOutboundHandler { public static final NettyHttp3FrameCodec INSTANCE = new NettyHttp3FrameCodec(); @Override protected void channelRead(ChannelHandlerContext ctx, Http3HeadersFrame frame) { Http3Headers headers = frame.headers(); if (headers.contains(TRI_PING)) { pingReceived(ctx); return; } ctx.fireChannelRead(new Http2MetadataFrame(getStreamId(ctx), new DefaultHttpHeaders(headers), false)); } private void pingReceived(ChannelHandlerContext ctx) { Http3Headers pongHeader = new DefaultHttp3Headers(false); pongHeader.set(TRI_PING, "0"); pongHeader.set(PseudoHeaderName.STATUS.value(), HttpStatus.OK.getStatusString()); ChannelFuture future = ctx.write(new DefaultHttp3HeadersFrame(pongHeader), ctx.newPromise()); if (future.isDone()) { ctx.close(); } else { future.addListener((ChannelFutureListener) f -> ctx.close()); } } @Override protected void channelRead(ChannelHandlerContext ctx, Http3DataFrame frame) { ctx.fireChannelRead( new Http2InputMessageFrame(getStreamId(ctx), new ByteBufInputStream(frame.content(), true), false)); } private static long getStreamId(ChannelHandlerContext ctx) { return ((QuicStreamChannel) ctx.channel()).streamId(); } @Override protected void channelInputClosed(ChannelHandlerContext ctx) { ctx.fireChannelRead(new Http2InputMessageFrame(getStreamId(ctx), StreamUtils.EMPTY, true)); } @Override @SuppressWarnings("unchecked") public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (msg instanceof Http2Header) { Http2Header headers = (Http2Header) msg; if (headers.isEndStream()) { ChannelFuture future = ctx.write( new DefaultHttp3HeadersFrame(((NettyHttpHeaders<Http3Headers>) headers.headers()).getHeaders()), ctx.newPromise()); if (future.isDone()) { ctx.close(promise); } else { future.addListener((ChannelFutureListener) f -> ctx.close(promise)); } return; } ctx.write( new DefaultHttp3HeadersFrame(((NettyHttpHeaders<Http3Headers>) headers.headers()).getHeaders()), promise); } else if (msg instanceof Http2OutputMessage) { Http2OutputMessage message = (Http2OutputMessage) msg; OutputStream body = message.getBody(); assert body instanceof ByteBufOutputStream || body == null; if (message.isEndStream()) { if (body == null) { ctx.close(promise); return; } ChannelFuture future = ctx.write(new DefaultHttp3DataFrame(((ByteBufOutputStream) body).buffer()), ctx.newPromise()); if (future.isDone()) { ctx.close(promise); } else { future.addListener((ChannelFutureListener) f -> ctx.close(promise)); } return; } if (body == null) { promise.trySuccess(); return; } ctx.write(new DefaultHttp3DataFrame(((ByteBufOutputStream) body).buffer()), promise); } else { ctx.write(msg, promise); } } @Override public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception { ctx.bind(localAddress, promise); } @Override public void connect( ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) { ctx.connect(remoteAddress, localAddress, promise); } @Override public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) { ctx.disconnect(promise); } @Override public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { ctx.close(promise); } @Override public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) { ctx.deregister(promise); } @Override public void read(ChannelHandlerContext ctx) throws Exception { ctx.read(); } @Override public void flush(ChannelHandlerContext ctx) { ctx.flush(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/netty4/Http3ChannelAddressAccessor.java
dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/netty4/Http3ChannelAddressAccessor.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http3.netty4; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.remoting.transport.netty4.ChannelAddressAccessor; import java.net.InetSocketAddress; import io.netty.channel.Channel; import io.netty.handler.codec.quic.QuicChannel; import io.netty.handler.codec.quic.QuicStreamChannel; @Activate(order = -100, onClass = "io.netty.handler.codec.quic.QuicChannel") public class Http3ChannelAddressAccessor implements ChannelAddressAccessor { @Override public String getProtocol() { return "UDP"; } @Override public InetSocketAddress getRemoteAddress(Channel channel) { if (channel instanceof QuicStreamChannel) { return (InetSocketAddress) ((QuicStreamChannel) channel).parent().remoteSocketAddress(); } if (channel instanceof QuicChannel) { return (InetSocketAddress) ((QuicChannel) channel).remoteSocketAddress(); } return null; } @Override public InetSocketAddress getLocalAddress(Channel channel) { if (channel instanceof QuicStreamChannel) { return (InetSocketAddress) ((QuicStreamChannel) channel).parent().localSocketAddress(); } if (channel instanceof QuicChannel) { return (InetSocketAddress) ((QuicChannel) channel).localSocketAddress(); } return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/netty4/NettyHttp3StreamChannel.java
dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/netty4/NettyHttp3StreamChannel.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http3.netty4; import org.apache.dubbo.remoting.http12.HttpMetadata; import org.apache.dubbo.remoting.http12.HttpOutputMessage; import org.apache.dubbo.remoting.http12.h2.H2StreamChannel; import org.apache.dubbo.remoting.http12.h2.Http2OutputMessage; import org.apache.dubbo.remoting.http12.h2.Http2OutputMessageFrame; import org.apache.dubbo.remoting.http12.netty4.NettyHttpChannelFutureListener; import java.net.SocketAddress; import java.util.concurrent.CompletableFuture; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufOutputStream; import io.netty.handler.codec.quic.QuicStreamChannel; public class NettyHttp3StreamChannel implements H2StreamChannel { private final QuicStreamChannel http3StreamChannel; public NettyHttp3StreamChannel(QuicStreamChannel http3StreamChannel) { this.http3StreamChannel = http3StreamChannel; } @Override public CompletableFuture<Void> writeResetFrame(long errorCode) { NettyHttpChannelFutureListener futureListener = new NettyHttpChannelFutureListener(); http3StreamChannel.close().addListener(futureListener); return futureListener; } @Override public Http2OutputMessage newOutputMessage(boolean endStream) { ByteBuf buffer = http3StreamChannel.alloc().buffer(); return new Http2OutputMessageFrame(new ByteBufOutputStream(buffer), endStream); } @Override public CompletableFuture<Void> writeHeader(HttpMetadata httpMetadata) { NettyHttpChannelFutureListener futureListener = new NettyHttpChannelFutureListener(); http3StreamChannel.write(httpMetadata).addListener(futureListener); return futureListener; } @Override public CompletableFuture<Void> writeMessage(HttpOutputMessage httpOutputMessage) { NettyHttpChannelFutureListener futureListener = new NettyHttpChannelFutureListener(); http3StreamChannel.write(httpOutputMessage).addListener(futureListener); return futureListener; } @Override public SocketAddress remoteAddress() { return http3StreamChannel.parent().remoteSocketAddress(); } @Override public SocketAddress localAddress() { return http3StreamChannel.parent().localSocketAddress(); } @Override public void flush() { http3StreamChannel.flush(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/netty4/Constants.java
dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/http3/netty4/Constants.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http3.netty4; public final class Constants { public static final String PIPELINE_CONFIGURATOR_KEY = "http3PipelineConfigurator"; public static final CharSequence TRI_PING = "tri-ping"; private Constants() {} }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyHttp3Server.java
dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyHttp3Server.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.transport.netty4; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.config.ConfigurationUtils; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.ChannelHandler; import org.apache.dubbo.remoting.RemotingException; import org.apache.dubbo.remoting.http3.Http3SslContexts; import org.apache.dubbo.remoting.transport.AbstractServer; import org.apache.dubbo.remoting.transport.dispatcher.ChannelHandlers; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Collection; import java.util.Map; import java.util.Objects; import java.util.function.Consumer; import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.handler.codec.http3.Http3; import io.netty.handler.codec.quic.InsecureQuicTokenHandler; import io.netty.handler.codec.quic.QuicChannel; import io.netty.util.concurrent.Future; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_CLOSE; import static org.apache.dubbo.remoting.Constants.EVENT_LOOP_BOSS_POOL_NAME; import static org.apache.dubbo.remoting.http3.netty4.Constants.PIPELINE_CONFIGURATOR_KEY; public class NettyHttp3Server extends AbstractServer { private Map<String, Channel> channels; private Bootstrap bootstrap; private EventLoopGroup bossGroup; private io.netty.channel.Channel channel; private Consumer<ChannelPipeline> pipelineConfigurator; private int serverShutdownTimeoutMills; public NettyHttp3Server(URL url, ChannelHandler handler) throws RemotingException { super(url, ChannelHandlers.wrap(handler, url)); } @Override @SuppressWarnings("unchecked") protected void doOpen() throws Throwable { bootstrap = new Bootstrap(); // initialize pipelineConfigurator and serverShutdownTimeoutMills before potential usage to avoid NPE. pipelineConfigurator = (Consumer<ChannelPipeline>) getUrl().getAttribute(PIPELINE_CONFIGURATOR_KEY); Objects.requireNonNull(pipelineConfigurator, "pipelineConfigurator should be set"); serverShutdownTimeoutMills = ConfigurationUtils.getServerShutdownTimeout(getUrl().getOrDefaultModuleModel()); bossGroup = NettyEventLoopFactory.eventLoopGroup(1, EVENT_LOOP_BOSS_POOL_NAME); NettyServerHandler nettyServerHandler = new NettyServerHandler(getUrl(), this); channels = nettyServerHandler.getChannels(); try { ChannelFuture channelFuture = bootstrap .group(bossGroup) .channel(NioDatagramChannel.class) .handler(Http3Helper.configCodec(Http3.newQuicServerCodecBuilder(), getUrl()) .sslContext(Http3SslContexts.buildServerSslContext(getUrl())) .tokenHandler(InsecureQuicTokenHandler.INSTANCE) .handler(new ChannelInitializer<QuicChannel>() { @Override protected void initChannel(QuicChannel ch) { ChannelPipeline pipeline = ch.pipeline(); pipelineConfigurator.accept(pipeline); pipeline.addLast(nettyServerHandler); } }) .build()) .bind(getBindAddress()); channelFuture.syncUninterruptibly(); channel = channelFuture.channel(); } catch (Throwable t) { closeBootstrap(); throw t; } } @Override protected void doClose() { try { if (channel != null) { // unbind. channel.close(); } } catch (Throwable e) { logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e); } try { Collection<Channel> channels = getChannels(); if (CollectionUtils.isNotEmpty(channels)) { for (Channel channel : channels) { try { channel.close(); } catch (Throwable e) { logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e); } } } } catch (Throwable e) { logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e); } closeBootstrap(); try { if (channels != null) { channels.clear(); } } catch (Throwable e) { logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e); } } private void closeBootstrap() { try { if (bootstrap != null) { long timeout = ConfigurationUtils.reCalShutdownTime(serverShutdownTimeoutMills); long quietPeriod = Math.min(2000L, timeout); Future<?> bossGroupShutdownFuture = bossGroup.shutdownGracefully(quietPeriod, timeout, MILLISECONDS); bossGroupShutdownFuture.syncUninterruptibly(); } } catch (Throwable e) { logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e); } } @Override protected int getChannelsSize() { return channels.size(); } @Override public Collection<Channel> getChannels() { return new ArrayList<>(channels.values()); } @Override public Channel getChannel(InetSocketAddress remoteAddress) { return channels.get(NetUtils.toAddressString(remoteAddress)); } @Override public boolean canHandleIdle() { return true; } @Override public boolean isBound() { return channel.isActive(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyHttp3ConnectionClient.java
dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyHttp3ConnectionClient.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.transport.netty4; import org.apache.dubbo.common.URL; import org.apache.dubbo.remoting.ChannelHandler; import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.remoting.RemotingException; import org.apache.dubbo.remoting.http3.Http3SslContexts; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPromise; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.handler.codec.http3.Http3; import io.netty.handler.codec.http3.Http3ClientConnectionHandler; import io.netty.handler.codec.quic.QuicChannel; import io.netty.handler.codec.quic.QuicChannelBootstrap; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; import static org.apache.dubbo.remoting.http3.netty4.Constants.PIPELINE_CONFIGURATOR_KEY; public final class NettyHttp3ConnectionClient extends AbstractNettyConnectionClient { private Consumer<ChannelPipeline> pipelineConfigurator; private AtomicReference<io.netty.channel.Channel> datagramChannel; private QuicChannelBootstrap bootstrap; public NettyHttp3ConnectionClient(URL url, ChannelHandler handler) throws RemotingException { super(url, handler); } @Override @SuppressWarnings("unchecked") protected void initConnectionClient() { super.initConnectionClient(); datagramChannel = new AtomicReference<>(); pipelineConfigurator = (Consumer<ChannelPipeline>) getUrl().getAttribute(PIPELINE_CONFIGURATOR_KEY); Objects.requireNonNull(pipelineConfigurator, "pipelineConfigurator should be set"); } @Override protected void initBootstrap() throws Exception { io.netty.channel.ChannelHandler codec = Http3Helper.configCodec(Http3.newQuicClientCodecBuilder(), getUrl()) .sslContext(Http3SslContexts.buildClientSslContext(getUrl())) .build(); io.netty.channel.Channel nettyDatagramChannel = new Bootstrap() .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, getConnectTimeout()) .group(NettyEventLoopFactory.NIO_EVENT_LOOP_GROUP.get()) .channel(NioDatagramChannel.class) .handler(new ChannelInitializer<NioDatagramChannel>() { @Override protected void initChannel(NioDatagramChannel ch) { ch.pipeline().addLast(codec); } }) .bind(0) .sync() .channel(); datagramChannel.set(nettyDatagramChannel); nettyDatagramChannel.closeFuture().addListener(channelFuture -> datagramChannel.set(null)); NettyConnectionHandler connectionHandler = new NettyConnectionHandler(this); bootstrap = QuicChannel.newBootstrap(nettyDatagramChannel) .handler(new ChannelInitializer<QuicChannel>() { @Override protected void initChannel(QuicChannel ch) { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(new Http3ClientConnectionHandler()); pipeline.addLast(Constants.CONNECTION_HANDLER_NAME, connectionHandler); pipelineConfigurator.accept(pipeline); ch.closeFuture().addListener(channelFuture -> clearNettyChannel()); } }) .remoteAddress(getConnectAddress()); } @Override protected ChannelFuture performConnect() { Channel channel = getNettyDatagramChannel(); if (channel == null) { return null; } ChannelPromise promise = channel.newPromise(); GenericFutureListener<Future<QuicChannel>> listener = f -> { if (f.isSuccess()) { promise.setSuccess(null); } else { promise.setFailure(f.cause()); } }; bootstrap.connect().addListener(listener); return promise; } @Override protected void performClose() { super.performClose(); io.netty.channel.Channel current = getNettyDatagramChannel(); if (current != null) { current.close(); } datagramChannel.set(null); } private io.netty.channel.Channel getNettyDatagramChannel() { return datagramChannel.get(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/transport/netty4/Http3Helper.java
dubbo-remoting/dubbo-remoting-http3/src/main/java/org/apache/dubbo/remoting/transport/netty4/Http3Helper.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.transport.netty4; import org.apache.dubbo.common.URL; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.nested.Http3Config; import io.netty.handler.codec.quic.QuicCodecBuilder; import io.netty.handler.codec.quic.QuicCongestionControlAlgorithm; import static java.util.concurrent.TimeUnit.MILLISECONDS; final class Http3Helper { @SuppressWarnings("unchecked") static <T extends QuicCodecBuilder<T>> T configCodec(QuicCodecBuilder<T> builder, URL url) { Http3Config config = ConfigManager.getProtocolOrDefault(url).getTripleOrDefault().getHttp3OrDefault(); builder.initialMaxData(config.getInitialMaxDataOrDefault()) .initialMaxStreamDataBidirectionalLocal(config.getInitialMaxStreamDataBidiLocalOrDefault()) .initialMaxStreamDataBidirectionalRemote(config.getInitialMaxStreamDataBidiRemoteOrDefault()) .initialMaxStreamDataUnidirectional(config.getInitialMaxStreamDataUniOrDefault()) .initialMaxStreamsBidirectional(config.getInitialMaxStreamsBidiOrDefault()) .initialMaxStreamsUnidirectional(config.getInitialMaxStreamsUniOrDefault()); if (config.getRecvQueueLen() != null && config.getSendQueueLen() != null) { builder.datagram(config.getRecvQueueLen(), config.getSendQueueLen()); } if (config.getMaxAckDelayExponent() != null) { builder.ackDelayExponent(config.getMaxAckDelayExponent()); } if (config.getMaxAckDelay() != null) { builder.maxAckDelay(config.getMaxAckDelay(), MILLISECONDS); } if (config.getDisableActiveMigration() != null) { builder.activeMigration(config.getDisableActiveMigration()); } if (config.getEnableHystart() != null) { builder.hystart(config.getEnableHystart()); } if (config.getCcAlgorithm() != null) { if ("RENO".equalsIgnoreCase(config.getCcAlgorithm())) { builder.congestionControlAlgorithm(QuicCongestionControlAlgorithm.RENO); } else if ("BBR".equalsIgnoreCase(config.getCcAlgorithm())) { builder.congestionControlAlgorithm(QuicCongestionControlAlgorithm.BBR); } } return (T) builder; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/ServerSentEventEncoderTest.java
dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/ServerSentEventEncoderTest.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.message; import org.apache.dubbo.remoting.http12.exception.EncodeException; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.nio.charset.StandardCharsets; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class ServerSentEventEncoderTest { static class DummyJsonEncoder implements HttpMessageEncoder { @Override public void encode(OutputStream outputStream, Object data, java.nio.charset.Charset charset) throws EncodeException { try { if (data instanceof byte[]) { outputStream.write((byte[]) data); } else { outputStream.write(String.valueOf(data).getBytes(charset)); } } catch (Exception e) { throw new EncodeException("encode error", e); } } @Override public MediaType mediaType() { return MediaType.APPLICATION_JSON; } @Override public boolean supports(String mediaType) { return true; } } @Test void shouldUseTextEventStreamContentType() { ServerSentEventEncoder sse = new ServerSentEventEncoder(new DummyJsonEncoder()); Assertions.assertEquals(MediaType.TEXT_EVENT_STREAM, sse.mediaType()); Assertions.assertEquals(MediaType.TEXT_EVENT_STREAM.getName(), sse.contentType()); } @Test void shouldEncodeServerSentEventFormat() { ServerSentEventEncoder sse = new ServerSentEventEncoder(new DummyJsonEncoder()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); sse.encode( bos, ServerSentEvent.builder() .event("message") .data("{\"a\":1}") .id("1") .build(), StandardCharsets.UTF_8); byte[] bytes = bos.toByteArray(); String text = new String(bytes, StandardCharsets.UTF_8); Assertions.assertTrue(text.contains("id:1\n")); Assertions.assertTrue(text.contains("event:message\n")); Assertions.assertTrue(text.contains("data:{\"a\":1}\n")); Assertions.assertTrue(text.endsWith("\n")); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/XmlSafetyTest.java
dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/XmlSafetyTest.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.message.codec; import java.io.*; import java.util.Collections; import java.util.HashSet; import java.util.Set; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledOnOs; import org.junit.jupiter.api.condition.OS; @EnabledOnOs(OS.LINUX) public class XmlSafetyTest { ProcessChecker checker = new ProcessChecker(); @BeforeEach void setUp() throws Exception { checker.prepare(); } @AfterEach void check() throws Exception { checker.check(); } @Test void testSafe1() { try { InputStream in = new ByteArrayInputStream(("<xml>\n" + " <dynamic-proxy>\n" + " <interface>java.util.List</interface>\n" + " <handler class=\"java.beans.EventHandler\">\n" + " <target class=\"java.lang.ProcessBuilder\">\n" + " <command>\n" + " <string>" + "sleep" + "</string>\n" + " <string>" + "60" + "</string>\n" + " </command>\n" + " </target>\n" + " <action>start</action>\n" + " </handler>\n" + " </dynamic-proxy>\n" + "</xml>") .getBytes()); new XmlCodec().decode(in, Object.class); } catch (Exception e) { } } @Test void testSafe2() { try { InputStream in = new ByteArrayInputStream(("<java>\n" + " <object class=\"java.lang.Runtime\">\n" + " <void method=\"exec\">\n" + " <string>" + "sleep" + "</string>\n" + " <string>" + "60" + "</string>\n" + " </void>\n" + " </object>\n" + "</java>") .getBytes()); new XmlCodec().decode(in, Object.class); } catch (Exception e) { } } static class ProcessChecker { Set<String> processesBefore; String currentPid; public Set<String> getProcesses() { if (currentPid == null) { return Collections.emptySet(); } try { Set<String> processes = new HashSet<>(); Process process = Runtime.getRuntime().exec(new String[] {"ps", "-o", "pid,ppid,cmd"}); try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { String line; boolean headerSkipped = false; while ((line = reader.readLine()) != null) { line = line.trim(); if (line.isEmpty()) { continue; } if (!headerSkipped) { headerSkipped = true; continue; } String[] parts = line.split("\\s+", 3); if (parts.length < 3) { continue; } String pid = parts[0]; String ppid = parts[1]; String cmd = parts[2]; if (ppid.equals(currentPid) && cmd.contains("sleep") && cmd.contains("60")) { processes.add(pid + ":" + cmd); } } } return processes; } catch (Exception e) { } return Collections.emptySet(); } public void prepare() { try { currentPid = new File("/proc/self").getCanonicalFile().getName(); } catch (IOException e) { currentPid = null; } processesBefore = getProcesses(); } public void check() throws Exception { Set<String> processesAfter = getProcesses(); for (String msg : processesAfter) { if (!processesBefore.contains(msg)) { throw new Exception("Command executed when XML deserialization."); } } } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/CodeUtilsTest.java
dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/CodeUtilsTest.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.message.codec; import org.apache.dubbo.remoting.http12.HttpHeaderNames; import org.apache.dubbo.remoting.http12.HttpHeaders; import org.apache.dubbo.remoting.http12.message.HttpMessageDecoder; import org.apache.dubbo.remoting.http12.message.HttpMessageEncoder; import org.apache.dubbo.remoting.http12.message.MediaType; import org.apache.dubbo.rpc.model.FrameworkModel; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; public class CodeUtilsTest { @Test void testDetermineHttpCodec() { CodecUtils codecUtils = new CodecUtils(FrameworkModel.defaultModel()); HttpHeaders headers = HttpHeaders.create(); headers.set(HttpHeaderNames.CONTENT_TYPE.getKey(), MediaType.APPLICATION_JSON.getName()); HttpMessageDecoder decoder = codecUtils.determineHttpMessageDecoder(null, headers.getFirst(HttpHeaderNames.CONTENT_TYPE.getKey())); Assertions.assertNotNull(decoder); Assertions.assertEquals(JsonPbCodec.class, decoder.getClass()); HttpMessageEncoder encoder; // If no Accept header provided, use Content-Type to find encoder encoder = codecUtils.determineHttpMessageEncoder(null, MediaType.APPLICATION_JSON.getName()); Assertions.assertNotNull(encoder); Assertions.assertEquals(JsonPbCodec.class, encoder.getClass()); encoder = codecUtils.determineHttpMessageEncoder(null, MediaType.APPLICATION_JSON.getName()); Assertions.assertNotNull(encoder); Assertions.assertEquals(JsonPbCodec.class, encoder.getClass()); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/User.java
dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/User.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.message.codec; import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; @XmlRootElement public class User implements Serializable { private String username; private String location; public User() {} public User(String username, String location) { this.username = username; this.location = location; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } @Override public String toString() { return "User{" + "username='" + username + '\'' + ", location='" + location + '\'' + '}'; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/CodecTest.java
dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/CodecTest.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.message.codec; import org.apache.dubbo.remoting.http12.message.HttpMessageCodec; import org.apache.dubbo.rpc.model.FrameworkModel; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import com.google.common.base.Charsets; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class CodecTest { CodecUtils codecUtils; @BeforeEach void beforeAll() { codecUtils = FrameworkModel.defaultModel().getBeanFactory().getOrRegisterBean(CodecUtils.class); } @Test void testXml() { String content = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<user><location>New York</location><username>JohnDoe</username></user>"; InputStream in = new ByteArrayInputStream(content.getBytes()); HttpMessageCodec codec = new XmlCodecFactory().createCodec(null, FrameworkModel.defaultModel(), null); User user = (User) codec.decode(in, User.class); Assertions.assertEquals("JohnDoe", user.getUsername()); Assertions.assertEquals("New York", user.getLocation()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); codec.encode(outputStream, user); String res = outputStream.toString(); Assertions.assertEquals(content, res); } @Test void testPlainText() { byte[] asciiBytes = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64 }; byte[] utf8Bytes = new byte[] { (byte) 0xE4, (byte) 0xBD, (byte) 0xA0, (byte) 0xE5, (byte) 0xA5, (byte) 0xBD, (byte) 0xEF, (byte) 0xBC, (byte) 0x8C, (byte) 0xE4, (byte) 0xB8, (byte) 0x96, (byte) 0xE7, (byte) 0x95, (byte) 0x8C }; byte[] utf16Bytes = new byte[] {0x4F, 0x60, 0x59, 0x7D, (byte) 0xFF, 0x0C, 0x4E, 0x16, 0x75, 0x4C}; InputStream in = new ByteArrayInputStream(asciiBytes); HttpMessageCodec codec = new PlainTextCodecFactory() .createCodec(null, FrameworkModel.defaultModel(), "text/plain; charset=ASCII"); String res = (String) codec.decode(in, String.class); Assertions.assertEquals("Hello, world", res); in = new ByteArrayInputStream(utf8Bytes); codec = PlainTextCodec.INSTANCE; res = (String) codec.decode(in, String.class, Charsets.UTF_8); Assertions.assertEquals("你好,世界", res); in = new ByteArrayInputStream(utf16Bytes); res = (String) codec.decode(in, String.class, Charsets.UTF_16); Assertions.assertEquals("你好,世界", res); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/HttpUtilsTest.java
dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/HttpUtilsTest.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.message.codec; import org.apache.dubbo.remoting.http12.HttpUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; public class HttpUtilsTest { @Test void testParseCharset() { String charset = HttpUtils.parseCharset("text/html;charset=utf-8"); Assertions.assertEquals("utf-8", charset); charset = HttpUtils.parseCharset("text/html"); Assertions.assertEquals("", charset); charset = HttpUtils.parseCharset("application/json;charset=utf-8; boundary=__X_PAW_BOUNDARY__"); Assertions.assertEquals("utf-8", charset); charset = HttpUtils.parseCharset("multipart/form-data; charset=utf-8; boundary=__X_PAW_BOUNDARY__"); Assertions.assertEquals("utf-8", charset); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpInputMessage.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpInputMessage.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import java.io.IOException; import java.io.InputStream; public interface HttpInputMessage extends AutoCloseable { InputStream getBody(); @Override default void close() throws IOException { getBody().close(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/RequestMetadata.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/RequestMetadata.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; public interface RequestMetadata extends HttpMetadata { String method(); String path(); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpResponse.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpResponse.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import java.io.OutputStream; import java.util.Collection; import java.util.Date; import java.util.List; public interface HttpResponse { int status(); void setStatus(int status); String header(CharSequence name); Date dateHeader(CharSequence name); List<String> headerValues(CharSequence name); boolean hasHeader(CharSequence name); Collection<String> headerNames(); HttpHeaders headers(); void addHeader(CharSequence name, String value); void addHeader(CharSequence name, Date value); void setHeader(CharSequence name, String value); void setHeader(CharSequence name, Date value); void setHeader(CharSequence name, List<String> value); void addCookie(HttpCookie cookie); String contentType(); void setContentType(String contentType); String mediaType(); String charset(); void setCharset(String charset); String locale(); void setLocale(String locale); Object body(); void setBody(Object body); OutputStream outputStream(); void setOutputStream(OutputStream os); void sendRedirect(String location); void sendError(int status); void sendError(int status, String message); boolean isEmpty(); boolean isContentEmpty(); boolean isCommitted(); void commit(); void setCommitted(boolean committed); void reset(); void resetBuffer(); HttpResult<Object> toHttpResult(); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpTransportListener.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpTransportListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; public interface HttpTransportListener<HEADER extends HttpMetadata, MESSAGE extends HttpInputMessage> { void onMetadata(HEADER metadata); void onData(MESSAGE message); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/ExceptionHandler.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/ExceptionHandler.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import org.apache.dubbo.common.extension.ExtensionScope; import org.apache.dubbo.common.extension.SPI; import org.apache.dubbo.common.logger.Level; import org.apache.dubbo.rpc.model.MethodDescriptor; /** * Interface for customize exception handling. * * @param <E> the type of exception to handle * @param <T> the type of result returned */ @SPI(scope = ExtensionScope.FRAMEWORK) public interface ExceptionHandler<E extends Throwable, T> { /** * Resolves the log level for a given throwable. * * @param throwable the exception * @return the log level, or null to ignore this extension */ default Level resolveLogLevel(E throwable) { return null; } /** * Resolves the gRPC status for a given throwable. * * @param headers the response headers * @param throwable the exception * @param metadata the request metadata, may be null * @param descriptor the method descriptor, may be null */ default boolean resolveGrpcStatus( E throwable, HttpHeaders headers, RequestMetadata metadata, MethodDescriptor descriptor) { return false; } /** * Handle the exception and return a result. * * @param throwable the exception * @param metadata the request metadata, may be null * @param descriptor the method descriptor, may be null * @return a result of type T, or null to ignore this extension */ default T handle(E throwable, RequestMetadata metadata, MethodDescriptor descriptor) { return null; } /** * Handles the exception and return a result for gRPC protocol. * * @param throwable the exception * @param metadata the request metadata, may be null * @param descriptor the method descriptor, may be null * @return a result of type T, or null to ignore this extension */ default T handleGrpc(E throwable, RequestMetadata metadata, MethodDescriptor descriptor) { return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpRequest.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpRequest.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import java.io.InputStream; import java.nio.charset.Charset; import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Map; public interface HttpRequest extends RequestMetadata { boolean isHttp2(); String method(); void setMethod(String method); String uri(); void setUri(String uri); String path(); String rawPath(); String query(); String header(CharSequence name); List<String> headerValues(CharSequence name); Date dateHeader(CharSequence name); boolean hasHeader(CharSequence name); Collection<String> headerNames(); HttpHeaders headers(); void setHeader(CharSequence name, String value); void setHeader(CharSequence name, List<String> values); void setHeader(CharSequence name, Date value); Collection<HttpCookie> cookies(); HttpCookie cookie(String name); int contentLength(); String contentType(); void setContentType(String contentType); String mediaType(); String charset(); Charset charsetOrDefault(); void setCharset(String charset); String accept(); Locale locale(); List<Locale> locales(); String scheme(); String serverHost(); String serverName(); int serverPort(); String remoteHost(); String remoteAddr(); int remotePort(); String localHost(); String localAddr(); int localPort(); String parameter(String name); String parameter(String name, String defaultValue); List<String> parameterValues(String name); String queryParameter(String name); List<String> queryParameterValues(String name); Collection<String> queryParameterNames(); Map<String, List<String>> queryParameters(); String formParameter(String name); List<String> formParameterValues(String name); Collection<String> formParameterNames(); boolean hasParameter(String name); Collection<String> parameterNames(); Collection<FileUpload> parts(); FileUpload part(String name); <T> T attribute(String name); void removeAttribute(String name); void setAttribute(String name, Object value); boolean hasAttribute(String name); Collection<String> attributeNames(); Map<String, Object> attributes(); InputStream inputStream(); void setInputStream(InputStream is); interface FileUpload { String name(); String filename(); String contentType(); int size(); InputStream inputStream(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpChannel.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpChannel.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import java.net.SocketAddress; import java.util.concurrent.CompletableFuture; public interface HttpChannel { CompletableFuture<Void> writeHeader(HttpMetadata httpMetadata); CompletableFuture<Void> writeMessage(HttpOutputMessage httpOutputMessage); HttpOutputMessage newOutputMessage(); SocketAddress remoteAddress(); SocketAddress localAddress(); void flush(); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/CompositeInputStream.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/CompositeInputStream.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import org.apache.dubbo.remoting.http12.exception.DecodeException; import java.io.IOException; import java.io.InputStream; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; public class CompositeInputStream extends InputStream { private final Queue<InputStream> inputStreams = new ConcurrentLinkedQueue<>(); private int totalAvailable = 0; private int readIndex = 0; public void addInputStream(InputStream inputStream) { inputStreams.offer(inputStream); try { totalAvailable += inputStream.available(); } catch (IOException e) { throw new DecodeException(e); } } @Override public int read() throws IOException { InputStream inputStream; while ((inputStream = inputStreams.peek()) != null) { int available = inputStream.available(); if (available == 0) { releaseHeadStream(); continue; } int read = inputStream.read(); if (read != -1) { ++readIndex; releaseIfNecessary(inputStream); return read; } releaseHeadStream(); } return -1; } @Override public int read(byte[] b, int off, int len) throws IOException { if (b == null) { throw new NullPointerException(); } else if (off < 0 || len < 0 || len > b.length - off) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } int total = 0; InputStream inputStream; while ((inputStream = inputStreams.peek()) != null) { int available = inputStream.available(); if (available == 0) { releaseHeadStream(); continue; } int read = inputStream.read(b, off + total, Math.min(len - total, available)); if (read != -1) { total += read; readIndex += read; releaseIfNecessary(inputStream); if (total == len) { return total; } } else { releaseHeadStream(); } } return total > 0 ? total : -1; } @Override public int available() { return totalAvailable - readIndex; } @Override public void close() throws IOException { InputStream inputStream; while ((inputStream = inputStreams.poll()) != null) { inputStream.close(); } } private void releaseHeadStream() throws IOException { InputStream removeStream = inputStreams.remove(); removeStream.close(); } private void releaseIfNecessary(InputStream inputStream) throws IOException { int available = inputStream.available(); if (available == 0) { releaseHeadStream(); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpOutputMessage.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpOutputMessage.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; public interface HttpOutputMessage extends AutoCloseable { HttpOutputMessage EMPTY_MESSAGE = new HttpOutputMessage() { private final OutputStream INPUT_STREAM = new ByteArrayOutputStream(0); @Override public OutputStream getBody() { return INPUT_STREAM; } }; OutputStream getBody(); @Override default void close() throws IOException { getBody().close(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpVersion.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpVersion.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; public enum HttpVersion { HTTP1("http1", "HTTP/1.1"), HTTP2("http2", "HTTP/2.0"); private final String version; private final String protocol; HttpVersion(String version, String protocol) { this.version = version; this.protocol = protocol; } public String getVersion() { return version; } public String getProtocol() { return protocol; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpCookie.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpCookie.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import org.apache.dubbo.common.utils.Assert; import org.apache.dubbo.common.utils.StringUtils; public final class HttpCookie { private final String name; private String value; private String domain; private String path; private long maxAge = Long.MIN_VALUE; private boolean secure; private boolean httpOnly; private String sameSite; public HttpCookie(String name, String value) { name = StringUtils.trim(name); Assert.notEmptyString(name, "name is required"); this.name = name; setValue(value); } public String name() { return name; } public String value() { return value; } public void setValue(String value) { Assert.notNull(name, "value can not be null"); this.value = value; } public String domain() { return domain; } public void setDomain(String domain) { this.domain = domain; } public String path() { return path; } public void setPath(String path) { this.path = path; } public long maxAge() { return maxAge; } public void setMaxAge(long maxAge) { this.maxAge = maxAge; } public boolean secure() { return secure; } public void setSecure(boolean secure) { this.secure = secure; } public boolean httpOnly() { return httpOnly; } public void setHttpOnly(boolean httpOnly) { this.httpOnly = httpOnly; } public String sameSite() { return sameSite; } public void setSameSite(String sameSite) { this.sameSite = sameSite; } public String toString() { StringBuilder buf = new StringBuilder(name).append('=').append(value); if (domain != null) { buf.append(", domain=").append(domain); } if (path != null) { buf.append(", path=").append(path); } if (maxAge >= 0) { buf.append(", maxAge=").append(maxAge).append('s'); } if (secure) { buf.append(", secure"); } if (httpOnly) { buf.append(", HTTPOnly"); } if (sameSite != null) { buf.append(", SameSite=").append(sameSite); } return buf.toString(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpHeaderNames.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpHeaderNames.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import io.netty.handler.codec.http2.Http2Headers.PseudoHeaderName; import io.netty.util.AsciiString; public enum HttpHeaderNames { STATUS(PseudoHeaderName.STATUS.value()), PATH(PseudoHeaderName.PATH.value()), METHOD(PseudoHeaderName.METHOD.value()), ACCEPT(io.netty.handler.codec.http.HttpHeaderNames.ACCEPT), CONTENT_TYPE(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE), CONTENT_LENGTH(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH), CONTENT_LANGUAGE(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LANGUAGE), TRANSFER_ENCODING(io.netty.handler.codec.http.HttpHeaderNames.TRANSFER_ENCODING), CACHE_CONTROL(io.netty.handler.codec.http.HttpHeaderNames.CACHE_CONTROL), LOCATION(io.netty.handler.codec.http.HttpHeaderNames.LOCATION), HOST(io.netty.handler.codec.http.HttpHeaderNames.HOST), COOKIE(io.netty.handler.codec.http.HttpHeaderNames.COOKIE), SET_COOKIE(io.netty.handler.codec.http.HttpHeaderNames.SET_COOKIE), LAST_MODIFIED(io.netty.handler.codec.http.HttpHeaderNames.LAST_MODIFIED), TE(io.netty.handler.codec.http.HttpHeaderNames.TE), CONNECTION(io.netty.handler.codec.http.HttpHeaderNames.CONNECTION), ALT_SVC("alt-svc"); private final String name; private final CharSequence key; HttpHeaderNames(String name) { this.name = name; key = AsciiString.cached(name); } HttpHeaderNames(CharSequence key) { name = key.toString(); this.key = key; } public String getName() { return name; } public CharSequence getKey() { return key; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpJsonUtils.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpJsonUtils.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import org.apache.dubbo.common.config.Configuration; import org.apache.dubbo.common.config.ConfigurationUtils; import org.apache.dubbo.common.json.JsonUtil; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.rpc.Constants; import org.apache.dubbo.rpc.model.FrameworkModel; import java.lang.reflect.Type; import java.util.List; import java.util.Map; import java.util.Objects; public final class HttpJsonUtils { private final JsonUtil jsonUtil; public HttpJsonUtils(FrameworkModel frameworkModel) { Configuration configuration = ConfigurationUtils.getGlobalConfiguration(frameworkModel.defaultApplication()); JsonUtil jsonUtil; String name = configuration.getString(Constants.H2_SETTINGS_JSON_FRAMEWORK_NAME, null); if (name == null) { jsonUtil = CollectionUtils.first(frameworkModel.getActivateExtensions(JsonUtil.class)); } else { try { jsonUtil = frameworkModel.getExtension(JsonUtil.class, name); } catch (Exception e) { throw new IllegalStateException("Failed to load json framework: " + name, e); } } this.jsonUtil = Objects.requireNonNull(jsonUtil, "Dubbo unable to find out any json framework"); } public <T> T toJavaObject(String json, Type type) { return jsonUtil.toJavaObject(json, type); } public <T> List<T> toJavaList(String json, Class<T> clazz) { return jsonUtil.toJavaList(json, clazz); } public String toJson(Object obj) { return jsonUtil.toJson(obj); } public String toPrettyJson(Object obj) { return jsonUtil.toPrettyJson(obj); } public Object convertObject(Object obj, Type targetType) { return jsonUtil.convertObject(obj, targetType); } public Object convertObject(Object obj, Class<?> targetType) { return jsonUtil.convertObject(obj, targetType); } public String getString(Map<String, ?> obj, String key) { return jsonUtil.getString(obj, key); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpResult.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpResult.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import org.apache.dubbo.remoting.http12.exception.HttpResultPayloadException; import org.apache.dubbo.remoting.http12.message.DefaultHttpResult.Builder; import java.io.Serializable; import java.util.List; import java.util.Map; public interface HttpResult<T> extends Serializable { int getStatus(); Map<String, List<String>> getHeaders(); T getBody(); default HttpResultPayloadException toPayload() { return new HttpResultPayloadException(this); } static <T> Builder<T> builder() { return new Builder<>(); } static <T> HttpResult<T> of(T body) { return new Builder<T>().body(body).build(); } static <T> HttpResult<T> of(int status, T body) { if (body instanceof String) { if (status == HttpStatus.MOVED_PERMANENTLY.getCode()) { return moved((String) body); } else if (status == HttpStatus.FOUND.getCode()) { return found((String) body); } } return new Builder<T>().status(status).body(body).build(); } static <T> HttpResult<T> of(HttpStatus status, T body) { return of(status.getCode(), body); } static <T> HttpResult<T> status(int status) { return new Builder<T>().status(status).build(); } static <T> HttpResult<T> status(HttpStatus status) { return status(status.getCode()); } static <T> HttpResult<T> ok() { return new Builder<T>().status(HttpStatus.OK).build(); } static <T> HttpResult<T> moved(String url) { return new Builder<T>().moved(url).build(); } static <T> HttpResult<T> found(String url) { return new Builder<T>().found(url).build(); } static <T> HttpResult<T> badRequest() { return new Builder<T>().status(HttpStatus.BAD_REQUEST).build(); } static <T> HttpResult<T> notFound() { return new Builder<T>().status(HttpStatus.NOT_FOUND).build(); } static HttpResult<String> error() { return new Builder<String>().status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } static HttpResult<String> error(String message) { return error(HttpStatus.INTERNAL_SERVER_ERROR, message); } static HttpResult<String> error(int status, String message) { return new Builder<String>().status(status).body(message).build(); } static HttpResult<String> error(HttpStatus status, String message) { return new Builder<String>().status(status).body(message).build(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/AbstractServerHttpChannelObserver.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/AbstractServerHttpChannelObserver.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.utils.JsonUtils; import org.apache.dubbo.remoting.http12.exception.HttpStatusException; import org.apache.dubbo.remoting.http12.message.HttpMessageEncoder; import org.apache.dubbo.rpc.RpcContext; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.function.BiConsumer; import java.util.function.Function; import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR; import static org.apache.dubbo.common.logger.LoggerFactory.getErrorTypeAwareLogger; public abstract class AbstractServerHttpChannelObserver<H extends HttpChannel> implements ServerHttpChannelObserver<H> { private static final ErrorTypeAwareLogger LOGGER = getErrorTypeAwareLogger(AbstractServerHttpChannelObserver.class); private final H httpChannel; private List<BiConsumer<HttpHeaders, Throwable>> headersCustomizers; private List<BiConsumer<HttpHeaders, Throwable>> trailersCustomizers; private Function<Throwable, ?> exceptionCustomizer; private HttpMessageEncoder responseEncoder; private boolean headerSent; private boolean completed; private boolean closed; protected AbstractServerHttpChannelObserver(H httpChannel) { this.httpChannel = httpChannel; } @Override public H getHttpChannel() { return httpChannel; } @Override public void addHeadersCustomizer(BiConsumer<HttpHeaders, Throwable> headersCustomizer) { if (headersCustomizers == null) { headersCustomizers = new ArrayList<>(); } headersCustomizers.add(headersCustomizer); } @Override public void addTrailersCustomizer(BiConsumer<HttpHeaders, Throwable> trailersCustomizer) { if (trailersCustomizers == null) { trailersCustomizers = new ArrayList<>(); } trailersCustomizers.add(trailersCustomizer); } @Override public void setExceptionCustomizer(Function<Throwable, ?> exceptionCustomizer) { this.exceptionCustomizer = exceptionCustomizer; } public HttpMessageEncoder getResponseEncoder() { return responseEncoder; } public void setResponseEncoder(HttpMessageEncoder responseEncoder) { this.responseEncoder = responseEncoder; } @Override public final void onNext(Object data) { if (closed) { return; } try { doOnNext(data); } catch (Throwable t) { LOGGER.warn(INTERNAL_ERROR, "", "", "Error while doOnNext", t); Throwable throwable = t; try { doOnError(throwable); } catch (Throwable t1) { LOGGER.warn(INTERNAL_ERROR, "", "", "Error while doOnError, original error: " + throwable, t1); throwable = t1; } onCompleted(throwable); } } @Override public final void onError(Throwable throwable) { if (closed) { return; } try { throwable = customizeError(throwable); if (throwable == null) { return; } } catch (Throwable t) { LOGGER.warn(INTERNAL_ERROR, "", "", "Error while handleError, original error: " + throwable, t); throwable = t; } try { doOnError(throwable); } catch (Throwable t) { LOGGER.warn(INTERNAL_ERROR, "", "", "Error while doOnError, original error: " + throwable, t); throwable = t; } onCompleted(throwable); } @Override public final void onCompleted() { if (closed) { return; } onCompleted(null); } protected void doOnNext(Object data) throws Throwable { int statusCode = resolveStatusCode(data); if (!headerSent) { sendMetadata(buildMetadata(statusCode, data, null, HttpOutputMessage.EMPTY_MESSAGE)); } sendMessage(buildMessage(statusCode, data)); } protected final int resolveStatusCode(Object data) { if (data instanceof HttpResult) { int status = ((HttpResult<?>) data).getStatus(); if (status >= 100) { return status; } } return HttpStatus.OK.getCode(); } protected final HttpMetadata buildMetadata( int statusCode, Object data, Throwable throwable, HttpOutputMessage message) { HttpResponse response = RpcContext.getServiceContext().getResponse(HttpResponse.class); HttpMetadata metadata = encodeHttpMetadata(message == null); HttpHeaders headers = metadata.headers(); if (response != null && response.headers() != null) { headers.set(response.headers()); } headers.set(HttpHeaderNames.STATUS.getKey(), HttpUtils.toStatusString(statusCode)); if (message != null) { headers.set(HttpHeaderNames.CONTENT_TYPE.getKey(), responseEncoder.contentType()); } customizeHeaders(headers, throwable, message); if (data instanceof HttpResult) { HttpResult<?> result = (HttpResult<?>) data; if (result.getHeaders() != null) { headers.set(result.getHeaders()); } } return metadata; } protected abstract HttpMetadata encodeHttpMetadata(boolean endStream); protected void customizeHeaders(HttpHeaders headers, Throwable throwable, HttpOutputMessage message) { List<BiConsumer<HttpHeaders, Throwable>> headersCustomizers = this.headersCustomizers; if (headersCustomizers != null) { for (int i = 0, size = headersCustomizers.size(); i < size; i++) { headersCustomizers.get(i).accept(headers, throwable); } } } protected final void sendMetadata(HttpMetadata metadata) { if (headerSent) { return; } getHttpChannel().writeHeader(metadata); headerSent = true; if (LOGGER.isDebugEnabled()) { LOGGER.debug("Http response headers sent: " + metadata.headers()); } } protected HttpOutputMessage buildMessage(int statusCode, Object data) throws Throwable { if (statusCode < 200 || statusCode == 204 || statusCode == 304) { return null; } if (data instanceof HttpResult) { data = ((HttpResult<?>) data).getBody(); } if (data == null && statusCode != 200) { return null; } if (LOGGER.isDebugEnabled()) { try { String text; if (data instanceof byte[]) { text = new String((byte[]) data, StandardCharsets.UTF_8); } else { text = JsonUtils.toJson(data); } LOGGER.debug("Http response body sent: '{}' by [{}]", text, httpChannel); } catch (Throwable ignored) { } } HttpOutputMessage message = encodeHttpOutputMessage(data); try { preOutputMessage(message); responseEncoder.encode(message.getBody(), data); } catch (Throwable t) { message.close(); throw t; } return message; } protected HttpOutputMessage encodeHttpOutputMessage(Object data) { return getHttpChannel().newOutputMessage(); } protected final void sendMessage(HttpOutputMessage message) throws Throwable { if (message == null) { return; } getHttpChannel().writeMessage(message); postOutputMessage(message); } protected void preOutputMessage(HttpOutputMessage message) throws Throwable {} protected void postOutputMessage(HttpOutputMessage message) throws Throwable {} protected Throwable customizeError(Throwable throwable) { if (exceptionCustomizer == null) { return throwable; } Object result = exceptionCustomizer.apply(throwable); if (result == null) { return throwable; } if (result instanceof Throwable) { return (Throwable) result; } onNext(result); return null; } protected void doOnError(Throwable throwable) throws Throwable { int statusCode = resolveErrorStatusCode(throwable); Object data = buildErrorResponse(statusCode, throwable); if (!headerSent) { sendMetadata(buildMetadata(statusCode, data, throwable, HttpOutputMessage.EMPTY_MESSAGE)); } sendMessage(buildMessage(statusCode, data)); } protected final int resolveErrorStatusCode(Throwable throwable) { if (throwable == null) { return HttpStatus.OK.getCode(); } if (throwable instanceof HttpStatusException) { return ((HttpStatusException) throwable).getStatusCode(); } return HttpStatus.INTERNAL_SERVER_ERROR.getCode(); } protected final ErrorResponse buildErrorResponse(int statusCode, Throwable throwable) { ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setStatus(HttpUtils.toStatusString(statusCode)); if (throwable instanceof HttpStatusException) { errorResponse.setMessage(((HttpStatusException) throwable).getDisplayMessage()); } else { errorResponse.setMessage(getDisplayMessage(throwable)); } return errorResponse; } protected String getDisplayMessage(Throwable throwable) { return "Internal Server Error"; } protected void onCompleted(Throwable throwable) { if (completed) { return; } doOnCompleted(throwable); completed = true; } protected void doOnCompleted(Throwable throwable) { HttpMetadata trailerMetadata = encodeTrailers(throwable); if (trailerMetadata == null) { return; } HttpHeaders headers = trailerMetadata.headers(); if (!headerSent) { headers.set(HttpHeaderNames.STATUS.getKey(), HttpUtils.toStatusString(resolveErrorStatusCode(throwable))); headers.set(HttpHeaderNames.CONTENT_TYPE.getKey(), getContentType()); } customizeTrailers(headers, throwable); getHttpChannel().writeHeader(trailerMetadata); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Http response trailers sent: " + headers); } } protected HttpMetadata encodeTrailers(Throwable throwable) { return null; } protected String getContentType() { return responseEncoder.contentType(); } protected boolean isHeaderSent() { return headerSent; } protected void customizeTrailers(HttpHeaders headers, Throwable throwable) { List<BiConsumer<HttpHeaders, Throwable>> trailersCustomizers = this.trailersCustomizers; if (trailersCustomizers != null) { for (int i = 0, size = trailersCustomizers.size(); i < size; i++) { trailersCustomizers.get(i).accept(headers, throwable); } } } @Override public void close() { closed(); } protected final void closed() { closed = true; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpUtils.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpUtils.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.io.StreamUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.http12.exception.DecodeException; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Locale; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufInputStream; import io.netty.buffer.ByteBufOutputStream; import io.netty.buffer.UnpooledByteBufAllocator; import io.netty.handler.codec.http.DefaultFullHttpRequest; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http.cookie.Cookie; import io.netty.handler.codec.http.cookie.CookieHeaderNames.SameSite; import io.netty.handler.codec.http.cookie.DefaultCookie; import io.netty.handler.codec.http.cookie.ServerCookieDecoder; import io.netty.handler.codec.http.cookie.ServerCookieEncoder; import io.netty.handler.codec.http.multipart.Attribute; import io.netty.handler.codec.http.multipart.DefaultHttpDataFactory; import io.netty.handler.codec.http.multipart.FileUpload; import io.netty.handler.codec.http.multipart.HttpDataFactory; import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder; import io.netty.handler.codec.http.multipart.InterfaceHttpData; public final class HttpUtils { public static final ByteBufAllocator HEAP_ALLOC = new UnpooledByteBufAllocator(false, false); public static final HttpDataFactory DATA_FACTORY = new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE); public static final String CHARSET_PREFIX = "charset="; private HttpUtils() {} public static String getStatusMessage(int status) { return HttpResponseStatus.valueOf(status).reasonPhrase(); } public static String toStatusString(int statusCode) { if (statusCode == 200) { return HttpStatus.OK.getStatusString(); } if (statusCode == 500) { return HttpStatus.INTERNAL_SERVER_ERROR.getStatusString(); } return Integer.toString(statusCode); } public static List<HttpCookie> decodeCookies(String value) { List<HttpCookie> cookies = new ArrayList<>(); for (Cookie c : ServerCookieDecoder.LAX.decodeAll(value)) { cookies.add(new HttpCookie(c.name(), c.value())); } return cookies; } public static String parseCharset(String contentType) { String charset = null; if (contentType == null) { charset = StringUtils.EMPTY_STRING; } else { int index = contentType.lastIndexOf(CHARSET_PREFIX); if (index == -1) { charset = StringUtils.EMPTY_STRING; } else { charset = contentType.substring(index + CHARSET_PREFIX.length()).trim(); int splits = charset.indexOf(CommonConstants.SEMICOLON_SEPARATOR); if (splits == -1) { return charset; } else { return charset.substring(0, splits).trim(); } } } return charset; } public static String encodeCookie(HttpCookie cookie) { DefaultCookie c = new DefaultCookie(cookie.name(), cookie.value()); c.setPath(cookie.path()); c.setDomain(cookie.domain()); c.setMaxAge(cookie.maxAge()); c.setSecure(cookie.secure()); c.setHttpOnly(cookie.httpOnly()); c.setSameSite(SameSite.valueOf(cookie.sameSite())); return ServerCookieEncoder.LAX.encode(c); } public static List<String> parseAccept(String header) { if (header == null) { return new ArrayList<>(); } List<Item<String>> mediaTypes = new ArrayList<>(); for (String item : StringUtils.tokenize(header, ',')) { int index = item.indexOf(';'); mediaTypes.add(new Item<>(StringUtils.substring(item, 0, index), parseQuality(item, index))); } return Item.sortAndGet(mediaTypes); } public static float parseQuality(String expr, int index) { float quality = 1.0F; if (index != -1) { int qStart = expr.indexOf("q=", index + 1); if (qStart != -1) { qStart += 2; int qEnd = expr.indexOf(',', qStart); String qString = qEnd == -1 ? expr.substring(qStart) : expr.substring(qStart, qEnd).trim(); try { quality = Float.parseFloat(qString); } catch (NumberFormatException ignored) { } } } return quality; } public static List<Locale> parseAcceptLanguage(String header) { if (header == null) { return new ArrayList<>(); } List<Item<Locale>> locales = new ArrayList<>(); for (String item : StringUtils.tokenize(header, ',')) { String[] pair = StringUtils.tokenize(item, ';'); locales.add(new Item<>(parseLocale(pair[0]), pair.length > 1 ? Float.parseFloat(pair[1]) : 1.0F)); } return Item.sortAndGet(locales); } public static List<Locale> parseContentLanguage(String header) { if (header == null) { return new ArrayList<>(); } List<Locale> locales = new ArrayList<>(); for (String item : StringUtils.tokenize(header, ',')) { locales.add(parseLocale(item)); } return locales; } public static Locale parseLocale(String locale) { String[] parts = StringUtils.tokenize(locale, '-', '_'); switch (parts.length) { case 2: return new Locale(parts[0], parts[1]); case 3: return new Locale(parts[0], parts[1], parts[2]); default: return new Locale(parts[0]); } } @SuppressWarnings("deprecation") public static HttpPostRequestDecoder createPostRequestDecoder( HttpRequest request, InputStream inputStream, String charset) { ByteBuf data; boolean canMark = inputStream.markSupported(); try { if (canMark) { inputStream.mark(Integer.MAX_VALUE); } if (inputStream.available() == 0) { return null; } else { data = HEAP_ALLOC.buffer(); ByteBufOutputStream os = new ByteBufOutputStream(data); StreamUtils.copy(inputStream, os); } } catch (IOException e) { throw new DecodeException("Error while reading post data: " + e.getMessage(), e); } finally { try { if (canMark) { inputStream.reset(); } else { inputStream.close(); } } catch (IOException ignored) { } } DefaultFullHttpRequest nRequest = new DefaultFullHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.POST, request.uri(), data, new DefaultHttpHeaders(false), new DefaultHttpHeaders(false)); HttpHeaders headers = nRequest.headers(); request.headers().forEach(e -> headers.add(e.getKey(), e.getValue())); if (charset == null) { return new HttpPostRequestDecoder(DATA_FACTORY, nRequest); } else { return new HttpPostRequestDecoder(DATA_FACTORY, nRequest, Charset.forName(charset)); } } public static String readPostValue(InterfaceHttpData item) { try { return ((Attribute) item).getValue(); } catch (IOException e) { throw new DecodeException("Error while reading post value: " + e.getMessage(), e); } } public static HttpRequest.FileUpload readUpload(InterfaceHttpData item) { return new DefaultFileUploadAdapter((FileUpload) item); } private static final class DefaultFileUploadAdapter implements HttpRequest.FileUpload { private final FileUpload fu; private InputStream inputStream; DefaultFileUploadAdapter(FileUpload fu) { this.fu = fu; } @Override public String name() { return fu.getName(); } @Override public String filename() { return fu.getFilename(); } @Override public String contentType() { return fu.getContentType(); } @Override public int size() { return (int) fu.length(); } @Override public InputStream inputStream() { if (inputStream == null) { inputStream = new ByteBufInputStream(fu.content()); } return inputStream; } } private static final class Item<V> implements Comparable<Item<V>> { private final V value; private final float q; public Item(V value, float q) { this.value = value; this.q = q; } @Override public int compareTo(Item<V> o) { return Float.compare(o.q, q); } public static <T> List<T> sortAndGet(List<Item<T>> items) { int size = items.size(); if (size == 0) { return Collections.emptyList(); } if (size == 1) { return Collections.singletonList(items.get(0).value); } Collections.sort(items); List<T> values = new ArrayList<>(size); for (int i = 0; i < size; i++) { values.add(items.get(i).value); } return values; } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpChannelHolder.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpChannelHolder.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; public interface HttpChannelHolder { HttpChannel getHttpChannel(); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/LimitedByteBufOutputStream.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/LimitedByteBufOutputStream.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import org.apache.dubbo.remoting.http12.exception.HttpOverPayloadException; import java.io.IOException; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufOutputStream; public class LimitedByteBufOutputStream extends ByteBufOutputStream { private final int capacity; public LimitedByteBufOutputStream(ByteBuf byteBuf, int capacity) { super(byteBuf); this.capacity = capacity == 0 ? Integer.MAX_VALUE : capacity; } @Override public void write(int b) throws IOException { ensureCapacity(1); super.write(b); } @Override public void write(byte[] b) throws IOException { ensureCapacity(b.length); super.write(b); } @Override public void write(byte[] b, int off, int len) throws IOException { ensureCapacity(len); super.write(b, off, len); } private void ensureCapacity(int len) { if (writtenBytes() + len > capacity) { throw new HttpOverPayloadException("Response Entity Too Large"); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/LimitedByteArrayOutputStream.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/LimitedByteArrayOutputStream.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import org.apache.dubbo.remoting.http12.exception.HttpOverPayloadException; import java.io.ByteArrayOutputStream; import java.io.IOException; public class LimitedByteArrayOutputStream extends ByteArrayOutputStream { private final int capacity; public LimitedByteArrayOutputStream(int capacity) { super(); this.capacity = capacity == 0 ? Integer.MAX_VALUE : capacity; } public LimitedByteArrayOutputStream(int size, int capacity) { super(size); this.capacity = capacity == 0 ? Integer.MAX_VALUE : capacity; } @Override public void write(int b) { ensureCapacity(1); super.write(b); } @Override public void write(byte[] b) throws IOException { ensureCapacity(b.length); super.write(b); } @Override public void write(byte[] b, int off, int len) { ensureCapacity(len); super.write(b, off, len); } private void ensureCapacity(int len) { if (size() + len > capacity) { throw new HttpOverPayloadException("Response Entity Too Large"); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/ErrorCodeHolder.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/ErrorCodeHolder.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; public interface ErrorCodeHolder { long getErrorCode(); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/FlowControlStreamObserver.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/FlowControlStreamObserver.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import org.apache.dubbo.common.stream.StreamObserver; public interface FlowControlStreamObserver<T> extends StreamObserver<T> { /** * Requests the peer to produce {@code count} more messages to be delivered to the 'inbound' * {@link StreamObserver}. * * <p>This method is safe to call from multiple threads without external synchronization. * * @param count more messages */ void request(int count); boolean isAutoRequestN(); /** * Swaps to manual flow control where no message will be delivered to {@link * StreamObserver#onNext(Object)} unless it is {@link #request request()}ed. Since {@code * request()} may not be called before the call is started, a number of initial requests may be * specified. */ void disableAutoFlowControl(); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/ErrorResponse.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/ErrorResponse.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import org.apache.dubbo.common.utils.ToStringUtils; import java.io.Serializable; public class ErrorResponse implements Serializable { private static final long serialVersionUID = 6828386002146790334L; private String status; private String message; public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } @Override public String toString() { return ToStringUtils.printToString(this); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpMetadata.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpMetadata.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; public interface HttpMetadata { HttpHeaders headers(); default String contentType() { return header(HttpHeaderNames.CONTENT_TYPE.getKey()); } default String header(CharSequence name) { return headers().getFirst(name); } default HttpMetadata header(CharSequence name, String value) { headers().set(name, value); return this; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpConstants.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpConstants.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; public final class HttpConstants { public static final String TRAILERS = "trailers"; public static final String CHUNKED = "chunked"; public static final String NO_CACHE = "no-cache"; public static final String X_FORWARDED_PROTO = "x-forwarded-proto"; public static final String X_FORWARDED_HOST = "x-forwarded-host"; public static final String X_FORWARDED_PORT = "x-forwarded-port"; public static final String HTTPS = "https"; public static final String HTTP = "http"; private HttpConstants() {} }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpMethods.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpMethods.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import java.nio.charset.StandardCharsets; public enum HttpMethods { GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE; public static final byte[][] HTTP_METHODS_BYTES; static { HttpMethods[] methods = values(); int len = methods.length; HTTP_METHODS_BYTES = new byte[len][]; for (int i = 0; i < len; i++) { HTTP_METHODS_BYTES[i] = methods[i].name().getBytes(StandardCharsets.ISO_8859_1); } } public boolean is(String name) { return name().equals(name); } public boolean supportBody() { return this == POST || this == PUT || this == PATCH; } @SuppressWarnings("StringEquality") public static HttpMethods of(String name) { // fast-path if (name == GET.name()) { return GET; } else if (name == POST.name()) { return POST; } return valueOf(name); } public static boolean isGet(String name) { return GET.name().equals(name); } public static boolean isPost(String name) { return POST.name().equals(name); } public static boolean supportBody(String name) { return name.charAt(0) == 'P'; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpHeaders.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpHeaders.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.remoting.http12.message.DefaultHttpHeaders; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.function.BiConsumer; public interface HttpHeaders extends Iterable<Entry<CharSequence, String>> { int size(); boolean isEmpty(); boolean containsKey(CharSequence key); String getFirst(CharSequence name); List<String> get(CharSequence key); HttpHeaders add(CharSequence name, String value); HttpHeaders add(CharSequence name, Iterable<String> value); HttpHeaders add(CharSequence name, String... value); HttpHeaders add(Map<? extends CharSequence, ? extends Iterable<String>> map); HttpHeaders add(HttpHeaders headers); HttpHeaders set(CharSequence name, String value); HttpHeaders set(CharSequence name, Iterable<String> value); HttpHeaders set(CharSequence name, String... value); HttpHeaders set(Map<? extends CharSequence, ? extends Iterable<String>> map); HttpHeaders set(HttpHeaders headers); List<String> remove(CharSequence key); void clear(); Set<String> names(); Set<CharSequence> nameSet(); Map<String, List<String>> asMap(); @Override Iterator<Entry<CharSequence, String>> iterator(); default Map<String, List<String>> toMap() { Map<String, List<String>> map = CollectionUtils.newLinkedHashMap(size()); for (Entry<CharSequence, String> entry : this) { map.computeIfAbsent(entry.getKey().toString(), k -> new ArrayList<>(1)) .add(entry.getValue()); } return map; } default void forEach(BiConsumer<String, String> action) { for (Entry<CharSequence, String> entry : this) { action.accept(entry.getKey().toString(), entry.getValue()); } } static HttpHeaders create() { return new DefaultHttpHeaders(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/ServerHttpChannelObserver.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/ServerHttpChannelObserver.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; import org.apache.dubbo.common.stream.StreamObserver; import java.util.function.BiConsumer; import java.util.function.Function; public interface ServerHttpChannelObserver<H extends HttpChannel> extends StreamObserver<Object>, AutoCloseable { H getHttpChannel(); void addHeadersCustomizer(BiConsumer<HttpHeaders, Throwable> headersCustomizer); void addTrailersCustomizer(BiConsumer<HttpHeaders, Throwable> trailersCustomizer); void setExceptionCustomizer(Function<Throwable, ?> exceptionCustomizer); void close(); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpStatus.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpStatus.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12; public enum HttpStatus { OK(200), CREATED(201), ACCEPTED(202), NO_CONTENT(204), MOVED_PERMANENTLY(301), FOUND(302), BAD_REQUEST(400), UNAUTHORIZED(401), FORBIDDEN(403), NOT_FOUND(404), METHOD_NOT_ALLOWED(405), NOT_ACCEPTABLE(406), REQUEST_TIMEOUT(408), CONFLICT(409), UNSUPPORTED_MEDIA_TYPE(415), INTERNAL_SERVER_ERROR(500); private final int code; private final String statusString; HttpStatus(int code) { this.code = code; this.statusString = String.valueOf(code); } public int getCode() { return code; } public String getStatusString() { return statusString; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/command/HeaderQueueCommand.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/command/HeaderQueueCommand.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.command; import org.apache.dubbo.remoting.http12.HttpMetadata; public class HeaderQueueCommand extends HttpChannelQueueCommand { private final HttpMetadata httpMetadata; public HeaderQueueCommand(HttpMetadata httpMetadata) { this.httpMetadata = httpMetadata; } @Override public void run() { getHttpChannel().writeHeader(httpMetadata).whenComplete((unused, throwable) -> { if (throwable != null) { completeExceptionally(throwable); } else { complete(unused); } }); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/command/HttpWriteQueue.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/command/HttpWriteQueue.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.command; import org.apache.dubbo.common.BatchExecutorQueue; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; public class HttpWriteQueue extends BatchExecutorQueue<HttpChannelQueueCommand> { private final Executor executor; public HttpWriteQueue(Executor executor) { this.executor = executor; } public CompletableFuture<Void> enqueue(HttpChannelQueueCommand cmd) { this.enqueue(cmd, this.executor); return cmd; } @Override protected void prepare(HttpChannelQueueCommand item) { item.run(); } @Override protected void flush(HttpChannelQueueCommand item) { item.run(); item.getHttpChannel().flush(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/command/HttpChannelQueueCommand.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/command/HttpChannelQueueCommand.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.command; import org.apache.dubbo.remoting.http12.HttpChannel; import org.apache.dubbo.remoting.http12.HttpChannelHolder; import java.util.concurrent.CompletableFuture; public abstract class HttpChannelQueueCommand extends CompletableFuture<Void> implements QueueCommand, HttpChannelHolder { private HttpChannelHolder httpChannelHolder; public void setHttpChannel(HttpChannelHolder httpChannelHolder) { this.httpChannelHolder = httpChannelHolder; } public HttpChannel getHttpChannel() { return httpChannelHolder.getHttpChannel(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/command/QueueCommand.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/command/QueueCommand.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.command; public interface QueueCommand extends Runnable {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/command/DataQueueCommand.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/command/DataQueueCommand.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.command; import org.apache.dubbo.remoting.http12.HttpOutputMessage; public class DataQueueCommand extends HttpChannelQueueCommand { private final HttpOutputMessage httpOutputMessage; public DataQueueCommand(HttpOutputMessage httpMessage) { this.httpOutputMessage = httpMessage; } @Override public void run() { getHttpChannel().writeMessage(httpOutputMessage).whenComplete((unused, throwable) -> { if (throwable != null) { completeExceptionally(throwable); } else { complete(unused); } }); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/CancelStreamException.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/CancelStreamException.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; import org.apache.dubbo.remoting.http12.ErrorCodeHolder; public class CancelStreamException extends RuntimeException implements ErrorCodeHolder { private static final long serialVersionUID = 1L; private final boolean cancelByRemote; private final long errorCode; private CancelStreamException(boolean cancelByRemote, long errorCode) { this.cancelByRemote = cancelByRemote; this.errorCode = errorCode; } public boolean isCancelByRemote() { return cancelByRemote; } public static CancelStreamException fromRemote(long errorCode) { return new CancelStreamException(true, errorCode); } public static CancelStreamException fromLocal(long errorCode) { return new CancelStreamException(false, errorCode); } @Override public long getErrorCode() { return errorCode; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/H2StreamChannel.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/H2StreamChannel.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; import org.apache.dubbo.remoting.http12.HttpChannel; import java.util.concurrent.CompletableFuture; public interface H2StreamChannel extends HttpChannel { CompletableFuture<Void> writeResetFrame(long errorCode); @Override default Http2OutputMessage newOutputMessage() { return this.newOutputMessage(false); } Http2OutputMessage newOutputMessage(boolean endStream); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2Header.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2Header.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; import org.apache.dubbo.remoting.http12.RequestMetadata; public interface Http2Header extends RequestMetadata, Http2StreamFrame { @Override default String name() { return "HEADER"; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2TransportListener.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2TransportListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; public interface Http2TransportListener extends CancelableTransportListener<Http2Header, Http2InputMessage> { void close(); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2MetadataFrame.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2MetadataFrame.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; import org.apache.dubbo.remoting.http12.HttpHeaders; import io.netty.handler.codec.http2.Http2Headers.PseudoHeaderName; public final class Http2MetadataFrame implements Http2Header { private final long streamId; private final HttpHeaders headers; private final boolean endStream; public Http2MetadataFrame(HttpHeaders headers) { this(-1L, headers, false); } public Http2MetadataFrame(HttpHeaders headers, boolean endStream) { this(-1L, headers, endStream); } public Http2MetadataFrame(long streamId, HttpHeaders headers, boolean endStream) { this.streamId = streamId; this.headers = headers; this.endStream = endStream; } @Override public HttpHeaders headers() { return headers; } @Override public String method() { return headers.getFirst(PseudoHeaderName.METHOD.value()); } @Override public String path() { return headers.getFirst(PseudoHeaderName.PATH.value()); } @Override public long id() { return streamId; } @Override public boolean isEndStream() { return endStream; } @Override public String toString() { return "Http2MetadataFrame{method='" + method() + '\'' + ", path='" + path() + '\'' + ", contentType='" + contentType() + "', streamId=" + streamId + ", endStream=" + endStream + '}'; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2ServerTransportListenerFactory.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2ServerTransportListenerFactory.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionScope; import org.apache.dubbo.common.extension.SPI; import org.apache.dubbo.rpc.model.FrameworkModel; @SPI(scope = ExtensionScope.FRAMEWORK) public interface Http2ServerTransportListenerFactory { Http2TransportListener newInstance(H2StreamChannel streamChannel, URL url, FrameworkModel frameworkModel); boolean supportContentType(String contentType); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2CancelableStreamObserver.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2CancelableStreamObserver.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; import org.apache.dubbo.common.stream.StreamObserver; import org.apache.dubbo.rpc.CancellationContext; public interface Http2CancelableStreamObserver<T> extends StreamObserver<T> { void setCancellationContext(CancellationContext cancellationContext); CancellationContext getCancellationContext(); void cancel(Throwable throwable); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2StreamFrame.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2StreamFrame.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; public interface Http2StreamFrame { long id(); String name(); boolean isEndStream(); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/CancelableTransportListener.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/CancelableTransportListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; import org.apache.dubbo.remoting.http12.HttpInputMessage; import org.apache.dubbo.remoting.http12.HttpMetadata; import org.apache.dubbo.remoting.http12.HttpTransportListener; public interface CancelableTransportListener<HEADER extends HttpMetadata, MESSAGE extends HttpInputMessage> extends HttpTransportListener<HEADER, MESSAGE> { void cancelByRemote(long errorCode); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2OutputMessageFrame.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2OutputMessageFrame.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; import java.io.IOException; import java.io.OutputStream; import io.netty.buffer.ByteBufOutputStream; public final class Http2OutputMessageFrame implements Http2OutputMessage { private final OutputStream body; private final boolean endStream; public Http2OutputMessageFrame(OutputStream body, boolean endStream) { this.body = body; this.endStream = endStream; } @Override public OutputStream getBody() { return body; } @Override public void close() throws IOException { if (body instanceof ByteBufOutputStream) { ((ByteBufOutputStream) body).buffer().release(); } body.close(); } @Override public boolean isEndStream() { return endStream; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2OutputMessage.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2OutputMessage.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; import org.apache.dubbo.remoting.http12.HttpOutputMessage; public interface Http2OutputMessage extends HttpOutputMessage, Http2StreamFrame { @Override default String name() { return "DATA"; } @Override default long id() { return -1; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2ServerChannelObserver.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2ServerChannelObserver.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; import org.apache.dubbo.remoting.http12.AbstractServerHttpChannelObserver; import org.apache.dubbo.remoting.http12.ErrorCodeHolder; import org.apache.dubbo.remoting.http12.FlowControlStreamObserver; import org.apache.dubbo.remoting.http12.HttpConstants; import org.apache.dubbo.remoting.http12.HttpHeaderNames; import org.apache.dubbo.remoting.http12.HttpHeaders; import org.apache.dubbo.remoting.http12.HttpMetadata; import org.apache.dubbo.remoting.http12.message.StreamingDecoder; import org.apache.dubbo.remoting.http12.netty4.NettyHttpHeaders; import org.apache.dubbo.rpc.CancellationContext; import io.netty.handler.codec.http2.DefaultHttp2Headers; public class Http2ServerChannelObserver extends AbstractServerHttpChannelObserver<H2StreamChannel> implements FlowControlStreamObserver<Object>, Http2CancelableStreamObserver<Object> { private CancellationContext cancellationContext; private StreamingDecoder streamingDecoder; private boolean autoRequestN = true; public Http2ServerChannelObserver(H2StreamChannel h2StreamChannel) { super(h2StreamChannel); } public void setStreamingDecoder(StreamingDecoder streamingDecoder) { this.streamingDecoder = streamingDecoder; } @Override protected HttpMetadata encodeHttpMetadata(boolean endStream) { HttpHeaders headers = new NettyHttpHeaders<>(new DefaultHttp2Headers(false, 8)); headers.set(HttpHeaderNames.TE.getKey(), HttpConstants.TRAILERS); return new Http2MetadataFrame(headers, endStream); } @Override protected HttpMetadata encodeTrailers(Throwable throwable) { return new Http2MetadataFrame(new NettyHttpHeaders<>(new DefaultHttp2Headers(false, 4)), true); } @Override public void setCancellationContext(CancellationContext cancellationContext) { this.cancellationContext = cancellationContext; } @Override public CancellationContext getCancellationContext() { return cancellationContext; } @Override public void cancel(Throwable throwable) { if (throwable instanceof CancelStreamException) { if (((CancelStreamException) throwable).isCancelByRemote()) { closed(); } } if (cancellationContext != null) { cancellationContext.cancel(throwable); } long errorCode = 0; if (throwable instanceof ErrorCodeHolder) { errorCode = ((ErrorCodeHolder) throwable).getErrorCode(); } getHttpChannel().writeResetFrame(errorCode); } @Override public void request(int count) { streamingDecoder.request(count); } @Override public void disableAutoFlowControl() { autoRequestN = false; } @Override public boolean isAutoRequestN() { return autoRequestN; } @Override public void close() { super.close(); streamingDecoder.onStreamClosed(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2InputMessageFrame.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2InputMessageFrame.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; import org.apache.dubbo.common.utils.ClassUtils; import java.io.InputStream; public final class Http2InputMessageFrame implements Http2InputMessage { private final long streamId; private final InputStream body; private final boolean endStream; public Http2InputMessageFrame(InputStream body, boolean endStream) { this(-1L, body, endStream); } public Http2InputMessageFrame(long streamId, InputStream body, boolean endStream) { this.streamId = streamId; this.body = body; this.endStream = endStream; } @Override public InputStream getBody() { return body; } @Override public String name() { return "DATA"; } @Override public long id() { return streamId; } @Override public boolean isEndStream() { return endStream; } @Override public String toString() { return "Http2InputMessageFrame{body=" + ClassUtils.toShortString(body) + ", body=" + streamId + ", endStream=" + endStream + '}'; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2InputMessage.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2InputMessage.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; import org.apache.dubbo.remoting.http12.HttpInputMessage; public interface Http2InputMessage extends HttpInputMessage, Http2StreamFrame {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2ChannelDelegate.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2ChannelDelegate.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2; import org.apache.dubbo.remoting.http12.HttpMetadata; import org.apache.dubbo.remoting.http12.HttpOutputMessage; import java.net.SocketAddress; import java.util.concurrent.CompletableFuture; public class Http2ChannelDelegate implements H2StreamChannel { private final H2StreamChannel h2StreamChannel; public Http2ChannelDelegate(H2StreamChannel h2StreamChannel) { this.h2StreamChannel = h2StreamChannel; } public H2StreamChannel getH2StreamChannel() { return h2StreamChannel; } @Override public CompletableFuture<Void> writeHeader(HttpMetadata httpMetadata) { return h2StreamChannel.writeHeader(httpMetadata); } @Override public CompletableFuture<Void> writeMessage(HttpOutputMessage httpOutputMessage) { return h2StreamChannel.writeMessage(httpOutputMessage); } @Override public SocketAddress remoteAddress() { return h2StreamChannel.remoteAddress(); } @Override public SocketAddress localAddress() { return h2StreamChannel.localAddress(); } @Override public void flush() { h2StreamChannel.flush(); } @Override public CompletableFuture<Void> writeResetFrame(long errorCode) { return h2StreamChannel.writeResetFrame(errorCode); } @Override public Http2OutputMessage newOutputMessage(boolean endStream) { return h2StreamChannel.newOutputMessage(endStream); } @Override public String toString() { return "Http2ChannelDelegate{" + "h2StreamChannel=" + h2StreamChannel + '}'; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/command/ResetQueueCommand.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/command/ResetQueueCommand.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2.command; import org.apache.dubbo.remoting.http12.command.HttpChannelQueueCommand; import org.apache.dubbo.remoting.http12.h2.H2StreamChannel; public class ResetQueueCommand extends HttpChannelQueueCommand { private final long errorCode; public ResetQueueCommand(long errorCode) { this.errorCode = errorCode; } @Override public void run() { ((H2StreamChannel) getHttpChannel()).writeResetFrame(errorCode).whenComplete((unused, throwable) -> { if (throwable != null) { completeExceptionally(throwable); } else { complete(unused); } }); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/command/Http2WriteQueueChannel.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/command/Http2WriteQueueChannel.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h2.command; import org.apache.dubbo.remoting.http12.HttpMetadata; import org.apache.dubbo.remoting.http12.HttpOutputMessage; import org.apache.dubbo.remoting.http12.command.DataQueueCommand; import org.apache.dubbo.remoting.http12.command.HeaderQueueCommand; import org.apache.dubbo.remoting.http12.command.HttpWriteQueue; import org.apache.dubbo.remoting.http12.h2.H2StreamChannel; import org.apache.dubbo.remoting.http12.h2.Http2ChannelDelegate; import java.util.concurrent.CompletableFuture; public class Http2WriteQueueChannel extends Http2ChannelDelegate { private final HttpWriteQueue httpWriteQueue; public Http2WriteQueueChannel(H2StreamChannel h2StreamChannel, HttpWriteQueue httpWriteQueue) { super(h2StreamChannel); this.httpWriteQueue = httpWriteQueue; } @Override public CompletableFuture<Void> writeHeader(HttpMetadata httpMetadata) { HeaderQueueCommand cmd = new HeaderQueueCommand(httpMetadata); cmd.setHttpChannel(this::getH2StreamChannel); return httpWriteQueue.enqueue(cmd); } @Override public CompletableFuture<Void> writeMessage(HttpOutputMessage httpOutputMessage) { DataQueueCommand cmd = new DataQueueCommand(httpOutputMessage); cmd.setHttpChannel(this::getH2StreamChannel); return httpWriteQueue.enqueue(cmd); } @Override public CompletableFuture<Void> writeResetFrame(long errorCode) { ResetQueueCommand cmd = new ResetQueueCommand(errorCode); cmd.setHttpChannel(this::getH2StreamChannel); return this.httpWriteQueue.enqueue(cmd); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/UnsupportedMediaTypeException.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/UnsupportedMediaTypeException.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.exception; public class UnsupportedMediaTypeException extends HttpStatusException { private static final long serialVersionUID = 1L; private final String mediaType; public UnsupportedMediaTypeException(String mediaType) { super(415, "Unsupported Media Type '" + mediaType + "'"); this.mediaType = mediaType; } public String getMediaType() { return mediaType; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/DecodeException.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/DecodeException.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.exception; public class DecodeException extends HttpStatusException { private static final long serialVersionUID = 1L; public DecodeException() { super(500); } public DecodeException(String message) { super(500, message); } public DecodeException(Throwable cause) { super(500, cause); } public DecodeException(String message, Throwable cause) { super(500, message, cause); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/UnimplementedException.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/UnimplementedException.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.exception; public class UnimplementedException extends HttpStatusException { private static final long serialVersionUID = 1L; private final String unimplemented; public UnimplementedException(String unimplemented) { super(500, "unimplemented " + unimplemented); this.unimplemented = unimplemented; } public String getUnimplemented() { return unimplemented; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/HttpResultPayloadException.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/HttpResultPayloadException.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.exception; import org.apache.dubbo.remoting.http12.HttpResult; import org.apache.dubbo.remoting.http12.HttpStatus; public class HttpResultPayloadException extends HttpStatusException { private static final long serialVersionUID = 1L; private final HttpResult<?> result; public HttpResultPayloadException(HttpResult<?> result) { super(result.getStatus()); this.result = result; } public HttpResultPayloadException(int statusCode, Object body) { super(statusCode); result = HttpResult.of(statusCode, body); } public HttpResultPayloadException(Object body) { this(HttpStatus.OK.getCode(), body); } @Override public synchronized Throwable fillInStackTrace() { return this; } @SuppressWarnings("unchecked") public <T> HttpResult<T> getResult() { return (HttpResult<T>) result; } @SuppressWarnings("unchecked") public <T> T getBody() { return (T) result.getBody(); } @Override public String getMessage() { return String.valueOf(result); } @Override public String toString() { return "HttpResultPayloadException{result=" + result + '}'; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/HttpStatusException.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/HttpStatusException.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.exception; import org.apache.dubbo.remoting.http12.HttpUtils; public class HttpStatusException extends RuntimeException { private static final long serialVersionUID = 1L; private final int statusCode; public HttpStatusException(int statusCode) { super(HttpUtils.getStatusMessage(statusCode)); this.statusCode = statusCode; } public HttpStatusException(int statusCode, String message) { super(message); this.statusCode = statusCode; } public HttpStatusException(int statusCode, Throwable cause) { super(HttpUtils.getStatusMessage(statusCode), cause); this.statusCode = statusCode; } public HttpStatusException(int statusCode, String message, Throwable cause) { super(message, cause); this.statusCode = statusCode; } public int getStatusCode() { return statusCode; } public String getDisplayMessage() { return getMessage(); } @Override public String toString() { return getClass().getName() + ": status=" + statusCode + ", " + getMessage(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/HttpRequestTimeout.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/HttpRequestTimeout.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.exception; import org.apache.dubbo.remoting.http12.HttpStatus; public class HttpRequestTimeout extends HttpStatusException { private static final long serialVersionUID = 1L; private final String side; private HttpRequestTimeout(String side) { super(HttpStatus.REQUEST_TIMEOUT.getCode()); this.side = side; } public String getSide() { return side; } public static HttpRequestTimeout serverSide() { return new HttpRequestTimeout("server"); } public static HttpRequestTimeout clientSide() { return new HttpRequestTimeout("client"); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/HttpOverPayloadException.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/HttpOverPayloadException.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.exception; public class HttpOverPayloadException extends HttpStatusException { private static final long serialVersionUID = 1L; public HttpOverPayloadException(String message) { super(500, message); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/EncodeException.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/exception/EncodeException.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.exception; public class EncodeException extends HttpStatusException { private static final long serialVersionUID = 1L; public EncodeException(String message) { super(500, message); } public EncodeException(String message, Throwable cause) { super(500, message); } public EncodeException(Throwable cause) { super(500, cause); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1ServerTransportListener.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1ServerTransportListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h1; import org.apache.dubbo.remoting.http12.HttpInputMessage; import org.apache.dubbo.remoting.http12.HttpTransportListener; import org.apache.dubbo.remoting.http12.RequestMetadata; public interface Http1ServerTransportListener extends HttpTransportListener<RequestMetadata, HttpInputMessage> {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1OutputMessage.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1OutputMessage.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h1; import org.apache.dubbo.remoting.http12.HttpOutputMessage; import java.io.IOException; import java.io.OutputStream; import io.netty.buffer.ByteBufOutputStream; public final class Http1OutputMessage implements HttpOutputMessage { private final OutputStream outputStream; public Http1OutputMessage(OutputStream outputStream) { this.outputStream = outputStream; } @Override public OutputStream getBody() { return outputStream; } @Override public void close() throws IOException { if (outputStream instanceof ByteBufOutputStream) { ((ByteBufOutputStream) outputStream).buffer().release(); } outputStream.close(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1ServerTransportListenerFactory.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1ServerTransportListenerFactory.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h1; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionScope; import org.apache.dubbo.common.extension.SPI; import org.apache.dubbo.remoting.http12.HttpChannel; import org.apache.dubbo.rpc.model.FrameworkModel; @SPI(scope = ExtensionScope.FRAMEWORK) public interface Http1ServerTransportListenerFactory { Http1ServerTransportListener newInstance(HttpChannel httpChannel, URL url, FrameworkModel frameworkModel); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1Metadata.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1Metadata.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h1; import org.apache.dubbo.remoting.http12.HttpHeaders; import org.apache.dubbo.remoting.http12.HttpMetadata; public final class Http1Metadata implements HttpMetadata { private final HttpHeaders headers; public Http1Metadata(HttpHeaders headers) { this.headers = headers; } @Override public HttpHeaders headers() { return headers; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/DefaultHttp1Request.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/DefaultHttp1Request.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h1; import org.apache.dubbo.remoting.http12.HttpHeaders; import org.apache.dubbo.remoting.http12.HttpInputMessage; import org.apache.dubbo.remoting.http12.RequestMetadata; import java.io.IOException; import java.io.InputStream; public final class DefaultHttp1Request implements Http1Request { private final RequestMetadata httpMetadata; private final HttpInputMessage httpInputMessage; public DefaultHttp1Request(RequestMetadata httpMetadata, HttpInputMessage httpInputMessage) { this.httpMetadata = httpMetadata; this.httpInputMessage = httpInputMessage; } @Override public InputStream getBody() { return httpInputMessage.getBody(); } @Override public HttpHeaders headers() { return httpMetadata.headers(); } @Override public String method() { return httpMetadata.method(); } @Override public String path() { return httpMetadata.path(); } @Override public void close() throws IOException { httpInputMessage.close(); } @Override public String toString() { return "Http1Request{method='" + method() + '\'' + ", path='" + path() + '\'' + ", contentType='" + contentType() + "'}"; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1ServerChannelObserver.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1ServerChannelObserver.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h1; import org.apache.dubbo.remoting.http12.AbstractServerHttpChannelObserver; import org.apache.dubbo.remoting.http12.HttpChannel; import org.apache.dubbo.remoting.http12.HttpMetadata; import org.apache.dubbo.remoting.http12.HttpOutputMessage; import org.apache.dubbo.remoting.http12.netty4.h1.NettyHttp1HttpHeaders; public class Http1ServerChannelObserver extends AbstractServerHttpChannelObserver<HttpChannel> { public Http1ServerChannelObserver(HttpChannel httpChannel) { super(httpChannel); } @Override protected HttpMetadata encodeHttpMetadata(boolean endStream) { return new Http1Metadata(new NettyHttp1HttpHeaders()); } @Override protected void doOnCompleted(Throwable throwable) { getHttpChannel().writeMessage(HttpOutputMessage.EMPTY_MESSAGE); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1RequestMetadata.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1RequestMetadata.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h1; import org.apache.dubbo.remoting.http12.HttpHeaders; import org.apache.dubbo.remoting.http12.RequestMetadata; public final class Http1RequestMetadata implements RequestMetadata { private final HttpHeaders headers; private final String method; private final String path; public Http1RequestMetadata(HttpHeaders headers, String method, String path) { this.headers = headers; this.method = method; this.path = path; } @Override public HttpHeaders headers() { return headers; } @Override public String method() { return method; } @Override public String path() { return path; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1InputMessage.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1InputMessage.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h1; import org.apache.dubbo.remoting.http12.HttpInputMessage; import java.io.InputStream; public final class Http1InputMessage implements HttpInputMessage { private final InputStream body; public Http1InputMessage(InputStream body) { this.body = body; } @Override public InputStream getBody() { return body; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/DefaultHttp1Response.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/DefaultHttp1Response.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h1; import org.apache.dubbo.remoting.http12.HttpHeaders; import org.apache.dubbo.remoting.http12.HttpInputMessage; import org.apache.dubbo.remoting.http12.HttpMetadata; import java.io.IOException; import java.io.InputStream; public final class DefaultHttp1Response implements HttpMetadata, HttpInputMessage { private final HttpMetadata httpMetadata; private final HttpInputMessage httpInputMessage; public DefaultHttp1Response(HttpMetadata httpMetadata, HttpInputMessage httpInputMessage) { this.httpMetadata = httpMetadata; this.httpInputMessage = httpInputMessage; } @Override public InputStream getBody() { return httpInputMessage.getBody(); } @Override public HttpHeaders headers() { return httpMetadata.headers(); } @Override public void close() throws IOException { httpInputMessage.close(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1Request.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1Request.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.h1; import org.apache.dubbo.remoting.http12.HttpInputMessage; import org.apache.dubbo.remoting.http12.RequestMetadata; public interface Http1Request extends RequestMetadata, HttpInputMessage {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/DefaultHttpMessageAdapterFactory.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/DefaultHttpMessageAdapterFactory.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.message; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.remoting.http12.HttpChannel; import org.apache.dubbo.remoting.http12.HttpMetadata; import org.apache.dubbo.remoting.http12.HttpResponse; @Activate public final class DefaultHttpMessageAdapterFactory implements HttpMessageAdapterFactory<DefaultHttpRequest, HttpMetadata, Void> { @Override public DefaultHttpRequest adaptRequest(HttpMetadata rawRequest, HttpChannel channel) { return new DefaultHttpRequest(rawRequest, channel); } @Override public HttpResponse adaptResponse(DefaultHttpRequest request, HttpMetadata rawRequest, Void rawResponse) { return new DefaultHttpResponse(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/DefaultListeningDecoder.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/DefaultListeningDecoder.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.message; import java.io.InputStream; public class DefaultListeningDecoder implements ListeningDecoder { private final HttpMessageDecoder httpMessageDecoder; private final Class<?>[] targetTypes; private Listener listener; public DefaultListeningDecoder(HttpMessageDecoder httpMessageDecoder, Class<?>[] targetTypes) { this.httpMessageDecoder = httpMessageDecoder; this.targetTypes = targetTypes; } @Override public void setListener(Listener listener) { this.listener = listener; } @Override public void decode(InputStream inputStream) { Object[] decode = this.httpMessageDecoder.decode(inputStream, targetTypes); this.listener.onMessage(decode); } @Override public void close() { this.listener.onClose(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/CodecMediaType.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/CodecMediaType.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.message; public interface CodecMediaType { MediaType mediaType(); default boolean supports(String mediaType) { return mediaType.startsWith(mediaType().getName()); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/HttpHeadersMapAdapter.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/HttpHeadersMapAdapter.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.message; import org.apache.dubbo.remoting.http12.HttpHeaders; import java.util.AbstractCollection; import java.util.AbstractSet; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; public final class HttpHeadersMapAdapter implements Map<String, List<String>> { private final HttpHeaders headers; public HttpHeadersMapAdapter(HttpHeaders headers) { this.headers = headers; } @Override public int size() { return headers.size(); } @Override public boolean isEmpty() { return headers.isEmpty(); } @Override public boolean containsKey(Object key) { return key instanceof CharSequence && headers.containsKey((CharSequence) key); } @Override public boolean containsValue(Object value) { for (Entry<CharSequence, String> entry : headers) { if (Objects.equals(value, entry.getValue())) { return true; } } return false; } @Override public List<String> get(Object key) { return key instanceof CharSequence ? headers.get((CharSequence) key) : Collections.emptyList(); } @Override public List<String> put(String key, List<String> value) { List<String> all = headers.get(key); headers.set(key, value); return all; } @Override public List<String> remove(Object key) { return key instanceof CharSequence ? headers.remove((CharSequence) key) : Collections.emptyList(); } @Override public void putAll(Map<? extends String, ? extends List<String>> m) { headers.set(m); } @Override public void clear() { headers.clear(); } @Override public Set<String> keySet() { return headers.names(); } @Override public Collection<List<String>> values() { Set<CharSequence> names = headers.nameSet(); return new AbstractCollection<List<String>>() { @Override public Iterator<List<String>> iterator() { Iterator<CharSequence> it = names.iterator(); return new Iterator<List<String>>() { @Override public boolean hasNext() { return it.hasNext(); } @Override public List<String> next() { CharSequence next = it.next(); return next == null ? Collections.emptyList() : headers.get(next); } }; } @Override public int size() { return names.size(); } }; } @Override public Set<Entry<String, List<String>>> entrySet() { Set<CharSequence> names = headers.nameSet(); return new AbstractSet<Entry<String, List<String>>>() { @Override public Iterator<Entry<String, List<String>>> iterator() { Iterator<CharSequence> it = names.iterator(); return new Iterator<Entry<String, List<String>>>() { @Override public boolean hasNext() { return it.hasNext(); } @Override public Entry<String, List<String>> next() { CharSequence next = it.next(); return new Entry<String, List<String>>() { @Override public String getKey() { return next == null ? null : next.toString(); } @Override public List<String> getValue() { return next == null ? Collections.emptyList() : get(next); } @Override public List<String> setValue(List<String> value) { if (next == null) { return Collections.emptyList(); } List<String> values = get(next); headers.set(next, value); return values; } }; } }; } @Override public int size() { return names.size(); } }; } @Override public boolean equals(Object obj) { return obj instanceof HttpHeadersMapAdapter && headers.equals(((HttpHeadersMapAdapter) obj).headers); } @Override public int hashCode() { return headers.hashCode(); } @Override public String toString() { return "HttpHeadersMapAdapter{" + "headers=" + headers + '}'; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/HttpMessageAdapterFactory.java
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/HttpMessageAdapterFactory.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dubbo.remoting.http12.message; import org.apache.dubbo.common.extension.ExtensionScope; import org.apache.dubbo.common.extension.SPI; import org.apache.dubbo.remoting.http12.HttpChannel; import org.apache.dubbo.remoting.http12.HttpRequest; import org.apache.dubbo.remoting.http12.HttpResponse; @SPI(scope = ExtensionScope.FRAMEWORK) public interface HttpMessageAdapterFactory<HR extends HttpRequest, REQUEST, RESPONSE> { HR adaptRequest(REQUEST rawRequest, HttpChannel channel); HttpResponse adaptResponse(HR request, REQUEST rawRequest, RESPONSE rawResponse); default HttpResponse adaptResponse(HR request, REQUEST rawRequest) { return adaptResponse(request, rawRequest, null); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false