<h2>Java Apache Axis2 web services client examples advanced</h2><br/><div style="overflow-x:auto"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta content="text/html; charset=UTF-8" /><meta name="copyright" content="(C) Copyright 2025" /><meta name="DC.rights.owner" content="(C) Copyright 2025" /><meta name="generator" content="DITA-OT" /><meta name="DC.type" content="concept" /><meta name="DC.title" content="Java Apache Axis2 web services client examples advanced" /><meta name="abstract" content="Examples showing how to construct and use an Axis2 client to consume a ServiceNow Web Service." /><meta name="description" content="Examples showing how to construct and use an Axis2 client to consume a ServiceNow Web Service." /><meta name="DC.subject" content="Java Apache Axis2 Web Services Client Examples" /><meta name="keywords" content="Java Apache Axis2 Web Services Client Examples" /><meta name="DC.relation" scheme="URI" content="../../../integrate/examples/concept/c_JAAWbSrvcsClntEx.html" /><meta name="DC.relation" scheme="URI" content="../../../build/applications/concept/api-implementation-reference.html" /><meta name="DC.relation" scheme="URI" content="../../../build/applications/concept/api-implementation.html" /><meta name="DC.relation" scheme="URI" content="../../../integrate/web-services/reference/r_AvailableWebServices.html" /><meta name="DC.relation" scheme="URI" content="../../../integrate/web-services/concept/inbound-web-services.html" /><meta name="DC.relation" scheme="URI" content="../../../integrate/examples/concept/c_InboundWebServiceExamples.html" /><meta name="DC.creator" content="ServiceNow" /><meta name="DC.date.created" content="2023-08-03" /><meta name="DC.date.modified" content="2025-01-30" /><meta name="DC.format" content="XHTML" /><meta name="DC.identifier" content="c_JAAWbSrvcsClntExAdv" /><link rel="stylesheet" type="text/css" href="../../../CSS/commonltr.css" /><title>Java Apache Axis2 web services client examples advanced</title></head><body id="c_JAAWbSrvcsClntExAdv"> <div class="breadcrumb"><a class="link" href="../../../build/applications/concept/api-implementation-reference.html" title="Get started using ServiceNow APIs with guides, resources, and reference documentation.">API implementation and reference</a> > <a class="link" href="../../../build/applications/concept/api-implementation.html" title="You can use JavaScript APIs to extend application server and client functionality. Use web services to connect ServiceNow applications to other software applications.">API implementation</a> > <a class="link" href="../../../integrate/web-services/reference/r_AvailableWebServices.html" title="HTTP-based web services allow diverse applications to talk to each other. ServiceNow supports both inbound (provider) and outbound (consumer) web services.">Web services</a> > <a class="link" href="../../../integrate/web-services/concept/inbound-web-services.html" title="You can use any of several web services to integrate with ServiceNow applications, including REST, SOAP, JSONv2, and RSS.">Inbound web services</a> > <a class="link" href="../../../integrate/examples/concept/c_InboundWebServiceExamples.html" title="Inbound web service examples demonstrate how to access ServiceNow web services.">Inbound web service examples</a> > </div> <h1 class="title topictitle1" id="ariaid-title1">Java Apache Axis2 web services client examples advanced</h1> <div class="body conbody"><p class="shortdesc">Examples showing how to construct and use an Axis2 client to consume a <span class="ph">ServiceNow</span> Web Service.</p> <p class="p">Axis is essentially a SOAP engine -- a framework for constructing SOAP processors such as clients, servers, or gateways. The current version of Axis is written in Java. This content is intended for system admins with a light development background in Java. To begin you would need Java JDK version 1.4.2 or higher and Axis2 version 1.0 or higher.</p> <div class="section"><h2 class="title sectiontitle">Create a Java Project</h2> <div class="p">This example uses Eclipse SDK Version: 3.4.2 for managing the source code and executing the web request. Eclipse is not required.<ul class="ul" id="c_JAAWbSrvcsClntExAdv__ul_gk3_tz3_gp"><li class="li">Open Eclipse and from the menu select <span class="ph menucascade"><span class="ph uicontrol">File</span> > <span class="ph uicontrol">New</span> > <span class="ph uicontrol">Project</span> > <span class="ph uicontrol">Java Project</span></span>.</li><li class="li">Give the project a name.</li><li class="li">Verify that the correct JRE is specified.<ul class="ul" id="c_JAAWbSrvcsClntExAdv__ul_yb5_xz3_gp"><li class="li">If using wsdl2java run "java -version" on the command line and this will be the version to specify for the project specific JRE.</li><li class="li">If using the Axis2 Codegen plugin use default JRE.<div class="p"><div class="fig fignone" id="c_JAAWbSrvcsClntExAdv__fig_ifm_21j_gp"><span class="figcap"><span class="fig--title-label">Figure 1. </span>Java Project</span> <img class="image" id="c_JAAWbSrvcsClntExAdv__image_bgy_21j_gp" src="../image/JavaProject.png" alt="" /> </div> </div> </li></ul> </li></ul> </div> </div> <div class="section"><h2 class="title sectiontitle">Generate your Axis2 client code</h2> <ul class="ul" id="c_JAAWbSrvcsClntExAdv__ul_z3y_h1j_gp"><li class="li">From a command line in the bin directory of the axis folder:<pre class="pre codeblock"><code>./wsdl2java.sh -uri https://<instance name>.service-now.com/incident.do?WSDL -o /glide/workspace/TestWebService/ </code></pre></li><li class="li">In the above example:<ul class="ul" id="c_JAAWbSrvcsClntExAdv__ul_izj_k1j_gp"><li class="li">The "-uri" is either the path where you have saved a copy of the wsdl to either ".wsdl" or ".xml", or the URL the WSDL resides at.</li><li class="li">The "-o" is the path where you want the files to be written out to. If not specified, the files will be written out to the current bin location.</li></ul> </li><li class="li">In Eclipse refresh the project and the generated Stub and CallbackHandler should now be displayed<div class="fig fignone" id="c_JAAWbSrvcsClntExAdv__fig_pqm_m1j_gp"><span class="figcap"><span class="fig--title-label">Figure 2. </span>Axis Stub</span> <img class="image" id="c_JAAWbSrvcsClntExAdv__image_zrj_n1j_gp" src="../image/AxisStub.png" alt="" /> </div> </li></ul> </div> <div class="section"><h2 class="title sectiontitle">Basic Authentication</h2> <pre class="pre codeblock"><code>HttpTransportProperties.Authenticator basicAuthentication = new HttpTransportProperties. Authenticator ( ) ; basicAuthentication. setUsername ( "admin" ) ; basicAuthentication. setPassword ( "admin" ) ; ... ServiceNowStub proxy = new ServiceNowStub ( ) ; ... proxy._getServiceClient ( ). getOptions ( ). setProperty (org. apache. axis2. transport. http. HTTPConstants. AUTHENTICATE, basicAuthentication ) ;</code></pre> </div> <div class="section"><h2 class="title sectiontitle">Compatibility with Axis2 Versions 1.1 and higher</h2> <div class="p">Chunking support is only available in HTTP Version 1.1. By default chunking is enabled in Axis2.xml for versions 1.1 and higher. <span class="ph">ServiceNow</span> does not support Chunking, so you will need to disable chunking at deployment time or at runtime.<ul class="ul" id="c_JAAWbSrvcsClntExAdv__ul_rcz_t1j_gp"><li class="li">Deployment time: One can disable HTTP chunking by removing or commenting out the following element from Axis2.xml<pre class="pre codeblock"><code><parameter name= "Transfer-Encoding" >chunked</parameter></code></pre></li><li class="li">Runtime: User can disable the chunking using following property set in Client or Stub, versions 1.1.1 and higher only<pre class="pre codeblock"><code>options.setProperty (org. apache. axis2. transport. http. HTTPConstants. CHUNKED, Boolean. FALSE ) ;</code></pre></li></ul> </div> </div> <div class="section"><h2 class="title sectiontitle">Creating Unique Packages</h2> <div class="p">You can use the Axis2 parameter namespace2package (ns2p) to create unique package names. The parameter uses this format:<pre class="pre codeblock"><code><Axis path>\bin\wsdl2java.bat -u -p cr2 -ns2p <namespace>=<package name> -uri <wsdl to convert></code></pre></div> <div class="p">For example:<pre class="pre codeblock"><code><Axis path>\bin\wsdl2java.bat -u -p cr2 -ns2p http://www.service-now.com/change_request=my.change_request -uri change_request</code></pre></div> </div> </div> <div class="related-links"> <div class="familylinks"> <div class="parentlink"><strong>Parent Topic:</strong> <a class="link" href="../../../integrate/examples/concept/c_JAAWbSrvcsClntEx.html" title="Examples demonstrating an integration with Axis2 Version 1.4.">Java Apache Axis2 web services client examples</a></div> </div> </div></body></html></div>