tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alltomee <andrelopes....@gmail.com>
Subject EJB remote access (WAR to WAR) throws java.lang.ClassCastException: com.sun.proxy.$Proxy*** cannot be cast to ***
Date Sat, 17 Dec 2016 23:45:51 GMT
Good night. I'm struggling with this problem forever, so I resolved to put
this question here. Any help will be welcome 

I'm migrating from Glassfish to TomEE. By now, all WARs has been moved and
working by default at TomEE, except one. I have two WARs, one called
EJBSERVER and another called EJBCLIENTS. The EJBSERVER has a EJB called
Hello, that has a method called sayHello, like below:

*package ejbs;

import java.io.*;
import javax.ejb.*;
import javax.annotation.*;

import interfaces.*;

@Stateless
@LocalBean
public class Hello implements HelloJNDI, Serializable{

  private String message = "Hello ";

  public String sayHello(String name) {

    return message + name + "!";
  }

}*

The class HelloJNDI is a interface inside the same WAR but at package
interfaces, like follow:

*package interfaces;

import javax.ejb.*;

@Remote
public interface HelloJNDI{
  String sayHello(String name);
}*

As you can see, it's very simple, like that examples we find at Internet. 

So, now I have another WAR called EJBCLIENTS, who will be client of Hello
class through it's interface HelloJNDI.

The class ClientJNDI is a servlet that does this:

*import java.io.*;
import java.util.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import javax.inject.*;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.*;

import interfaces.*;

@WebServlet("/clientjndi")
public class ClientJNDI extends HttpServlet{

  public void doGet(HttpServletRequest req, HttpServletResponse res) throws
IOException{

    res.setContentType("text/html; charset=UTF-8");

    PrintWriter writer = res.getWriter();

    try{    
      InitialContext ctx = new InitialContext();
      HelloJNDI hello = (HelloJNDI)
ctx.lookup("java:global/ejbserver/Hello!interfaces.HelloJNDI");
      writer.print(hello.sayHello("World"));
    }
    catch(NamingException e){
      System.out.println("JNDI error");
      e.printStackTrace();
    }

    res.flushBuffer();

  }

}*

So, before anything, let me say that this example works perfectly at
Glassfish. At TomEE and OpenEJB, the following error is shown at browser:

*java.lang.ClassCastException: com.sun.proxy.$Proxy182 cannot be cast to
interfaces.HelloJNDI
	clients.ClientJNDI.doGet(ClientJNDI.java:28)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)*

What's wrong?



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/EJB-remote-access-WAR-to-WAR-throws-java-lang-ClassCastException-com-sun-proxy-Proxy-cannot-be-cast--tp4680774.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Mime
View raw message