0 Replies Latest reply on May 30, 2005 7:56 AM by Alexander Meisinger

    EJB 2.1 Service Endpiont: Custom Types

    Alexander Meisinger Newbie

      Hi,

      I am using JBoss 4.0.2, Eclipse 3.0.2 with JBossIDE 1.4.1e30 and xDoclet 1.2.3. I wrote a ejb 2.1 service endpoint with standard data types - it works fine. Now I want to add a custom object (Person). Which steps must be done?

      My file-structure is as follows:

      /Tutorial
       /src
       /tutorial.ejb (package)
       HelloBean.java
       /tutorial.interfaces (package)
       TutorialHelloEndpoint.java
       /META-INF
       /wsdl
       service.wsdl
       ejb-jar.xml
       jboss.xml
       mapping.xml
       webservices.xml
       /JRE System Library [J2SDK 1.4.2_05]
       ...
       /J2EE 1.4 Libraries (JBoss-IDE)
       ...
       /Web Services 1.0 Libraries (JBoss-IDE)
       ...
       /build
       tutorial.jar
       /resources
       template.wsdl
       wsdl-build.xdt
       generate-wsdl-script.xml
       packaging-build.wsdl
       wsdl-build.xml
       xdoclet.properties
       xdoclet-build.xml
      


      I'll give you an overview of my code:

      HelloBean.java
      /*
       * Created on 25.05.2005
       *
       * TODO To change the template for this generated file go to
       * Window - Preferences - Java - Code Style - Code Templates
       */
      package tutorial.ejb;
      
      import java.rmi.RemoteException;
      
      import javax.ejb.CreateException;
      import javax.ejb.EJBException;
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;
      
      /**
       * @ejb.bean name="Hello"
       * display-name="Name for Hello"
       * description="Description for Hello"
       * jndi-name="ejb/Hello"
       * type="Stateless"
       * view-type="service-endpoint"
       *
       * @ejb.interface
       * service-endpoint-class="tutorial.interfaces.TutorialHelloEndpoint"
       *
       * @wsee.port-component
       * name="TutorialHelloEndpointPort"
       */
      public class HelloBean implements SessionBean {
      
       public HelloBean() {}
       public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException {}
       public void ejbRemove() throws EJBException, RemoteException {}
       public void ejbActivate() throws EJBException, RemoteException {}
       public void ejbPassivate() throws EJBException, RemoteException {}
       public void ejbCreate() throws CreateException {}
      
       /**
       * Business method
       * @ejb.interface-method view-type = "service-endpoint"
       */
       public String sayHello(String name) {
       return "Hello " + name + "!";
       }
      }
      

      TutorialHelloEndpoint
      /*
       * Generated by XDoclet - Do not edit!
       */
      package tutorial.interfaces;
      
      /**
       * Service endpoint interface for Hello.
       */
      public interface TutorialHelloEndpoint
       extends java.rmi.Remote
      {
       /**
       * Business method
       */
       public java.lang.String sayHello( java.lang.String name )
       throws java.rmi.RemoteException;
      }
      

      mapping.xml
      <?xml version="1.0" encoding="UTF-8"?>
      
      <java-wsdl-mapping
       xmlns="http://java.sun.com/xml/ns/j2ee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
       http://java.sun.com/xml/ns/j2ee/j2ee_jaxrpc_mapping_1_1.xsd"
       version="1.1">
      
       <package-mapping>
       <package-type>tutorial.ejb</package-type>
       <namespaceURI>http://Hello</namespaceURI>
       </package-mapping>
      </java-wsdl-mapping>
      

      webservices.xml
      <?xml version="1.0" encoding="UTF-8"?>
      
      <webservices
       xmlns="http://java.sun.com/xml/ns/j2ee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/j2ee_web_services_1_1.xsd"
       version="1.1">
      
       <webservice-description>
       <icon>
       </icon>
       <webservice-description-name>Tutorial</webservice-description-name>
       <wsdl-file>META-INF/wsdl/service.wsdl</wsdl-file>
       <jaxrpc-mapping-file>META-INF/mapping.xml</jaxrpc-mapping-file>
       <port-component>
       <icon>
       </icon>
       <port-component-name>TutorialHelloEndpointPort</port-component-name>
       <wsdl-port>TutorialHelloEndpointPort</wsdl-port>
       <service-endpoint-interface>tutorial.interfaces.TutorialHelloEndpoint</service-endpoint-interface>
       <service-impl-bean>
       <ejb-link>Hello</ejb-link>
       </service-impl-bean>
       </port-component>
       </webservice-description>
      </webservices>
      

      jboss.xml
       ...
       <session>
       <ejb-name>Hello</ejb-name>
      
       <method-attributes>
       </method-attributes>
       </session>
       ...
      

      ejb-jar.xml
       ...
       <description><![CDATA[No Description.]]></description>
       <display-name>Generated by XDoclet</display-name>
       <enterprise-beans>
       <!-- Session Beans -->
       <session >
       <description><![CDATA[Description for Hello]]></description>
       <display-name>Name for Hello</display-name>
       <ejb-name>Hello</ejb-name>
       <service-endpoint>tutorial.interfaces.TutorialHelloEndpoint</service-endpoint>
       <ejb-class>tutorial.ejb.HelloBean</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Container</transaction-type>
      
       </session>
       ...
      

      wsdl-build.xml (ant-script)
      ...
       <target name="init">
       <mkdir dir="src/META-INF/wsdl" />
       <delete file="src/META-INF/wsdl/service.wsdl" />
       <copy file="resources/template.wsdl" tofile="src/META-INF/wsdl/service.wsdl" />
       </target>
       <target name="generateall" depends="init,generateTutorialHelloEndpoint">
       </target>
       <target name="generateTutorialHelloEndpoint">
       <echo message="Generate WSDL for TutorialHelloEndpoint" />
       <java classname="org.apache.axis.wsdl.Java2WSDL"
       classpathref="build.classpath" fork="yes">
       <arg value="-Isrc/META-INF/wsdl/service.wsdl" />
       <arg value="-osrc/META-INF/wsdl/service.wsdl" />
       <arg value="-lhttp://this.value.is.replaced.by.jboss" />
       <arg value="-STutorialHelloEndpointService" />
       <arg value="-sTutorialHelloEndpointPort" />
       <arg value="-uENCODED" />
       <arg value="-ptutorial.interfaces=http://Hello" />
       <arg value="tutorial.interfaces.TutorialHelloEndpoint" />
       </java>
       </target>
      ...
      

      xdoclet-build.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <project default="_xdoclet_generation_" name="XDoclet Generator">
      <property file="xdoclet-build.properties"/>
      <property name="eclipse.home" value="C:/Java/eclipse"/>
      <property name="xdoclet.basedir" value="${eclipse.home}/plugins/org.jboss.ide.eclipse.xdoclet.core_1.4.1.e30"/>
      <property name="jboss.net.version" value="4.0"/>
      
      <path id="project.classpath"><pathelement location="bin"/>
       ...
      </path>
      
      <path id="xdoclet.classpath">
       <path refid="project.classpath"/>
       <fileset dir="${xdoclet.basedir}">
       <include name="*.jar"/>
       <exclude name="xdoclet-module-jboss-net-*.jar"/>
       </fileset>
       <fileset dir="${xdoclet.basedir}">
       <include name="xdoclet-module-jboss-net-${jboss.net.version}*.jar"/>
       </fileset>
      </path>
      
      <target name="_xdoclet_generation_" depends="N10004"/>
      <target name="N10004" description="EJB-Configuration">
       <taskdef classpathref="xdoclet.classpath" classname="xdoclet.modules.ejb.EjbDocletTask" name="ejbdoclet"/>
       <ejbdoclet ejbSpec="2.1" destDir="src" force="true" >
       <deploymentdescriptor destDir="src/META-INF" >
       </deploymentdescriptor>
       <fileset dir="src" includes="**/*Bean.java" >
       </fileset>
       <jboss Version="4.0" destDir="src/META-INF" >
       </jboss>
       <packageSubstitution packages="ejb" substituteWith="interfaces" >
       </packageSubstitution>
       <service-endpoint pattern="{0}Endpoint" destDir="src" >
       </service-endpoint>
       </ejbdoclet>
       <taskdef classpathref="xdoclet.classpath"
       classname="xdoclet.modules.wsee.WseeDocletTask" name="wseedoclet"/>
       <wseedoclet jaxrpcMappingFile="META-INF/mapping.xml" wsdlFile="META-INF/wsdl/service.wsdl" destDir="src/META-INF" force="true" >
       <deploymentdescriptor>
       <configParam name="Name" value="Tutorial" >
       </configParam>
       </deploymentdescriptor>
       <fileset dir="src" includes="**/*Bean.java" excludes="" >
       </fileset>
       </wseedoclet>
      </target>
      </project>
      

      packaging-build.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <project default="_packaging_generation_" name="Packaging Generator">
       <target name="_packaging_generation_" depends="N10004"/>
       <target name="N10004" description="Tutorial.jar">
       <mkdir dir="build"/>
       <jar destfile="build/Tutorial.jar">
       <zipfileset dir="bin" includes="**/*.class"/>
       <zipfileset dir="src/META-INF" prefix="META-INF" includes="**/*"/>
       </jar>
       </target>
      </project>
      



      Custom Type: Person
      package tutorial.myobjects;
      
      public class Person {
       private int nAge;
       private String strName;
      
       public Person() {
       setNAge(-1);
       setStrName("NONAME");
       }
      
       public Person(int age, String name) {
       setNAge(age);
       setStrName(name);
       }
      
       public int getNAge() { return nAge; }
       public void setNAge(int age) { nAge = age; }
       public String getStrName() { return strName; }
       public void setStrName(String strName) { this.strName = strName; }
      
      }
      


      Thank you!