• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

use jaxws:binding to change a name of a web method

 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, ranchers,
I can use this external binding to change a webmethod hellWorld into HiWorld

I can use the wsdl to generate a client code. The client can call the HiWorld method. However, the server has helloWorld method instead. I got a no class definition found error.

So, what should I do?
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is your WSDL and how do you generate the client code?

Regards,
Frits
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using external binding to change method name while generating client code will be reflected in generated SEI, but will retain the original method name in @WebMethod(operationName="") which will be on the method of generated SEI.

Invoking Web Service w/ altered method name (at client) shouldn't be a issue as @WebMethod(operationName="") value is used when generating SOAP message.

Changing operationName value on generated SEI will cause invocation failure, with exception similar as below:
javax.xml.ws.WebServiceException: Method xyz is exposed as WebMethod, but there is no corresponding wsdl operation with name xyz



Regards,
Noni
 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose I have this :


I deployed the SEI and SBI on Tomcat. The WSDL has helloWorld as the operation node in portType node.
Suppose the WSDL is at http://localhost:8080/example/helloworld?wsdl

I generated the client code using wsimport -keep -p client http://localhost:8080/example/helloworld?wsdl -b external.xml , where external.xml is the file with the bindings in my previous post.
And so on the client code, I invoke hiWorld instead of helloWorld.
But I got a no class definition exception. I guess the reason is on the client code, it has hiWorld method, but the operation is helloWorld.
 
Noni Singh
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your request reaching the server? I mean, is the exception raised by client before sending request or server?

If reaching the server, could you check the SOAP request message which is getting generated. Per my understanding, it should have <helloWorld> instead of <hiWorld> as body part.

Can you try again, by generating client from same WSDL but w/o external binding as "no class definition exception" is for missing class.

 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tired it without -b external.xml. It worked.
But the server side does not generate any error message. On the client side, it throws the no class definition found exception. So, obviously, the the request has not reached the server yet.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How does your client code look like and can you post a bit of the exception stack trace?
 
Noni Singh
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which parameterStyle in @SOAPBinding annotation, WRAPPED (default) or BARE, you've on the SEI?
 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help. I tried with my homework as a practical example:


The WSDL (only relevant part shown):


//external binding file, changeName.xml




//The SEI from the client side after the changeName.xml is used
public interface OrderServiceWS{

@WebMethod(operationName = "catalogue")
@WebResult(targetNamespace = "")
@RequestWrapper(localName = "catalogue", targetNamespace = "http://...", className = "hw4Client.Catalogue")
@ResponseWrapper(localName = "catalogueResponse", targetNamespace = "http://...", className = "hw4Client.CatalogueResponse")
public hw4Client.CatalogueResponse.Return shopCatalogue();

}
[/code]

 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


@WebServiceRef(wsdlLocation="http://localhost:8080/inventoryWS/ws/OrderServiceHw4?wsdl")
private static OrderService service;
private static OrderServiceWS port;
service = new OrderService();
port = service.getOrderPort();
port.shopCatalogue();


You are injecting the OrderService instance in your client (is you client a Servlet, or an EJB, or a POJO?) in to the "service" field.

What I don't get is why you create a new Service instance ( service = new OrderService() )?

Regards,
Frits
 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The web service is deployed as a Servlet on Tomcat.

The wsimport generates the OrderService , OrderServiceWS and other artifacts from the WSDL on the client side. The client can use an instance of OrderService to invoke the service deployed on Tomcat.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but you still haven't answered my 2 questions.
 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To answer your second question:
The wsimport generates OrderService interface and OrderServiceWS class from the WSDL. So, the client creates an instance of OrderService to invoke the web methods.
In Java Web Service Up and Running by Martin Kalin, in Chapter 1-2, there are example like that.

Here is another example:
http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/

In the HelloWorldClient example, an instance of Service, HelloWorldImpService is created to call the web method.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so why are you injecting the service with the webserviceref?
 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is part of my OrderService from the client:


My instructor provides the @WebServiceRef (....) to inject the WSDL.
I am sure it still works without the @WebServiceRef (...)
 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I look at an example from :
http://docs.oracle.com/javaee/6/tutorial/doc/bnayn.html

It also inject the WSDL by using @WebServiceRef(wsdlLocation=...)
I see your point now.
If I inject the service by @WebServiceRef, I don't even need to create an instance.

In my case,
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I see your point now.
If I inject the service by @WebServiceRef, I don't even need to create an instance.


Exactly

When you remove the @WebServiceRef, do you still get the exception?

Can you post a bit of the stacktrace?

Regards,
Frits
 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Experiment 1:

It works
But ...
 
Noni Singh
Greenhorn
Posts: 20
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Per JAX-WS 2.2 spec - "The WebServiceRef annotation is required to be honored when running on the Java EE 5 platform, where it is subject to the common resource
injection rules described by the platform specification [35]."


@WebServiceRef will work with JAX-WS managed clients: Servlet, EJB, or another Web service.

You client code looks like standalone java client and that's why the annotation is not working and service is null.


 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You client code looks like standalone java client and that's why the annotation is not working and service is null.


Correct!

Regards,
Frits
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic