use of com.weibo.api.motan.rpc.Request in project motan by weibocom.
the class FailoverHaStrategyTest method setUp.
@Before
@Override
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
super.setUp();
loadBalance = mockery.mock(LoadBalance.class);
final Referer<IWorld> referer1 = mockery.mock(Referer.class, "ref1");
final Referer<IWorld> referer2 = mockery.mock(Referer.class, "ref2");
referers = new ArrayList<Referer<IWorld>>();
referers.add(referer1);
referers.add(referer2);
failoverHaStrategy = new FailoverHaStrategy<IWorld>() {
@Override
protected List<Referer<IWorld>> selectReferers(Request request, LoadBalance<IWorld> loadBalance) {
return referers;
}
};
URL url = new URL(MotanConstants.PROTOCOL_MOTAN, NetUtils.LOCALHOST, 0, IWorld.class.getName());
url.addParameter(URLParamType.retries.getName(), String.valueOf(retries));
failoverHaStrategy.setUrl(url);
}
use of com.weibo.api.motan.rpc.Request in project incubator-skywalking by apache.
the class MotanProviderInterceptor method beforeMethod.
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
Request request = (Request) allArguments[0];
ContextCarrier contextCarrier = new ContextCarrier();
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
next.setHeadValue(request.getAttachments().get(next.getHeadKey()));
}
AbstractSpan span = ContextManager.createEntrySpan(generateViewPoint(request), contextCarrier);
SpanLayer.asRPCFramework(span);
span.setComponent(ComponentsDefine.MOTAN);
}
use of com.weibo.api.motan.rpc.Request in project incubator-skywalking by apache.
the class MotanConsumerInterceptor method beforeMethod.
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
URL url = (URL) objInst.getSkyWalkingDynamicField();
Request request = (Request) allArguments[0];
if (url != null) {
ContextCarrier contextCarrier = new ContextCarrier();
String remotePeer = url.getHost() + ":" + url.getPort();
AbstractSpan span = ContextManager.createExitSpan(generateOperationName(url, request), contextCarrier, remotePeer);
span.setComponent(ComponentsDefine.MOTAN);
Tags.URL.set(span, url.getIdentity());
SpanLayer.asRPCFramework(span);
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
request.setAttachment(next.getHeadKey(), next.getHeadValue());
}
}
}
use of com.weibo.api.motan.rpc.Request in project motan by weibocom.
the class NettyEncoder method encode.
@Override
protected Object encode(ChannelHandlerContext ctx, Channel nettyChannel, Object message) throws Exception {
byte[] data = encodeMessage(message);
ChannelBuffer channelBuffer;
short type = ByteUtil.bytes2short(data, 0);
if (type == DefaultRpcCodec.MAGIC) {
channelBuffer = encodeV1(message, data);
} else if (type == MotanV2Header.MAGIC) {
channelBuffer = encodeV2(data);
} else {
throw new MotanFrameworkException("can not encode message, unknown magic:" + type);
}
if (message instanceof Response) {
((Response) message).setAttachment(MotanConstants.CONTENT_LENGTH, String.valueOf(channelBuffer.readableBytes()));
}
if (message instanceof Request) {
MotanFrameworkUtil.logEvent((Request) message, MotanConstants.TRACE_CENCODE);
} else if (message instanceof Response) {
MotanFrameworkUtil.logEvent((Response) message, MotanConstants.TRACE_SENCODE);
}
return channelBuffer;
}
use of com.weibo.api.motan.rpc.Request in project motan by weibocom.
the class UnSerializableClass method testNettyRequestDecodeException.
/**
* @throws Exception
*/
@Test
public void testNettyRequestDecodeException() throws Exception {
NettyServer nettyServer;
nettyServer = new NettyServer(url, new MessageHandler() {
@Override
public Object handle(Channel channel, Object message) {
Request request = (Request) message;
DefaultResponse response = new DefaultResponse();
response.setRequestId(request.getRequestId());
response.setValue("success");
return response;
}
});
nettyServer.open();
NettyClient nettyClient = new NettyClient(url);
nettyClient.open();
DefaultRequest request = new DefaultRequest();
request.setRequestId(RequestIdGenerator.getRequestId());
request.setInterfaceName(url.getPath());
request.setMethodName("hello");
request.setParamtersDesc("void");
try {
nettyClient.request(request);
Assert.assertTrue(false);
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("framework decode error"));
} finally {
nettyClient.close();
nettyServer.close();
}
}
Aggregations