• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Why i can't cast my object properly?

 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day,

I'm working on implementation of an external vendor API, which is in fact an EJB service and package into an .ear file.

the idea is first we call to API manager, and then use the method which return a list of object, the object is belong to API proprietary object (ie:Status object).

What have been done so far, i managed to get the API manager which is not null, and the manager return a list, however it seem return me a list in different object type, as mentioned below, we expecting "Status" object but it return StatusImpl.

the API manager which is local session bean give the correct result if using stateless bean to implement the method of it, but not the case if we use Spring to do it.

Appreciated anyone can shed some light on this, what is wrong and how can i handle it ? Thanks a lot!

Below is the exception:


servlet springDispatcherServlet threw exception
java.lang.ClassCastException: com.hp.api.schoolclass.StatusImpl cannot be cast to com.api.schoolclass.Status



Below code managed to get the API manager



Below is how my own manager to call the API method


 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a wild guess, do you have a copy of Status class in your codebase or are you referring to the Status class from the EAR's jar of the EJB module?
 
Nakataa Kokuyo
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply Ankit, I need to put all necessary api .jar files as dependency in maven, the Status class considering in my code base right?

Appreciated your sharing what will happen if Status class in my codebase or EAR's jar.
 
Ankit Garg
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what the structure of your project is, but what I meant is there should not be two versions of Status class. I guess your web application in which you are using Spring to get the session bean and the EJB application is part of the same EAR. What I'm trying to say is there should not be two separate Status.java files, one in your EJB project and one in your WAR (Web application) project. The WAR project should have a dependency on EJB project's JAR to refer to Status class...
 
Nakataa Kokuyo
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankit,

Sound like making sense to me, we are using war project and we included the api jar file into our environment, we imported it in our client class, Let called this as "Local" Status.class, we then do a Context lookup to the ear file, we get the EJB manager and invoked it method and return result and finally assign back into "Local" Status.class.

I might be new to EJB, or what is the right approach i should go for? how my war project do the dependency to EAR project's jar ? appreciated if you have little snippet code to enlighten me if possible.

 
Ankit Garg
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still a little confused how everything is setup in your project. Let's take this one step at a time.

1. Are the EJB and WAR project are in the same EAR?
_I. If they are:
___a. You must have a compile time dependency on the EJB project.
___b. At runtime the Status.class would be available to the web application from the EJB application as it's running as part of the same EAR application.
_II. If the EJB and WAR are not part of the same EAR (I don't think that would be the case as you said your EJBs are local EJBs)
___a. In this case you'll have to package EJB project's JAR with your WAR project.
2. Are you using Maven? If yes maybe you can post your maven configuration how you've defined the dependencies...
 
Nakataa Kokuyo
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankit,

Sorry for confusion, The EJB and WAR are not part of same EAR.

means in the EJB which call the API method are package into EAR named "api-ear", we have a WAR to call this "api-ear" to get the value.

But both EAR and WAR under the same jboss server. so i have to take the EJB JAR and package together with my WAR ? is there a better choice? caused the EAR is provided by vendor. we try not to modify what they given.
 
Nakataa Kokuyo
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ankit for your help, found out it was due to duplicate API jar file.
 
Hot dog! An advertiser loves us THIS much:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic