Search code examples
ejb-3.0rmiclasscastexception

EJB3 remote invocation throws ClassCastException


Somehow when I try a remote remote EJB3 call the ClassCastException is thrown.

Server:

public interface CardManager extends Manager {
     public CardCheckResponse check(CardCheckRequest request);
}


@Remote
public interface RMICardManagerRemote extends CardManager {
     static String CARD_CHECK_RMI_REMOTE_JNDI = "CardCheckRMI/remote";
}


@Stateless
@RemoteBinding(jndiBinding = RMICardManagerRemote.CARD_CHECK_RMI_REMOTE_JNDI)
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class RealRMICardManager implements RMICardManagerRemote {
    private CardManager cardManager = injector.getInstance(CardManager.class);

    @Override
    public CardCheckResponse check(CardCheckRequest request) {
    return cardManager.check(request);
    }

}

Client:

InitialContext remoteContext = new InitialContext(PropertiesUtil.getCardCheckProp());
RMICardManagerRemote rmiCardManagerRemote = (RMICardManagerRemote) remoteContext.lookup(RMICardManagerRemote.CARD_CHECK_RMI_REMOTE_JNDI);

//throws ClassCastException
CardCheckResponse cardCheckResponse = rmiCardManagerRemote.check(cardCheckRequest); 

Stacktrace:

java.lang.ClassCastException: com.cardcheck.dto.CardCheckResponse cannot be cast to com.cardcheck.dto.CardCheckResponse
    at $Proxy307.check(Unknown Source)
    at com.xxx.cardCheck(RechargeAdapter.java:267)

I've checked if it was duplicate jar, but is not the case. Does anyone have any idea to solve this problem?

Thanks in advance


Solution

  • Solved!

    The problem is caused by JBoss's unified class loader. I solved my problem creating a custom loader in jboss-app.xml:

    <loader-repository> com.cardcheck loader = cardCheck heard </ loader-repository>