4 Replies Latest reply on Mar 4, 2005 4:04 PM by Marcelo Pitanga

    Deploy a EJB as Web Service

    Marcelo Pitanga Newbie

      Hi,

      All examples that i´ve found use another class ( extends java.rmi.Remote) and not directly of a EJB Remote.

      Is possible deploy a EJB directly as Web Services?

      Thanks in advanced

        • 2. Re: Deploy a EJB as Web Service
          Marcelo Pitanga Newbie

          Hi Thomas,

          My problem.

          Example:

          My EJB...
          Remote interface...

          import ....
          public interface APIMensagem extends EJBObject
          {
          ...
          public void enviarMensagem( String id, logType objmsg ) throws JMSException, NamingException, RemoteException;
          }
          


          Home interface

          import ....
          public interface APIMensagemHome extends EJBHome
          {
           APIMensagem create () throws RemoteException, CreateException;
          }
          


          Bean
          import ....
          public class APIMensagemBean implements SessionBean
          {
          .....
           public void enviarMensagem( String id, logType objmsg ) {
           try {
           msgObj.enviarMensagem(id, objmsg);
           } catch (Exception e){
           System.out.println("Erro : "+e);
           }
           }
          ....
          }
          


          when i use the wscompile for generate the WSDL and RPC-Mapping it fail.

          APIMensagemServiceConfig.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
           <service name="APIMensagemService"
           targetNamespace="http://middlog.com.br/wsdl"
           typeNamespace="http://middlog.com.br/types"
           packageName="middlog.API">
           <interface name="middlog.API.APIMensagem"/>
           </service>
          </configuration>
          


          wscompile command and message error:

          C:\implementacao>wscompile -cp C:/implementacao/middlog/build -gen:server -f:rpc
          literal -d C:/implementacao/middlog/resources -mapping C:/implementacao/middlog/resources/APIMensagem_mapping.xml C:/implementacao/middlog/APIMensagemServiceConfig.xml
          
          java.lang.reflect.InvocationTargetException
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
          java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
          sorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:585)
           at org.apache.commons.launcher.ChildMain.run(ChildMain.java:269)
          Caused by: java.lang.NoClassDefFoundError: javax/ejb/EJBObject
           at java.lang.ClassLoader.defineClass1(Native Method)
           at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
           at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
          4)
           at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
           at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
           at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
           at java.security.AccessController.doPrivileged(Native Method)
           at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
           at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
           at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
           at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
           at java.lang.Class.forName0(Native Method)
           at java.lang.Class.forName(Class.java:242)
           at com.sun.xml.rpc.processor.modeler.rmi.RmiUtils.getLoadableClassName(R
          miUtils.java:78)
           at com.sun.xml.rpc.processor.modeler.rmi.RmiUtils.getRealName(RmiUtils.j
          ava:54)
           at com.sun.xml.rpc.processor.modeler.rmi.RmiModeler.modelPort(RmiModeler
          .java:676)
           at com.sun.xml.rpc.processor.modeler.rmi.RmiModeler.buildLiteralModel(Rm
          iModeler.java:603)
           at com.sun.xml.rpc.processor.modeler.rmi.RmiModeler.buildModel(RmiModele
          r.java:457)
           at com.sun.xml.rpc.processor.config.ModelInfo.buildModel(ModelInfo.java:
          88)
           at com.sun.xml.rpc.processor.Processor.runModeler(Processor.java:63)
           at com.sun.xml.rpc.tools.wscompile.CompileTool.run(CompileTool.java:714)
          
           at com.sun.xml.rpc.util.ToolBase.run(ToolBase.java:43)
           at com.sun.xml.rpc.tools.wscompile.Main.main(Main.java:22)
           ... 5 more
          C:\implementacao>


          Following the Wiki:

          package ...

          import ...
          
          public interface APIMensagemEndpoint extends Remote
          {
          ...
          public void enviarMensagem( String id, logType objmsg ) throws RemoteException;
          }
          


          APIMensagemServiceConfig.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
           <service name="APIMensagemService"
           targetNamespace="http://middlog.com.br/wsdl"
           typeNamespace="http://middlog.com.br/types"
           packageName="middlog.API">
           <interface name="middlog.API.APIMensagemEndpoint"/>
           </service>
          </configuration>
          


          wscompile..
          C:\implementacao>wscompile -cp C:/implementacao/middlog/build -gen:server -f:rpc
          literal -d C:/implementacao/middlog/resources -mapping C:/implementacao/middlog
          /resources/APIMensagem_mapping.xml C:/implementacao/middlog/APIMensagemServiceC
          onfig.xml
          C:\implementacao>


          After create this new class extends from java.rmi.Remote the wscompile generate the wsdl and rpcmapping correctly.

          Question 1) if i´ve implemented a remote interface for my EJB session bean why i have that to create another class for generate my web services?

          Question 2) After generate this wsdl, the wscompile generate others class. These class will must package joint with my EJB?


          O volume na unidade C ? Disco local
          O n£mero de s?rie do volume ? 2C16-CF4F

          Pasta de C:\implementacao\middlog\resources\middlog\API

          04/03/2005 16:08 .
          04/03/2005 16:08 ..
          04/03/2005 16:02 274 APIMensagemEndpoint_abrefila_RequestStruct.class
          04/03/2005 16:02 1.533 APIMensagemEndpoint_abrefila_RequestStruct_LiteralSerializer.class
          04/03/2005 16:02 276 APIMensagemEndpoint_abrefila_ResponseStruct.class
          04/03/2005 16:02 1.536 APIMensagemEndpoint_abrefila_ResponseStruct_LiteralSerializer.class
          04/03/2005 16:02 854 APIMensagemEndpoint_enviarMensagem2_RequestStruct.class
          04/03/2005 16:02 4.070 APIMensagemEndpoint_enviarMensagem2_RequestStruct_LiteralSerializer.class
          04/03/2005 16:02 757 APIMensagemEndpoint_enviarMensagem_RequestStruct.class
          04/03/2005 16:02 3.792 APIMensagemEndpoint_enviarMensagem_RequestStruct_LiteralSerializer.class
          04/03/2005 16:02 288 APIMensagemEndpoint_enviarMensagem_ResponseStruct.class
          04/03/2005 16:02 290 APIMensagemEndpoint_enviarMensagem_ResponseStruct1.class
          04/03/2005 16:02 1.557 APIMensagemEndpoint_enviarMensagem_ResponseStruct1_LiteralSerializer.class
          04/03/2005 16:02 1.554 APIMensagemEndpoint_enviarMensagem_ResponseStruct_LiteralSerializer.class
          04/03/2005 16:02 278 APIMensagemEndpoint_fecharfila_RequestStruct.class
          04/03/2005 16:02 1.539 APIMensagemEndpoint_fecharfila_RequestStruct_LiteralSerializer.class
          04/03/2005 16:02 280 APIMensagemEndpoint_fecharfila_ResponseStruct.class
          04/03/2005 16:02 1.542 APIMensagemEndpoint_fecharfila_ResponseStruct_LiteralSerializer.class
          04/03/2005 16:02 11.059 APIMensagemEndpoint_Tie.class
          04/03/2005 16:02 3.576 APIMensagemService_SerializerRegistry.class
          04/03/2005 16:08 0 list.txt
          19 arquivo(s) 35.055 bytes
          2 pasta(s) 63.495.778.304 bytes dispon¡veis

          O volume na unidade C ? Disco local
          O n£mero de s?rie do volume ? 2C16-CF4F

          Pasta de C:\implementacao\middlog\resources\middlog\modelo

          04/03/2005 16:10 .
          04/03/2005 16:10 ..
          04/03/2005 16:10 0 list.txt
          04/03/2005 16:02 2.642 logType_LiteralSerializer.class
          2 arquivo(s) 2.642 bytes
          2 pasta(s) 63.495.774.208 bytes dispon¡veis



          • 3. Re: Deploy a EJB as Web Service
            Thomas Diesler Master

            1) The methods exposed through a EJB remote interface are not necessarily the same as for the WS endpoint

            2) No, they are jwsdp specific

            • 4. Re: Deploy a EJB as Web Service
              Marcelo Pitanga Newbie

              Hi Thomas,

              Thank's for help.