Hi,
I am having problems invoking web services which have a return type.
I am trying to do all this "by hand".
Here is the code.
==
/* Service Interface */
public interface ISimpleWebService {
public String serviceMethodUno();
}
==
/* Service Implementation */
public class SimpleWebService implements ISimpleWebService {
public String serviceMethodUno() {
System.out.println("serviceMethodUno");
return "serviceMethodUnoResponse";
}
}
==
/* The code which trys to do it all */
public class XfireEmbedder {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// Load up the core of XFire
XFire xfireCore = XFireFactory.newInstance().getXFire();
// Create JMS Connection factory and associate the XFire core
with
// that JMS Connection factory to create a JMS Transport
ConnectionFactory jmsConnectionFactory = new
ActiveMQConnectionFactory(
"tcp://localhost:61616");
JMSTransport jmsTransport = new JMSTransport(xfireCore,
jmsConnectionFactory);
// Register the JMS Transport into the Transport Manager
associated
// with the XFire core
TransportManager xfireTransportManager = xfireCore
.getTransportManager();
xfireTransportManager.register(jmsTransport);
// Instantiate a Service factory to serve POJOs over the
Transports
// registered into the XFire core
ServiceFactory xfireServiceFactory = new ObjectServiceFactory(
xfireTransportManager);
// This is extraneous
((ObjectServiceFactory) xfireServiceFactory)
.addSoap12Transport(JMSTransport.BINDING_ID);
// Now create the Web Service and associate an implementation
with
// that web service
Service simpleWebService = xfireServiceFactory.create(
ISimpleWebService.class, "SimpleWebService",
null, null);
simpleWebService.setProperty(ObjectInvoker.SERVICE_IMPL_CLASS,
SimpleWebService.class);
// Register the web service into the XFire core
xfireCore.getServiceRegistry().register(simpleWebService);
// Simulate the Web Service client using XFire client API
Object serviceProxy = new
XFireProxyFactory().create(simpleWebService,
"jms://SimpleWebService");
ISimpleWebService webServiceClient = (ISimpleWebService)
serviceProxy;
// Since JMS doesn't really have a concept of anonymous
endpoints, we
// need to let xfire know what JMS endpoint we should use
((XFireProxy)
Proxy.getInvocationHandler(webServiceClient)).getClient()
.setEndpointUri("jms://Peer1");
// Start up an actual JMS broker
BrokerService jmsBroker = new BrokerService();
jmsBroker.setPersistent(false);
jmsBroker.addConnector("tcp://localhost:61616");
jmsBroker.start();
Connection jmsConnection =
jmsConnectionFactory.createConnection();
jmsConnection.start();
// This channel has to be created explicitly
Channel channel =
jmsTransport.createChannel("jms://SimpleWebService");
String serviceResult = webServiceClient.serviceMethodUno();
System.out.println("================== >> " + serviceResult);
jmsConnection.stop();
jmsConnection.close();
jmsBroker.stop();
}
}
And the output that I get is ...
==
2007-01-27 23:16:46,125 [MQ Session Task] DEBUG HandlerPipeline
- Invoking handler
org.codehaus.xfire.client.ClientReceiveHandler in phase service
Exception in thread "main" org.codehaus.xfire.XFireRuntimeException:
Could not invoke service.. Nested exception is
org.codehaus.xfire.fault.XFireFault: Index: 0, Size: 0
org.codehaus.xfire.fault.XFireFault: Index: 0, Size: 0
at org.codehaus.xfire.fault.XFireFault.createFault(XFireFault.java:89)
at org.codehaus.xfire.client.Client.onReceive(Client.java:386)
at
org.codehaus.xfire.transport.AbstractChannel.receive(AbstractChannel.java:38)
at
org.codehaus.xfire.transport.jms.JMSChannel.onMessage(JMSChannel.java:300)
at
org.apache.activemq.ActiveMQMessageConsumer.dispatch(ActiveMQMessageConsumer.java:840)
at
org.apache.activemq.ActiveMQSessionExecutor.dispatch(ActiveMQSessionExecutor.java:96)
at
org.apache.activemq.ActiveMQSessionExecutor.iterate(ActiveMQSessionExecutor.java:165)
at
org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:111)
at
org.apache.activemq.thread.PooledTaskRunner.access$100(PooledTaskRunner.java:26)
at
org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:44)
at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.LinkedList.entry(Unknown Source)
at java.util.LinkedList.get(Unknown Source)
at java.util.Collections$UnmodifiableList.get(Unknown Source)
at
org.codehaus.xfire.service.binding.AbstractBinding.read(AbstractBinding.java:191)
at
org.codehaus.xfire.service.binding.WrappedBinding.readMessage(WrappedBinding.java:50)
at
org.codehaus.xfire.soap.handler.SoapBodyHandler.invoke(SoapBodyHandler.java:42)
at
org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Client.onReceive(Client.java:382)
... 11 more
==
I have tried to step through the code in the debugger and I observed that:
- AbstractBinding.java : 179, The code trys to determine whether the passed
in MessageContext has the property "Client.CLIENT_MODE" set to true or
not. If true, then it looks for an outputMessage otherwise the inputMessage.
- The MessageContext instantiated in JMSChannel.java:274 is never assigned
a property "Client.CLIENT_MODE".
- As a result, in AbstractBinding.java, the code is everytime looking at the
inputMessage which during the SOAP response will contain nothing resulting
in the mentioned Index out of bounds exception.
However I am not facing this problem when I declare the web service to have
no return type.
How can this problem be fixed ?
Cheers,
--
Gagan
--
Gagan
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email