2 Replies Latest reply on Jul 14, 2012 12:18 PM by BKBK

    Calling EJB from cfm page

    Blackmore111

      Hello.

      I'm using ColdFusion 9 and openejb 4.0.0. Have a problem with calling ejb from cfm page. Stuck at hello world : )

      Code:

       

      <CFOBJECT

          action=create

          name=ctx

          type="JAVA"

          class="javax.naming.Context">

       

      <!--- Create the Properties object and call an explicit constructor--->

      <CFOBJECT

          action=create

          name=prop

          type="JAVA"

          class="java.util.Properties">

       

      <!--- Call the init method (provided by cfobject)

              to invoke the Properties object constructor. --->

      <cfset prop.init()>

       

      <!--- Specify the properties These are required for a remote server only --->

      <cfset prop.put(ctx.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory")>

      <cfset prop.put(ctx.PROVIDER_URL, "localhost:4201")>

       

      <CFOBJECT

          action=create

          name=initContext

          type="JAVA"

          class="javax.naming.InitialContext">

       

      <cfset initContext.init(prop)>

       

      <cfset home = initContext.lookup("HelloBeanRemote")>

       

       

      initContext.lookup causes an unknown error, browser just shows HTTP 500 (Internal Server Error)

       

      However, this code on java works just perfect:

       

      package org.acme;

      import java.util.Properties;

      import javax.naming.InitialContext;

      import javax.naming.Context;

      import javax.rmi.PortableRemoteObject;

      public class HelloClient

      {

              public static void main(String[] args) throws Exception

        {

        Properties props = new Properties();

        props.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.openejb.client.RemoteInitialContext Factory");

        props.put(Context.PROVIDER_URL,"127.0.0.1:4201");

        Context ctx = new InitialContext(props);

        Object ref = ctx.lookup("HelloBeanRemote");

        Hello h = (Hello)PortableRemoteObject.narrow(ref,Hello.class);

        String result = h.sayHello();

        int summa = h.sum(37, 5);

        System.out.println(result);

        System.out.println(summa);

        }

      }

       

       

      So I created a java class named HelloInterface which does the whole thing and returns string recieved from bean. Tested it with java, works fine, but calling it from CF gets to HTTP 500 too. Code:

       

      <cfobject

                action="create"

         type="java"

                class="org.acme.HelloInterface"

                name="hello">

       

      <cfset msg = hello.getHello()>

      [<cfoutput>#msg#</cfoutput>]

       

      Message was edited by: Blackmore111