DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Private Remote Maven Repository With Artipie
  • Using Python Libraries in Java
  • DGS GraphQL and Spring Boot
  • How to Build a New API Quickly Using Spring Boot and Maven

Trending

  • Building an AI/ML Data Lake With Apache Iceberg
  • Dropwizard vs. Micronaut: Unpacking the Best Framework for Microservices
  • IoT and Cybersecurity: Addressing Data Privacy and Security Challenges
  • Cosmos DB Disaster Recovery: Multi-Region Write Pitfalls and How to Evade Them
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Creating Apache AXIS2 Client Jar From a WSDL Using MAVEN

Creating Apache AXIS2 Client Jar From a WSDL Using MAVEN

In this article, we will try to create a client jar from a WSDL file through which we can communicate with the exposed SOAP web services.

By 
Ashish Lohia user avatar
Ashish Lohia
DZone Core CORE ·
Jun. 04, 18 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
42.5K Views

Join the DZone community and get the full member experience.

Join For Free

Prerequisites

Before starting, you will need Java and Maven installed in your system. You can refer here.

BackDrop

In this article, we will try to create a client jar from a WSDL file through which we can communicate with the exposed SOAP web services. The technology used to create the client jar will be Apache Axis2. The main reason I am writing this is because I faced some issues while trying to create a client for my own requirements. The motive behind creating the client jar is avoiding the boilerplate code to generate the SOAP message to a great extent. There are other ways to create clients as well, each having there own advantages and trade-offs.

Jar Creation Process

Create a simple maven project with a POM file.

Copy and paste the POM file below.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>{{your group id}}</groupId>
    <artifactId>{{your artifact id}}</artifactId>
    <version>{{version of jar}}</version>
    <name>{{name of jar}}</name>
    <build>
        <plugins>
            <!-- Generates JAVA source files from the WSDL -->
            <plugin>
                <groupId>org.apache.axis2</groupId>
                <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
                <version>1.7.7</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsdl2code</goal>
                        </goals>
                        <configuration>
                            <packageName>{{name of the package to be used}}</packageName>
                            <wsdlFile>{{path of WSDL file to be used}}</wsdlFile>
                            <databindingName>xmlbeans</databindingName>
                            <!--TODO: Update this file with new WSDL versions -->
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptorRefs>
                        <descriptorRef>src</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <!-- this is used for inheritance merges -->
                        <phase>package</phase>
                        <!-- bind to the packaging phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.apache.openejb</groupId>
                                    <artifactId>openejb-javaagent</artifactId>
                                    <version>3.0-beta-2</version>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>target/generated-sources/axis2/wsdl2code/resources</directory>
            </resource>
            <resource>
                <directory>target/generated-sources/xmlbeans/resources</directory>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
            <version>1.7.7</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

Modify the fields between {{ .. }} as per your requirement.

For example: 

groupId : com.ash.wsdl.java

artifactId: wsdl2java

version: 1

name: wsdl2java

packageName: com.ash.wsdl.java

wsdlFile: full path of your WSDL file.

After that, all you need to do is run mvn clean install from the root of the project.

The client jar will be automatically created and added to the local m2 repository.

Using the Jar to Communicate

Once the jar is successfully created, you can add its dependency in your application like this:

<dependency>
  <groupId> com.ash.wsdl.java</groupId>
  <artifactId>wsdl2java</artifactId>
  <version>1</version>
</dependency>

You will also need some external dependencies for the client to work.

<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.20</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.20</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-xmlbeans</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.apache.neethi</groupId>
<artifactId>neethi</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.woden</groupId>
<artifactId>woden-core</artifactId>
<version>1.0M10</version>
</dependency>
<dependency>
<groupId>org.apache.ws.xmlschema</groupId>
<artifactId>xmlschema-core</artifactId>
<version>2.2.1</version>
</dependency>

You are good to go now.

Now, let's see how we can call the web services through the jar.

ServiceStub ServiceStub= new ServiceStub();
Options options =ServiceStub._getServiceClient().getOptions();
options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, "true");
options.setProperty(HTTPConstants.CHUNKED, "false");
options.setManageSession(true);

Your service stub is ready to be used now. Just create the desired SOAP message objects from the Factory and make WS calls.

I am sharing one example from my application on how to use the stub.

OrderDocument orderDocument = OrderDocument.Factory.newInstance();
Order newOrder = orderDocument.addNewOrder();
OrderInput orderInput = newOrder.addNewInput();

OrderInputHeader requestHeader = orderInput.addNewHeader();
requestHeader.setServiceSessionKey("ash");
requestHeader.setRequestID("ash111");
requestHeader.setTimeout(10);
requestHeader.setPageSize(0);
requestHeader.setWaitForResponse(true);
requestHeader.setPagingDirection(0);

OrderInputParameters inputParameters = orderInput.addNewParameters();
OrderNumberArray orderNumberArray = inputParameters.addNewOrderNumberArray1();
orderNumberArray.addOrderNumber(1);
orderNumberArray = inputParameters.addNewOrderNumberArray1();
orderNumberArray.addOrderNumber(2);
inputParameters.setRelatedOrders(false);


OrderResponseDocument orderResponseDocument = iosplusServiceStub.order(orderDocument);

All the elements extend XmlBeans, so a lot of useful functionalities are available by default. For example, just doing a toString on any of the objects will generate the corresponding SOAP message for that object.

Post your questions or concerns in the comments, and I will try to answer as quickly as I can.

JAR (file format) Apache Axis2 Apache Maven

Opinions expressed by DZone contributors are their own.

Related

  • Private Remote Maven Repository With Artipie
  • Using Python Libraries in Java
  • DGS GraphQL and Spring Boot
  • How to Build a New API Quickly Using Spring Boot and Maven

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!