IN this blog i will be showing how to consume SOAP webservice in java by generating Client code using Apache CXF.
Prerequisites for this blog are as follows.
Once the client code is generate. Following are the important note, which will help you in quick startup.
Prerequisites for this blog are as follows.
- Eclipse Mars
- Java
- Apache CXF
- WSDL file for any SOAP webservice.
Install CXF
Apache CXF can be downloaded from "CXF". After downloading setup, unzip it in your system.
Configure cxf in eclipse.
Go to Windows - Preferences - Webservice - CXF 2.0 Preferences
Then select CXF Runtime - click on Add - Specify CSF installed location - Click on Finish.
I have highlighted the steps with blocks in below screen shot.
Create Web Project or Paste WSDL in existing project.
After configuring you need create Project in eclipse, or if you are using it in existing project then paste the WSDL file which you have received from service provider.
After configuring you need create Project in eclipse, or if you are using it in existing project then paste the WSDL file which you have received from service provider.
Next step will be to generate the client code
Right click on wsdl file, Go to - Webservice - Generate Client
Webservice Client popup will come, next specify the Configuration by clicking on the "Webservice runtime" link. In the Client configuration popup select "Apache CXF 2.x". Click OK.
Click next button, specify the package incase it needs to be changed. Otherwise keep everything default and finish the steps.
Once the client code is generate. Following are the important note, which will help you in quick startup.
- Locate file which has name with *_Client.java. This is sample client code which is generated by CXF. This shows invocation steps.
- Locate file which extends "javax.xml.ws.Service", this is the main service class which will be utilized in invoking the service.
GlobalWeather ss = new GlobalWeather();
GlobalWeatherSoap port = ss.getGlobalWeatherSoap();
java.lang.String _getCitiesByCountry__return = port.getCitiesByCountry("Country Name");
System.out.println("getCitiesByCountry.result=" + _getCitiesByCountry__return);
Incase you need to override the end point url, following code can be used to override the end point url.
GlobalWeather ss = new GlobalWeather(); GlobalWeatherSoap port = ss.getGlobalWeatherSoap(); //code to override the end point BindingProvider bp = (BindingProvider) port; bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "NEW URL"); java.lang.String _getCitiesByCountry__return = port.getCitiesByCountry("Country Name"); System.out.println("getCitiesByCountry.result=" + _getCitiesByCountry__return);
No comments:
Post a Comment