Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAXWS client erroring out when calling a stateless session bean exposed as a webservice

 
Allen Bandela
Ranch Hand
Posts: 128
Eclipse IDE MS IE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have deployed a Stateless Session bean as a webservice in Glassfish. I'm using JAXWS client to call the business method on the web service as follows:


The HelloBean webservice is as follows:


I get the following exception when running the client:


I'm unable to figure out why it is expecting an Interface. I'm running the example from Mastering EJB 4th edition Chap 5. Can anyone please advise.

Thanks,
Allen
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
It looks like you have forgotten to add the endpointInterface element to the @WebService annotation.
I think it should look like this:

Note that the endpoint interface must also be annotated with the @WebService annotation.
Hope this helps!
 
Allen Bandela
Ranch Hand
Posts: 128
Eclipse IDE MS IE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. That worked. I also had to change to

Allen
 
Chintan Rajyaguru
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since your code is working, you might not care but I would like to clarify something.

When you use dynamic proxy, you have no generated code. So, when you use the code service.getPort (Class<T> endpointInterface), YOU need to supply an INTERFACE that the dynamic proxy can implement. This interface must conform to the port type defined in the WSDL. In your case, you were passing a class as opposed to an interface, that's why you got the error. The getPort() method needs an interface, see the API javadoc here.

The easiest way to get the interface is to use the remote interface you have already defined for your EJB. Make sure the interface is packaged with the client and is available in the runtime classpath.

The more interesting questions is, what if you had a POJO based web service? The JAX-WS specification says if [minimally] a class has @WebService annotation, all of its methods must be exposed as a web service and an interface must be generated and used dynamically at runtime. In this scenario, you have no interface. How would you write a client? Or what if your web service is written in .Net and you want to write dynamic client. Where would you get the interface from and how would you invoke the service?

Well, you have two choices: (1) Generate and use static client. In your example, it would generate a class GreeterService.java or something like that. This class will have a method getXYZPort(). You can use this method to get the port and invoke the service on it. (2) Generate code, which among other things will generate an interface. Write a dynamic client and pass this interface to your getPort() method. The limitation in this case would be that you still have to 'generate' client side code.

I consider this issue a lack of completeness in the JAX-WS specification. If the specs allow a POJO web service without an interface, it should also allow a dynamic client without an interface. As long as you pass the port name and namespace, it should automatically generate the endpoint interface at runtime. Unfortunately, that's not how it works.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chintan!
It was a very interesting message!
Best regards!
 
Allen Bandela
Ranch Hand
Posts: 128
Eclipse IDE MS IE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did have this question in the back of my mind. Thanks for clarifying.

In your comment, you speify twice to generate code
(1) Generate and use static client.
.
(2) Generate code, which among other things will generate an interface


How to generate. By using tools and the wsdl? I guess I'll learn about this as I read further in the book..
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, JAX-WS contains the wsgen and wsimport tools which are used to generate misc. artifacts.
Check this webpage: http://www.j2ee.me/webservices/docs/2.0/jaxws/jaxws-tools.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic