Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Polymorphism & Web Services. Fact or fiction?

843833Nov 13 2007
Greetings to all,

I have made some research before posting this question but it unfortunately had no results. I am still blind on the following subject and anybody who could give me some light would be a lot appreciated.

I have implemented a server and exposed its services in my 'DispatcherBean' EJB. An example follows:
package nk.example.examplews;

import javax.ejb.Stateless;
import nk.example.LittleEJBs.HappyEJB;
import nk.example.LittleEJBs.LittleEJB;
import nk.example.LittleEJBs.MoodyEJB;
import nk.example.examplews.Dispatcher;

@javax.jws.WebService(name="DispatcherBean", targetNamespace="urn:examplews.example.nk", serviceName="DispatcherBeanService")
public @Stateless class DispatcherBean implements Dispatcher, DispatcherLocal {

	@javax.jws.WebMethod()
	public String sayHi(LittleEJB aLittleEJB) {
		return aLittleEJB.sayHi();
	}
}
LittleEJB is an abstract class, parent of MoodyEJB and HappyEJB. The problem is: After using the WSDL to get the stubs to the client
I CAN NOT SEE the subclasses of LittleEJB. All I see is the LittleEJB.
Then I did the following: I added two dummy methods in my DispatcherBean:

@javax.jws.WebMethod()
	public void dummyHappyEJB(HappyEJB happy){}
	
	@javax.jws.WebMethod()
	public void dummyMoodyEJB(MoodyEJB moody){}
Doing that, I was hapilly able to see the subclasses on the client, but ... they ain' t working !!!
If I make the parent class (LittleEJB) abstract then i get an unmarshall exception when it tries to instantiate !!!! the abstract class.
If I remove the abstract key and keep it a simple class then it doesn fail, nor it throws any exception but it just don' t work. The subclass constructors are never called. Only the parent class' constructor is called.

Therefore, I am prisoned to make a separate method and a whole distinct class for each kind of message I want the client to send to the server.

Is that it?? Using Web Services also means forgeting the great concept of OO which is called polymorphism???

Or is there any workround?
Or even something that I don' t know? I think I found workarounds for C++ and VB (#$@^#$%).

If anyone has solved it and knows how to guide me or can tell me where to search, please do so.
Thank you all.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 11 2007
Added on Nov 13 2007
0 comments
179 views