运行了一下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);
}
分享到:
相关推荐
使用tuscany配置和发布简单的webservcie接口例子
Tuscany架构 Tuscany架构.jpg Tuscany架构.jpg
soa apache-TUSCANY 源码 SCA目前实现的框架
tuscany的一点文档,其实主要比较有用的是其中讲策略的。
Apache Tuscany SCA 的入门资料,属于Step by step类型的.
Tuscany SCA in Action
apache-tuscany tuscany
Tuscany-SDO-学习笔记
tuscany wsdl2java tools
5个代码例子使用的是 Tuscany1.5版本。请在官网下载jar包。 下载地址:http://archive.apache.org/dist/tuscany/java/sca/1.5/apache-tuscany-sca-1.5.zip 5个例子从不同的角度讲解了tuscany的整体架构思想。文档...
Tuscany SCA与Spring、Hibernate整合实例-简洁方法。为了控制大小,把项目lib中的jar都删了...
tuscany1.6.2源代码,由于apache上的服务器经常下载不了,上传一份做备份
sdo为各种数据提供了一个通用的操作接口。
最流行的SAO开源产品的最新版,分5个部分压缩;其它部分不要分。
apache-tuscany-sca-1.6.zip
自制CHM版的API文档,带索引。 注:如果各位下载后打开或无法显示页面,请在CHM文件右键—属性—解除锁定即可。
Tuscany In Action.pdf