robert allurent [
https://community.jboss.org/people/robert.piskule] created the
discussion
"Real hard time with EJB3-- javax.naming.Reference instead of $Proxy"
To view the discussion, visit:
https://community.jboss.org/message/750237#750237
--------------------------------------------------------------
Hey all. I'm having a really difficult time with EJB3.
I have a server running a simple calculator demo. I am trying to create a Mule ESB call
into it. If I run my calculator client standalone, it works fine. If I move my calculator
client to Mule, it fails.
One hint I have is that running standalone, my EJB call returns a class $Proxy2 and
running on Mule, it returns class javax.naming.Reference. Any Ideas
OUTPUT:
If I run my EJB Client on my local client, it works just fine:
Initializing
CLASS:class $Proxy2
Loaded Calculator Bean
public final float $Proxy2.division(float,float), public final float
$Proxy2.subtract(float,float), .....public final void java.lang.Object.wait() throws
java.lang.InterruptedException public final float $Proxy2.division(float,float), public
final float $Proxy2.subtract(float,float), .....public final void java.lang.Object.wait()
throws java.lang.InterruptedException
Result:-3.0
But if I run my EJB Client on my Mule Server, it breaks:
Initializing
CLASS:class javax.naming.Reference
Loaded Calculator Bean
public void javax.naming.Reference.add(int,javax.naming.RefAddr), public void
javax.naming.Reference.add(javax.naming.RefAddr), ..... public void
javax.naming.Reference.add(int,javax.naming.RefAddr), public void
javax.naming.Reference.add(javax.naming.RefAddr), .....
java.lang.NoSuchMethodException: javax.naming.Reference.subtract(float, float)
at java.lang.Class.getMethod(Unknown Source)
CODE:
Here's my code. Like I said, it's identicle on both my Mule Server and Eclipse
Client.
package com.allurent;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.mule.api.MuleEvent;
import org.mule.api.MuleException;
public class CalculatorLocal implements org.mule.api.processor.MessageProcessor
{
private static Object calculator = null;
public static void jspInit() {
System.out.println("Initializing");
Hashtable<String, String> t = new Hashtable<String,
String>();
t.put("java.naming.provider.url",
"jnp://localhost:1099");
t.put("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
t.put("java.naming.factory.initial",
"org.jboss.naming.NamingContextFactory");
InitialContext ic = null;
try {
ic = new InitialContext(t);
} catch (NamingException e) {
e.printStackTrace();
}
Object temp = null;
try {
temp = ic.lookup("example/CalculatorBean/remote");
} catch (NamingException e) {
e.printStackTrace();
}
System.out.println("CLASS:"+temp.getClass());
calculator = temp;
System.out.println("Loaded Calculator Bean");
}
public static void jspDestroy() {
calculator = null;
}
public static void main (String [] args)
{
args = new String[3];
args[1] = "12";
args[2] = "15";
args[0] = "subtract";
jspInit();
try {
String s1 = args[1];
String s2 = args[2];
String s3 = args[0];
if ( s1 != null && s2 != null ) {
Float num1 = new Float(s1);
Float num2 = new Float(s2);
System.out.println(Arrays.toString(calculator.getClass().getMethods()));
Class<? extends Object> c = calculator.getClass();
Method m = c.getMethod(s3, float.class, float.class);
Object value = null;
value = m.invoke(calculator, num1.floatValue(), num2.floatValue());
System.out.println("Result:"+value.toString());
}
}
catch (Exception e) {
e.printStackTrace ();
}
jspDestroy();
}
@Override
public MuleEvent process(MuleEvent event) throws MuleException {
CalculatorLocal.main(new String [] {"test","test2"});
return null;
}
}
I've been working on this for 3 days now, and I'm at my wit's end.
Thanks,
-Rob
--------------------------------------------------------------
Reply to this message by going to Community
[
https://community.jboss.org/message/750237#750237]
Start a new discussion in EJB3 at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=1&...]