5 Replies Latest reply: Aug 14, 2012 10:18 AM by Cheng Fang RSS

cannot be cast to... when lookup local using jboss 7.1.1 Final

Doan Long Newbie

Untitled.png

sample Attach Files

 

SERVER

[CODE]

package org.local.calculator;

import javax.ejb.Local;

@Local

public interface CalculatorLocal {

public int add(int x, int y);

}

 

package org.sample.calculatorbean;
import javax.ejb.Stateless;
import org.local.calculator.CalculatorLocal;

@Stateless(name = "CalculatorBean")
public class CalculatorBean implements CalculatorLocal {
public int add(int x, int y) {
  System.out.println("\n\t[CalculatorBean]  add() invoked.");
  return (x + y);
}
}

 

package org.sample.remote;
import javax.ejb.*;

@Remote
public interface CallerRemote {
public String testMethod();

public String callEJBOne(int a, int b);
}

package org.sample.remotecaller;
import javax.annotation.Resource;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
import org.local.calculator.CalculatorLocal;
import org.sample.remote.CallerRemote;

@Stateless(name = "CallerName", mappedName = "CallerMappedName")
public class CallerBean implements CallerRemote {
@Resource
private SessionContext context;
private CalculatorLocal local;

public String testMethod() {
  System.out.println("\n\n\t Bean testMethod() called....");
  return "DONE----returned";
}

public String callEJBOne(int a, int b) {
  int result = 0;
  try {
   Object object = context
     .lookup("java:global/sample-ear/sample-ejb/CalculatorBean!org.local.calculator.CalculatorLocal");
   local = (CalculatorLocal) object;
   System.out.println("\n\n\t Bean callEJBOne(a,b) called....");
   result = local.add(a, b);
  } catch (Exception e) {
   e.printStackTrace();
  }
  return "DONE----result = " + result;
}
}

 

[CODE]

CLIENT

 

[CODE]

package org.sample.client;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.sample.remote.CallerRemote;

public class TestClientEjb3 {
public static void main(String[] args) {
  String result = "";
  System.out.println("\n\n\t Hello ...");
  try {
   Properties p = new Properties();
   p.put(Context.INITIAL_CONTEXT_FACTORY,
     "org.jboss.naming.remote.client.InitialContextFactory");
   p.put(Context.PROVIDER_URL, "remote://localhost:4447");
   p.put(Context.SECURITY_PRINCIPAL, "fmis2");
   p.put(Context.SECURITY_CREDENTIALS, "fmis");
   InitialContext initialContext = new InitialContext(p);
   CallerRemote remote = (CallerRemote) initialContext
     .lookup("sample-ear/remote-ejb/CallerName!org.sample.remote.CallerRemote");
   result = remote.callEJBOne(1000, 2000);
  } catch (Exception e) {
   e.printStackTrace();
  }
  System.out.println("ONE----result = " + result);
}
}

[CODE]

Run error

 

13:34:07,435 ERROR [stderr] (EJB default - 1) java.lang.ClassCastException: org.local.calculator.CalculatorLocal$$$view2 cannot be cast to org.local.calculator.CalculatorLocal

13:34:07,437 ERROR [stderr] (EJB default - 1)  at org.sample.remotecaller.CallerBean.callEJBOne(CallerBean.java:26)

13:34:07,437 ERROR [stderr] (EJB default - 1)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

13:34:07,438 ERROR [stderr] (EJB default - 1)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

13:34:07,439 ERROR [stderr] (EJB default - 1)  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

13:34:07,440 ERROR [stderr] (EJB default - 1)  at java.lang.reflect.Method.invoke(Method.java:597)

13:34:07,441 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72)

13:34:07,442 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

13:34:07,443 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)

13:34:07,444 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36)

13:34:07,445 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

13:34:07,446 ERROR [stderr] (EJB default - 1)  at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)

13:34:07,447 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

13:34:07,449 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)

13:34:07,450 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

13:34:07,451 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

13:34:07,452 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)

13:34:07,453 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

13:34:07,454 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)

13:34:07,456 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

13:34:07,457 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228)

13:34:07,457 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304)

13:34:07,458 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190)

13:34:07,459 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

13:34:07,462 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ejb3.remote.EJBRemoteTransactionPropagatingInterceptor.processInvocation(EJBRemoteTransactionPropagatingInterceptor.java:80)

13:34:07,463 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

13:34:07,464 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)

13:34:07,466 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

13:34:07,467 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)

13:34:07,468 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

13:34:07,469 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)

13:34:07,470 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

13:34:07,471 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:43)

13:34:07,474 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

13:34:07,476 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)

13:34:07,477 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

13:34:07,478 ERROR [stderr] (EJB default - 1)  at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

13:34:07,479 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165)

13:34:07,480 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.invokeMethod(MethodInvocationMessageHandler.java:302)

13:34:07,481 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.access$200(MethodInvocationMessageHandler.java:64)

13:34:07,483 ERROR [stderr] (EJB default - 1)  at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler$1.run(MethodInvocationMessageHandler.java:196)

13:34:07,484 ERROR [stderr] (EJB default - 1)  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)

13:34:07,485 ERROR [stderr] (EJB default - 1)  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

13:34:07,486 ERROR [stderr] (EJB default - 1)  at java.util.concurrent.FutureTask.run(FutureTask.java:138)

13:34:07,486 ERROR [stderr] (EJB default - 1)  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

13:34:07,487 ERROR [stderr] (EJB default - 1)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

13:34:07,488 ERROR [stderr] (EJB default - 1)  at java.lang.Thread.run(Thread.java:662)

13:34:07,489 ERROR [stderr] (EJB default - 1)  at org.jboss.threads.JBossThread.run(JBossThread.java:122)

13:34:07,521 INFO  [org.jboss.as.naming] (Remoting "longdv" task-3) JBAS011806: Channel end notification received, closing channel Channel ID 78dc8332 (inbound) of Remoting connection 00472c8d to null