use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.
the class AbstractClient method removeAttribute.
public void removeAttribute(String key) {
Channel channel = getChannel();
if (channel == null)
return;
channel.removeAttribute(key);
}
use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.
the class ServerPeer method getChannel.
@Override
public Channel getChannel(InetSocketAddress remoteAddress) {
String host = remoteAddress.getAddress() != null ? remoteAddress.getAddress().getHostAddress() : remoteAddress.getHostName();
int port = remoteAddress.getPort();
Channel channel = super.getChannel(remoteAddress);
if (channel == null) {
for (Map.Entry<URL, Client> entry : clients.entrySet()) {
URL url = entry.getKey();
if (url.getIp().equals(host) && url.getPort() == port) {
return entry.getValue();
}
}
}
return channel;
}
use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.
the class ExchangeCodecTest method testMessageLengthGreaterThanMessageActualLength.
// http://code.alibabatech.com/jira/browse/DUBBO-392
@Test
public void testMessageLengthGreaterThanMessageActualLength() throws Exception {
Channel channel = getCliendSideChannel(url);
Request request = new Request(1L);
request.setVersion("2.0.0");
Date date = new Date();
request.setData(date);
ChannelBuffer encodeBuffer = ChannelBuffers.dynamicBuffer(1024);
codec.encode(channel, encodeBuffer, request);
byte[] bytes = new byte[encodeBuffer.writerIndex()];
encodeBuffer.readBytes(bytes);
int len = Bytes.bytes2int(bytes, 12);
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
out.write(bytes, 0, 12);
/*
* 填充长度不能低于256,hessian每次默认会从流中读取256个byte.
* 参见 Hessian2Input.readBuffer
*/
int padding = 512;
out.write(Bytes.int2bytes(len + padding));
out.write(bytes, 16, bytes.length - 16);
for (int i = 0; i < padding; i++) {
out.write(1);
}
out.write(bytes);
/* request|1111...|request */
ChannelBuffer decodeBuffer = ChannelBuffers.wrappedBuffer(out.toByteArray());
Request decodedRequest = (Request) codec.decode(channel, decodeBuffer);
Assert.assertTrue(date.equals(decodedRequest.getData()));
Assert.assertEquals(bytes.length + padding, decodeBuffer.readerIndex());
decodedRequest = (Request) codec.decode(channel, decodeBuffer);
Assert.assertTrue(date.equals(decodedRequest.getData()));
}
use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.
the class TelnetCodecTest method testEecode_assertEquals.
protected void testEecode_assertEquals(Object request, byte[] ret, boolean isServerside) throws IOException {
//init channel
Channel channel = isServerside ? getServerSideChannel(url) : getCliendSideChannel(url);
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(1024);
codec.encode(channel, buffer, request);
byte[] data = new byte[buffer.readableBytes()];
buffer.readBytes(data);
Assert.assertEquals(ret.length, data.length);
for (int i = 0; i < ret.length; i++) {
if (ret[i] != data[i]) {
Assert.fail();
}
}
}
use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.
the class ExchangeCodecTest method test_Encode_Error_Response.
@Test
public void test_Encode_Error_Response() throws IOException {
ChannelBuffer encodeBuffer = ChannelBuffers.dynamicBuffer(1024);
Channel channel = getCliendSideChannel(url);
Response response = new Response();
response.setHeartbeat(true);
response.setId(1001l);
response.setStatus((byte) 10);
response.setVersion("11");
String badString = "bad";
response.setErrorMessage(badString);
Person person = new Person();
response.setResult(person);
codec.encode(channel, encodeBuffer, response);
byte[] data = new byte[encodeBuffer.writerIndex()];
encodeBuffer.readBytes(data);
//encode resault check need decode
ChannelBuffer decodeBuffer = ChannelBuffers.wrappedBuffer(data);
Response obj = (Response) codec.decode(channel, decodeBuffer);
Assert.assertEquals(response.getId(), obj.getId());
Assert.assertEquals(response.getStatus(), obj.getStatus());
Assert.assertEquals(response.isHeartbeat(), obj.isHeartbeat());
Assert.assertEquals(badString, obj.getErrorMessage());
Assert.assertEquals(null, obj.getResult());
// Assert.assertEquals(response.getVersion(), obj.getVersion());
}
Aggregations