tuscany中remotable接口

运行了一下SOA核心及应用第五章的实现一个web服务中的代码,发现老是跑不通,于是试着跑了下代码中对于web服务测试的代码,如下:

@Test
public void testQueryRemainningWS() throws InterruptedException,
MalformedURLException, ServiceException, RemoteException {
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL("http://localhost:8080/AccountInfo"));
call.setOperationName(new QName("http://accountinfo", "queryRemainning"));
String ret = (String) call.invoke( new Object[] { "C01" } );
assertNotNull(ret);
assertEquals("100.0",ret);
}

原理也很简单,就是按照axis的客户端要求发起web服务调用看看结果。我运行后发现找不到queryRemainning方法,于是debug进去看看。发现tuscany在InterfaceContractMapperImpl.map(Interface, Operation),这个函数里面做了接口与操作的转换。我的目的是wsdl转java,在这里比较的时候步骤比较多,其中有个步骤会比较两个接口是不是都是remotable的,如下:

public boolean isCompatible(Operation source, Operation target, boolean remotable)
{
label0:
{
if(source == target)
return true;
if(source.isDynamic() || target.isDynamic())
return true;
if(!source.getName().equals(target.getName()))
return false;
if(source.getInterface().isRemotable() != target.getInterface().isRemotable())
return false;
DataType sourceOutputType = source.getOutputType();
DataType targetOutputType = target.getOutputType();
if(!isCompatible(targetOutputType, sourceOutputType, remotable))
return false;
boolean checkSourceWrapper = true;
List sourceInputType = (List)source.getInputType().getLogical();
if(source.isInputWrapperStyle() && source.getInputWrapper() != null)
{
sourceInputType = (List)source.getInputWrapper().getUnwrappedInputType().getLogical();
checkSourceWrapper = false;
}
boolean checkTargetWrapper = true;
List targetInputType = (List)target.getInputType().getLogical();
if(target.isInputWrapperStyle() && target.getInputWrapper() != null)
{
targetInputType = (List)target.getInputWrapper().getUnwrappedInputType().getLogical();
checkTargetWrapper = false;
}
if(checkSourceWrapper != checkTargetWrapper)
return true;
if(sourceInputType.size() != targetInputType.size())
return false;
int size = sourceInputType.size();
for(int i = 0; i < size; i++)
if(!isCompatible((DataType)sourceInputType.get(i), (DataType)targetInputType.get(i), remotable))
return false;

Iterator i$ = target.getFaultTypes().iterator();
boolean found;
label1:
do
{
if(!i$.hasNext())
break label0;
DataType targetFaultType = (DataType)i$.next();
found = true;
Iterator i$ = source.getFaultTypes().iterator();
DataType sourceFaultType;
do
{
if(!i$.hasNext())
continue label1;
sourceFaultType = (DataType)i$.next();
found = false;
} while(!isCompatible(targetFaultType, sourceFaultType, remotable));
found = true;
} while(found);
return false;
}
return true;
}

在代码中11行的地方return了,于是查的新的tuscany要求java接口必须声明为remotable才可以发布为外部service。这里tuscany用了值传递,也就是用xml做wsdl和java接口之间的数据传递。
这是关于remotable接口的说明:
Annotation used to indicate a Java interface as remotable. Remotable interfaces use pass-by-value semantics, can be published as entry points and used for external services.
将原有代码的interface加remotable 注解后程序跑通!!!

package samples;

import org.osoa.sca.annotations.Remotable;

@Remotable
public interface AccountInfo {

public String queryRemainning(String accountId);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目录 ................................................................................................................................................................................... 5  1.  通用注解、API、客户程序和实现模型 ................................................................................................................. 7  1.1. 简介 ........................................................................................................................................................................... 7  1.2. 实现的元数据 ........................................................................................................................................................... 7  1.2.1. 服务元数据 ............................................................................................................................................................ 8  1.2.2.@Reference ........................................................................................................................................................... 8  1.2.3. @Property ............................................................................................................................................................. 9  1.2.4. 实现作用域:@Scope、@Init、@Destroy ....................................................................................................... 9  1.3 接口元数据 .............................................................................................................................................................. 10  1.3.1. @Remotable ....................................................................................................................................................... 10  1.3.2. @Conversational ................................................................................................................................................ 11  1.4. 客户 API .................................................................................................................................................................. 11  1.4.1. SCA构件访问服务 .............................................................................................................................................. 11  1.4.2. 非 SCA构件的实现访问服务 ............................................................................................................................ 11  1.5. 错误处理 ................................................................................................................................................................. 12  1.6. 异步与会话编程 ..................................................................................................................................................... 12  1.6.1. @OneWay ........................................................................................................................................................... 12 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值