• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Calling EJB from cfm page

New Here ,
Jul 04, 2012 Jul 04, 2012

Copy link to clipboard

Copied

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

TOPICS
Advanced techniques

Views

846

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 08, 2012 Jul 08, 2012

Copy link to clipboard

Copied

Solved. Should've added one more library to CF Classpath - javax.ejb.jar

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 14, 2012 Jul 14, 2012

Copy link to clipboard

Copied

LATEST

Please kindly mark it as solved. Just might be of help to somebody else.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation