Skip to main content

Creating a CXF Maven Web Service Client in Eclpise

This post will describe its how easy to create web service client using cxf.

create simple maven project 

  • open eclipse 
  • create maven project  quick start

WSDL 

I will using weather service to do the deployment. get the wsdl from
http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL

save it at src/main/wsdl/weather.wsdl

add cxf plugin


open the pom.xml

create a tag  <build></build> inside <project> tag if not existing.
create a <plugins></plugins> inside <build> tag
paste following within <plugins> tags


            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>2.1.2</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <sourceRoot>target/generated/cxf</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>src/main/wsdl/weather.wsdl</wsdl>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>


implementation

generate-sources
use following command to generate the java classes from wsdl.

mvn generate-sources

create a jar file using
mv install
 
java codes should be created at target folder.
new java files should be able to located at
target/generated/cxf

to use the code in our code, for eclipse we will have to add the newly created jar to class path.

now go to main java class.

and update it to call the web service.

    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
        Weather weather = new Weather();
        WeatherSoap weatherSoap = weather.getWeatherSoap();
        ForecastReturn forecastReturn=weatherSoap.getCityForecastByZIP("94025");
       
        List< Forecast > forecasts = forecastReturn.getForecastResult().getForecast();
       
        for (Forecast forecast : forecasts ){
            System.out.println("------------------------------");
            System.out.println(forecast.getDate().toString());
            System.out.println(forecast.getProbabilityOfPrecipiation().getDaytime().toString() );
            System.out.println(forecast.getTemperatures().getDaytimeHigh().toString());
            System.out.println(forecast.getDesciption().toString());
            System.out.println(forecast.getWeatherID() );
            System.out.println(forecast.getClass().toString());
          
          
        }
    }


out put will  be

Hello World!
------------------------------
2013-01-03T00:00:00
10
56
Partly Cloudy
2
class com.cdyne.ws.weatherws.Forecast
------------------------------
2013-01-04T00:00:00
00
57
Partly Cloudy
2
class com.cdyne.ws.weatherws.Forecast
------------------------------
2013-01-05T00:00:00
10
58
Partly Cloudy
2
class com.cdyne.ws.weatherws.Forecast
------------------------------
2013-01-06T00:00:00
20
56
Partly Cloudy
2
class com.cdyne.ws.weatherws.Forecast
------------------------------
2013-01-07T00:00:00
10
58
Partly Cloudy
2
class com.cdyne.ws.weatherws.Forecast
------------------------------
2013-01-08T00:00:00
10
58
Partly Cloudy
2
class com.cdyne.ws.weatherws.Forecast
------------------------------
2013-01-09T00:00:00
10
57
Partly Cloudy
2
class com.cdyne.ws.weatherws.Forecast


NOTE:
eclipse validation will requests to put plugins tag inside plugins management in the pom.xml. Even though this will solve eclipse issue, it will not create the java files using wsdl. so make sure plugins tag is directly under build tag.

Comments

Popular posts from this blog

Oracle Database 12c installation on Ubuntu 16.04

This article describes how to install Oracle 12c 64bit database on Ubuntu 16.04 64bit. Download software  Download the Oracle software from OTN or MOS or get a downloaded zip file. OTN: Oracle Database 12c Release 1 (12.1.0.2) Software (64-bit). edelivery: Oracle Database 12c Release 1 (12.1.0.2) Software (64-bit)   Unpacking  You should have following two files downloaded now. linuxamd64_12102_database_1of2.zip linuxamd64_12102_database_2of2.zip Unzip and copy them to \tmp\databases NOTE: you might have to merge two unzipped folders to create a single folder. Create new groups and users Open a terminal and execute following commands. you might need root permission. groupadd -g 502 oinstall groupadd -g 503 dba groupadd -g 504 oper groupadd -g 505 asmadmin Now create the oracle user useradd -u 502 -g oinstall -G dba,asmadmin,oper -s /bin/bash -m oracle You will prompt to set to password. set a momorable password and write it down. ...

DBCA : No Protocol specified

when trying to execute dbca from linux terminal got this error message. now execute the command xhost, you probably receiving No protocol specified xhost:  unable to open display ":0" issue is your user is not allowed to access the x server. You can use xhost to limit access for X server for security reasons. probably you are logged in as oracle user. switch back to default user and execute xhost again. you should see something like SI:localuser:nuwan solution is adding the oracle to access control list xhost +SI:localuser:oracle now go back to oracle user and try dbca it should be working

Java Multithreading 2021

Thread Thread Is a subprocess that follows a separate execution path, different stack frame and executes independently but they share the same process resources.  Multithreading is the process of executing one or more threads simultaneously that helps in executing multiple tasks at the same time. Advantages less memory fast efficient Supports multitasking Exception in one thread does not affect the other    Thread lifecycle New Runnable Running Non-Runnable Terminated   Ways to create a thread? Extending Thread class Implementing Runnable class   Thread.start() vs Thread.run() Class java.lang.Thread .start() Creates a new thread and the run() method is executed on the newly created thread. Can’t be invoked more than one time otherwise throws java.lang.IllegalStateException.  Interface java.lang.Runnable.run(), No new thread is created and the run() method is executed on the calling thread itself. Multiple invocation is possible   Constructors of a th...