Friday, April 15, 2005

Publishing an EJB as WS


To expose an EJB as an endpoint, there are two ways - if the container supports EJB2.1 spec, a stateless session bean can be exposed as a web service or use Axis Platform to publish an EJB as a WS. I preferred the latter for some project reasons. I'm using WLS8.1 SP2.
The process doesn't require more than 3-4 lines in the deploy.wsdd file.
The following is a copy paste from the deploy.wsdd:





<parameter name="beanJndiName" value="HelloBean"/>
<parameter name="homeInterfaceName" value="demo.HelloHome"/>
<parameter name="remoteInterfaceName" value="demo.Hello"/>
<parameter name="allowedMethods" value="*"/>
<parameter name="jndiURL" value="t3://localhost:7001"/>
<parameter name="jndiContextClass" value="weblogic.jndi.WLInitialContextFactory"/>


And Bingo! I executed published and consumed the WS at the first go without any errors. whew! what a relief.
The next step was to send and receive arrays of VOs from the WS. This requried some fiddling of the wsdd file again. This line did the magic:



<beanMapping qname="myNS:VO" xmlns:myNS="urn:ravi" languageSpecificType="java:ravi.MyVO"/>



and the extra lines in the client program>



call.registerTypeMapping(MyVO.class, qn,
new org.apache.axis.encoding.ser.BeanSerializerFactory(MyVO.class, qn),
new org.apache.axis.encoding.ser.BeanDeserializerFactory(MyVO.class, qn));
call.setReturnType( qn );




This solved 80% of my problem. The next step was to return an array of VOs. This required just one change in the above code
call.setReturnType(XMLType.SOAP_ARRAY);
I'm delighted on publishing and consuming the WS. I'm still excited, thought I would write a Eclipse plugin that uses axis and generates stubs for static invocation.. Hmm not a bad idea....

No comments: