提交 5763254f 编写于 作者: K kimi

DUBBO-135

git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@1989 1a56cb94-b969-4eaa-88fa-be21384802f2
上级 fcf76141
...@@ -98,10 +98,10 @@ public class ThriftCodec implements Codec { ...@@ -98,10 +98,10 @@ public class ThriftCodec implements Codec {
throws IOException { throws IOException {
if ( message instanceof Request ) { if ( message instanceof Request ) {
encodeRequest( output, ( Request ) message ); encodeRequest( channel, output, ( Request ) message );
} }
else if ( message instanceof Response ) { else if ( message instanceof Response ) {
encodeResponse( output, ( Response ) message ); encodeResponse( channel, output, ( Response ) message );
} else { } else {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
new StringBuilder( 32 ) new StringBuilder( 32 )
...@@ -184,7 +184,7 @@ public class ThriftCodec implements Codec { ...@@ -184,7 +184,7 @@ public class ThriftCodec implements Codec {
result.setMethodName( message.name ); result.setMethodName( message.name );
String argsClassName = ExtensionLoader.getExtensionLoader(ClassNameGenerator.class) String argsClassName = ExtensionLoader.getExtensionLoader(ClassNameGenerator.class)
.getDefaultExtension().generateArgsClassName( serviceName, message.name ); .getExtension(ThriftClassNameGenerator.NAME).generateArgsClassName( serviceName, message.name );
if ( StringUtils.isEmpty( argsClassName ) ) { if ( StringUtils.isEmpty( argsClassName ) ) {
throw new RpcException( RpcException.SERIALIZATION_EXCEPTION, throw new RpcException( RpcException.SERIALIZATION_EXCEPTION,
...@@ -295,7 +295,7 @@ public class ThriftCodec implements Codec { ...@@ -295,7 +295,7 @@ public class ThriftCodec implements Codec {
} else if ( message.type == TMessageType.REPLY ) { } else if ( message.type == TMessageType.REPLY ) {
String resultClassName = ExtensionLoader.getExtensionLoader( ClassNameGenerator.class ) String resultClassName = ExtensionLoader.getExtensionLoader( ClassNameGenerator.class )
.getDefaultExtension().generateResultClassName( serviceName, message.name ); .getExtension(ThriftClassNameGenerator.NAME).generateResultClassName( serviceName, message.name );
if ( StringUtils.isEmpty( resultClassName ) ) { if ( StringUtils.isEmpty( resultClassName ) ) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
...@@ -390,7 +390,7 @@ public class ThriftCodec implements Codec { ...@@ -390,7 +390,7 @@ public class ThriftCodec implements Codec {
} }
private void encodeRequest( OutputStream output, Request request ) private void encodeRequest( Channel channel, OutputStream output, Request request )
throws IOException { throws IOException {
RpcInvocation inv = ( RpcInvocation ) request.getData(); RpcInvocation inv = ( RpcInvocation ) request.getData();
...@@ -413,7 +413,8 @@ public class ThriftCodec implements Codec { ...@@ -413,7 +413,8 @@ public class ThriftCodec implements Codec {
seqId ); seqId );
String methodArgs = ExtensionLoader.getExtensionLoader( ClassNameGenerator.class ) String methodArgs = ExtensionLoader.getExtensionLoader( ClassNameGenerator.class )
.getDefaultExtension().generateArgsClassName( serviceName, inv.getMethodName() ); .getExtension(channel.getUrl().getParameter(ThriftConstants.CLASS_NAME_GENERATOR_KEY, ThriftClassNameGenerator.NAME))
.generateArgsClassName(serviceName, inv.getMethodName());
if ( StringUtils.isEmpty( methodArgs ) ) { if ( StringUtils.isEmpty( methodArgs ) ) {
throw new RpcException( RpcException.SERIALIZATION_EXCEPTION, throw new RpcException( RpcException.SERIALIZATION_EXCEPTION,
...@@ -529,15 +530,16 @@ public class ThriftCodec implements Codec { ...@@ -529,15 +530,16 @@ public class ThriftCodec implements Codec {
} }
private void encodeResponse( OutputStream output, Response response ) private void encodeResponse( Channel channel, OutputStream output, Response response )
throws IOException { throws IOException {
RpcResult result = ( RpcResult ) response.getResult(); RpcResult result = ( RpcResult ) response.getResult();
RequestData rd = cachedRequest.get( response.getId() ); RequestData rd = cachedRequest.get( response.getId() );
String resultClassName = ExtensionLoader.getExtensionLoader( ClassNameGenerator.class ) String resultClassName = ExtensionLoader.getExtensionLoader( ClassNameGenerator.class ).getExtension(
.getDefaultExtension().generateResultClassName( rd.serviceName, rd.methodName ); channel.getUrl().getParameter(ThriftConstants.CLASS_NAME_GENERATOR_KEY, ThriftClassNameGenerator.NAME))
.generateResultClassName(rd.serviceName, rd.methodName);
if ( StringUtils.isEmpty( resultClassName ) ) { if ( StringUtils.isEmpty( resultClassName ) ) {
throw new RpcException( RpcException.SERIALIZATION_EXCEPTION, throw new RpcException( RpcException.SERIALIZATION_EXCEPTION,
......
...@@ -7,6 +7,7 @@ public final class ThriftConstants { ...@@ -7,6 +7,7 @@ public final class ThriftConstants {
public static final String THRIFT_PROTOCOL_KEY = "thrift.protocol"; public static final String THRIFT_PROTOCOL_KEY = "thrift.protocol";
public static final String BINARY_THRIFT_PROTOCOL = "binary"; public static final String BINARY_THRIFT_PROTOCOL = "binary";
public static final String CLASS_NAME_GENERATOR_KEY = "class.name.generator";
public static final String DEFAULT_PROTOCOL = BINARY_THRIFT_PROTOCOL; public static final String DEFAULT_PROTOCOL = BINARY_THRIFT_PROTOCOL;
private ThriftConstants() {} private ThriftConstants() {}
......
package com.alibaba.dubbo.rpc.protocol.thrift.examples; package com.alibaba.dubbo.rpc.protocol.thrift.examples;
import com.alibaba.dubbo.rpc.gen.dubbo.Demo;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.dubbo.rpc.gen.thrift.Demo;
/** /**
* @author <a href="mailto:gang.lvg@alibaba-inc.com">kimi</a> * @author <a href="mailto:gang.lvg@alibaba-inc.com">kimi</a>
*/ */
...@@ -12,7 +13,7 @@ public class DubboDemoConsumer { ...@@ -12,7 +13,7 @@ public class DubboDemoConsumer {
ClassPathXmlApplicationContext context = ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("dubbo-demo-consumer.xml"); new ClassPathXmlApplicationContext("dubbo-demo-consumer.xml");
context.start(); context.start();
Demo demo = (Demo) context.getBean("demoService"); Demo.Iface demo = (Demo.Iface) context.getBean("demoService");
System.out.println(demo.echoI32(32)); System.out.println(demo.echoI32(32));
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
System.out.println(demo.echoI32(i + 1)); System.out.println(demo.echoI32(i + 1));
......
...@@ -12,6 +12,6 @@ ...@@ -12,6 +12,6 @@
<dubbo:protocol name="thrift" /> <dubbo:protocol name="thrift" />
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.rpc.gen.dubbo.Demo" timeout="1000000" /> <dubbo:reference id="demoService" interface="com.alibaba.dubbo.rpc.gen.thrift.Demo$Iface" timeout="1000000" />
</beans> </beans>
\ No newline at end of file
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
<dubbo:protocol id="thrift" name="thrift" /> <dubbo:protocol id="thrift" name="thrift" />
<bean id="demoService" class="com.alibaba.dubbo.rpc.protocol.thrift.DubboDemoImpl"/> <bean id="demoService" class="com.alibaba.dubbo.rpc.protocol.thrift.ThriftDemoImpl"/>
<dubbo:service protocol="thrift" interface="com.alibaba.dubbo.rpc.gen.dubbo.Demo" ref="demoService"/> <dubbo:service protocol="thrift" interface="com.alibaba.dubbo.rpc.gen.thrift.Demo$Iface" ref="demoService"/>
</beans> </beans>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册