Closed wsky closed 11 years ago
spring server config:
<beans>
<bean name="testService" class="TestService" />
<bean name="handshaker" class="com.taobao.top.link.remoting.CustomHandshaker" />
<bean name="callContext" class="com.taobao.top.link.remoting.MethodCallContextBean" />
<bean name="server" class="com.taobao.top.link.remoting.SpringServerBean">
<property name="port" value="8889" />
<property name="path" value="api" />
<property name="maxMessageSize" value="1024" />
<property name="maxBusinessThreadCount" value="200" />
<property name="handshaker">
<ref bean="handshaker" />
</property>
</bean>
<bean class="com.taobao.top.link.remoting.ServiceBean">
<property name="interfaceName" value="TestInterface" />
<property name="target">
<ref bean="testService" />
</property>
</bean>
</beans>
handshaker:
public class CustomHandshaker implements HandshakerBean {
@Override
public void onHandshake(List<Entry<String, String>> headers, ChannelContextBean context) throws Exception {
for (Entry<String, String> entry : headers) {
// custom your context for this connection
context.set(entry.getKey(), entry.getValue());
// validate something
if (entry.getKey().equalsIgnoreCase("id"))
return;
}
throw new LinkException("miss id");
}
}
get callcontext at server
MethodCallContextBean callContext = (MethodCallContextBean) beanFactory.getBean("callContext");
callContext.get("appkey");
spring client config:
<beans>
<bean name="headers" class="com.taobao.top.link.remoting.HandshakingHeadersBean">
<property name="headers">
<map>
<entry key="appkey"><value>test</value></entry>
</map>
</property>
</bean>
<bean name="test" class="com.taobao.top.link.remoting.SpringServiceProxyBean">
<property name="interfaceName" value="TestInterface" />
<property name="uri" value="ws://localhost:8889/" />
<property name="executionTimeout" value="5000" />
<property name="serialization" value="json" />
<property name="headers">
<ref bean="headers" />
</property>
</bean>
</beans>
context should be shared between remoting sinks or call-lifecycle