1

I am using JBoss4.2.2 and java6.

The deployed ear's name is apa.ear

In a servlet I have the following code line:

placeBid = (PlaceBid) context.lookup("apa/"
  + PlaceBid.class.getSimpleName() + "/remote");

I have a generated jboss-app.xml like this:

<jboss-app>
  <loader-repository>apa:app=ejb3</loader-repository>
</jboss-app>

When trying to get the PlaceBid via the context I get this exception

java.lang.ClassCastException: $Proxy99 cannot be cast to se.nextit.actionbazaar.buslogic.PlaceBid

The PlaceBid interface looks like this:

@Remote
public interface PlaceBid {
 Long addBid(String userId, Long itemId, Double bidPrice);
}

When I run the example coming with EJB3 in action it works. EJB3 in action sample code comes with ant building. I want to use Maven so I have rearranged the code some.

However, I don't understan what I am doing wrong here. I have some thoughts about the jboss-app.xml file. I am not sure of how its content should look like.

Grateful for any help.

Best wishes Lasse

1
  • give the code where you are injecting PlaceBid Commented Apr 5, 2010 at 7:17

2 Answers 2

1

As a first step, try the following:

Object obj = context.lookup("apa/" + PlaceBid.class.getSimpleName() + "/remote");
System.out.println("Object = " + obj.getClass().getName());
System.out.println("Interfaces = " + Arrays.toString(obj.getClass().getInterfaces()));

It will tell you what the actual stub concrete class is and what interfaces it implements. This may then give you enough of a hint to work out what's going wrong.

Also presumably your bean is defined as:

@Stateless
public class MyPlaceBidBean implements PlaceBid {
    ...
}

i.e. it implements the PlaceBid interface?

Sign up to request clarification or add additional context in comments.

Comments

0

If context is of type javax.naming.Context (or InitialContext), then the problem is that you have a missing call to PortableRemoteObject.narrow:

placeBid = (PlaceBid) PortableRemoteObject.narrow(context.lookup("apa/"
  + PlaceBid.class.getSimpleName() + "/remote", PlaceBid.class);

This is required by the EJB specification for remote interfaces. If you use a reference instead (@EJB or ejb-ref), the container will handle the narrow for you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.