宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

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

@Test
public void testQueryRemainningWS) throws InterruptedException,
MalformedURLException, ServiceException, RemoteException {
Service service = new Service);
Call call = Call) service.createCall);
call.setTargetEndpointAddressnew URL”http://localhost:8080/AccountInfo”));
call.setOperationNamenew QName”http://accountinfo”, “queryRemainning”));
String ret = String) call.invoke new Object[] { “C01” } );
assertNotNullret);
assertEquals”100.0″,ret);
}
原理也很简单,就是按照axis的客户端要求发起web服务调用看看结果。我运行后发现找不到queryRemainning方法,于是debug进去看看。发现tuscany在InterfaceContractMapperImpl.mapInterface, Operation),这个函数里面做了接口与操作的转换。我的目的是wsdl转java,在这里比较的时候步骤比较多,其中有个步骤会比较两个接口是不是都是remotable的,如下:

public boolean isCompatibleOperation source, Operation target, boolean remotable)
{
label0:
{
ifsource == target)
return true;
ifsource.isDynamic) || target.isDynamic))
return true;
if!source.getName).equalstarget.getName)))
return false;
ifsource.getInterface).isRemotable) != target.getInterface).isRemotable))
return false;
DataType sourceOutputType = source.getOutputType);
DataType targetOutputType = target.getOutputType);
if!isCompatibletargetOutputType, sourceOutputType, remotable))
return false;
boolean checkSourceWrapper = true;
List sourceInputType = List)source.getInputType).getLogical);
ifsource.isInputWrapperStyle) && source.getInputWrapper) != null)
{
sourceInputType = List)source.getInputWrapper).getUnwrappedInputType).getLogical);
checkSourceWrapper = false;
}
boolean checkTargetWrapper = true;
List targetInputType = List)target.getInputType).getLogical);
iftarget.isInputWrapperStyle) && target.getInputWrapper) != null)
{
targetInputType = List)target.getInputWrapper).getUnwrappedInputType).getLogical);
checkTargetWrapper = false;
}
ifcheckSourceWrapper != checkTargetWrapper)
return true;
ifsourceInputType.size) != targetInputType.size))
return false;
int size = sourceInputType.size);
forint i = 0; i < size; i++)
if!isCompatibleDataType)sourceInputType.geti), DataType)targetInputType.geti), 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!isCompatibletargetFaultType, sourceFaultType, remotable));
found = true;
} whilefound);
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 queryRemainningString accountId);
}