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
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
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

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Private Remote Maven Repository With Artipie
  • How To Deploy Helidon Application to Kubernetes With Kubernetes Maven Plugin
  • Deploy MuleSoft App to CloudHub2 Using GitHub Actions CI/CD Pipeline
  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin

Trending

  • .NET Performance Optimization Techniques for Expert Developers
  • Log Analysis: How to Digest 15 Billion Logs Per Day and Keep Big Queries Within 1 Second
  • CI/CD Tools and Technologies: Unlock the Power of DevOps
  • What Technical Skills Can You Expect To Gain From a DevOps Course Syllabus?
  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.

Ashish Lohia user avatar by
Ashish Lohia
CORE ·
Jun. 04, 18 · Tutorial
Like (2)
Save
Tweet
Share
39.77K 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
  • How To Deploy Helidon Application to Kubernetes With Kubernetes Maven Plugin
  • Deploy MuleSoft App to CloudHub2 Using GitHub Actions CI/CD Pipeline
  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • 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: