Skip navigation
Blackmore111
Currently Being Moderated

Calling EJB from cfm page

Jul 4, 2012 10:36 PM

Tags: #error #java #coldfusion_9 #lookup #ejb

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. RemoteInitialContextFactory");

  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

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points