|
|
|
Here is a fix for BLZ-248 : it checks the return type expected by the developper and it transforms the return double in an int if needed.
When I try to code, I got a ClassCast exception related to object array as result of amfconnection.call that was other than Object[].
here's the correction I made in the AMFClientProxy.java file public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { AMFConnection connection = new AMFConnection(); if (username != null) { String userpasswd = username + ":" + password; String encoding = new String(new Base64().encode(userpasswd.getBytes())); connection.addHttpRequestHeader("Authorization", "Basic " + encoding); } connection.connect(url); Object[] params = args; if (null == params) { params = new Object[0]; } Object callResult = connection.call(serviceName + "." + method.getName(), params); connection.close(); // Creates a new array with the valid type from the call result if (method.getReturnType().isArray()) { Object[] arrayOfValidType = (Object[]) Array.newInstance(method.getReturnType().getComponentType(), ((Object[]) callResult).length); System.arraycopy(callResult, 0, arrayOfValidType, 0, ((Object[]) callResult).length); callResult = arrayOfValidType; } return callResult; } | |||||||||||||||||||||||||||||||||||||||||||
Spring configuration for AMF remote invokation :
<bean id="contractServiceFactory" class="AMFClientFactory">
<property name="serviceClass" value="xxxxx.xxxx.contract.api.ContractService" />
<property name="url" value="http://localhost:8081/xxxxx/messagebroker/amf" />
<property name="username" value="admin" />
<property name="password" value="admin" />
<property name="serviceName" value="contractService" />
</bean>
<bean id="contractService" class="xxxxx.xxxx.contract.api.ContractService" factory-bean="contractServiceFactory" factory-method="create"/>
Spring configuration local invokation :
<bean id="contractService" class="xxxxx.xxxx.contract.impl.ContractServiceImpl" />
Java code :
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-client.xml");
ContractService service = (ContractService) context.getBean("contractService");
List<Contract> contracts = service.findContractType();
As you can see, the java code doesn't change at all when you switch from local invokation to amf remote invokation.