JAX WS WebService AXIS - Yash-777/Axis1x_Soap GitHub Wiki

WSDL2Java: Building stubs, skeletons, and data types from WSDl

Online WSDL: http://sofa.uqam.ca/soda/webservices.php

Soap UI test for calculator wsdl

Online Soap client GUI:

This is a simple webservice testing tool that allows you to debug WSDL files - view the list of functions, see what XML needs to be sent to each one, customize it, get the response, etc.


JAXB hello world example

package com.mkyong.yash.ws;
import javax.jws.*;
 
//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld{
    @WebMethod String getHelloWorldAsString(String name);
    @WebMethod String getSampleText();
}

@WebService(endpointInterface = "com.mkyong.yash.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
    @Override
    public String getHelloWorldAsString(String name) {
        return "Hello World JAX-WS " + name;
    }
    @Override
    public String getSampleText() {
        return "Hello World JAX-WS  YYYY";
    }
}

Standalone app to run Web-Server without Server:

//Endpoint publisher
public class HelloWorldPublisher{
    public static void main(String[] args) {
        Endpoint.publish("http://localhost:9999/ws/hello", new HelloWorldImpl());
    }
}

Consume End-Point Service with out Service Classes:

// PRODUCER Check without Client: With out Service Classes, Which generated by wsImport
URL WSDL_LOCATION = new URL("http://localhost:9999/ws/hello?wsdl");
QName qname = new QName("http://ws.yash.mkyong.com/", "HelloWorldImplService"); // nameSpace, ServiceClass

Service service = Service.create(WSDL_LOCATION, qname);

HelloWorld hello = service.getPort(HelloWorld.class); // Operations Listed Interface Name

System.out.println("Result : "+ hello.getHelloWorldAsString("777"));

Consume End-Point Service with Service Classes: http://www.soapclient.com/interop/rpcEnc.wsdl

// wsimport -XdisableSSLHostnameVerification -keep http://localhost:9999/ws/hello?wsdl
// JAX-WS RI 2.1.1 in JDK 6, Generated source version: 2.1
HelloWorldImplService helloService = new HelloWorldImplService();
HelloWorld hello = helloService.getHelloWorldImplPort();

System.out.println(hello.getHelloWorldAsString("mkyong"));
System.out.println(hello.getSampleText());

// java -cp C:/Yash/axis-1_4/lib/* org.apache.axis.wsdl.WSDL2Java http://localhost:9999/ws/hello?wsdl
java.net.URL endpointURL = new java.net.URL("http://localhost:9999/ws/hello");
javax.xml.rpc.Service service = new org.apache.axis.client.Service();
((org.apache.axis.client.Service) service).setTypeMappingVersion("1.1");
HelloWorldImplPortBindingStub obj_axis = new HelloWorldImplPortBindingStub(endpointURL, service);
String text = obj_axis.getSampleText();
System.out.println("Response: "+ text);

// WSDL2Java -uri http://localhost:9999/ws/hello?wsdl
HelloWorldImplServiceStub obj_axis2 = new HelloWorldImplServiceStub();
GetSampleTextResponse sampleText = obj_axis2.getSampleText(new GetSampleText());
System.out.println("Response: "+ sampleText.get_return());

Axis User-gide

$ set CLASSPATH=C:\Yash\WebServices\axis-1_4\lib
$ 1. java org.apache.axis.wsdl.WSDL2Java http://localhost:9999/ws/hello?wsdl
$ 2. java org.apache.axis.wsdl.WSDL2Java D:/Yash/HellowWorld.xml

Second loacalPath.wsdl is used when we get java.net.ConnectException for the WSDL URL.

$ java -cp C:/Yash/WebServices/axis-1_4/lib/* org.apache.axis.wsdl.WSDL2Java http://localhost:9999/ws/hello?wsdl
$ java -cp C:/Yash/WebServices/axis-1_4/lib/* org.apache.axis.wsdl.WSDL2Java http://www.dneonline.com/calculator.asmx
	java.net.ConnectException: Connection timed out: connect

$ java -cp C:/Yash/WebServices/axis-1_4/lib/* org.apache.axis.wsdl.WSDL2Java Calulator.xml
  • Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled. Adding javax.mail-api-1.6.0.jar to class-path is sufficent to solve the issue

Direct download page axis 1.4zip


Axis2 User-gide

$ AXIS2_HOME = C:\Yash\WebServices\axis2-1.7.9, Path = %AXIS2_HOME%\bin
$ WSDL2Java -uri http://localhost:9999/ws/hello?wsdl
$ WSDL2Java -uri D:/Yash/HellowWorld.xml

set path=%path%;C:\Yash\WebServices\axis2-1.7.9\bin; -- No spaces in between path=path.

Download and unpack the Axis2 Standard Binary Distribution into a convenient location so that the distribution resides in its own directory. Set an environment variable AXIS2_HOME to the pathname of the extracted directory of Axis2 (Eg: /opt/axis2-1.7.9). Direct download page axis2


Pom dependencies:

// Axis 1.4
dependency: javax.xml.soap:saaj-api:1.3.4
dependency: javax.xml:jaxrpc-api:1.1
dependency: org.apache.axis:axis:1.4
dependency: wsdl4j:wsdl4j:1.6.2
dependency: xalan:xalan:2.7.1
dependency: xerces:xercesImpl:2.11.0
dependency: net.sf.saxon:Saxon-HE:9.7.0-15
// NoClassDefFoundError: org/apache/commons/discovery/tools/DiscoverSingleton
dependency: commons-discovery:commons-discovery:0.5

// AXIS 2
dependency: org.apache.axis2:axis2:1.6.2
// ClassNotFoundException: org.apache.axis2.transport.local.LocalTransportSender
dependency: org.apache.ws.commons.axiom:axiom-api:1.2.22
// java.lang.ClassNotFoundException: org.apache.axis2.transport.http.CommonsHTTPTransportSender
dependency: org.apache.axis2:axis2-transport-local:1.7.9
// java.lang.ClassNotFoundException: javax.mail.internet.ParseException
dependency: javax.mail:javax.mail-api:1.6.0

RPC Axis Server code

<!-- APP - server-config.wsdd
         - web.xml -->
<ns1:deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java" xmlns:ns1="http://xml.apache.org/axis/wsdd/">
<ns1:globalConfiguration>
    <ns1:parameter name="sendMultiRefs"                     value="true"/>
    <ns1:parameter name="disablePrettyXML"                  value="true"/>
    <ns1:parameter name="adminPassword"                     value="admin"/>
    <ns1:parameter name="dotNetSoapEncFix"                  value="true"/>
    <ns1:parameter name="enableNamespacePrefixOptimization" value="false"/>
    <ns1:parameter name="sendXMLDeclaration"                value="true"/>
    <ns1:parameter name="attachments.implementation"        value="org.apache.axis.attachments.AttachmentsImpl"/>
    <ns1:parameter name="sendXsiTypes"                      value="true"/>
    <ns1:requestFlow>
     <ns1:handler type="java:org.apache.axis.handlers.JWSHandler">
        <ns1:parameter name="scope" value="session"/>
     </ns1:handler>
     <ns1:handler type="java:org.apache.axis.handlers.JWSHandler">
        <ns1:parameter name="scope" value="request"/>
        <ns1:parameter name="extension" value=".jwr"/>
     </ns1:handler>
    </ns1:requestFlow>
</ns1:globalConfiguration>

<ns1:handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>
<ns1:handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>
<ns1:handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>
<ns1:service name="HelloWorldImpl" provider="java:RPC" style="wrapped" use="literal">
    <ns2:operation name="getHelloWorldAsString" qname="ns1:String" xmlns:ns1="http://ws.yash.mkyong.com/"
        xmlns:ns2="http://xml.apache.org/axis/wsdd/" soapAction="">
        <ns2:parameter qname="ns1:arg0" type="ns1:string"/>
    </ns2:operation>
    <ns2:operation name="getSampleText" qname="ns1:string" xmlns:ns1="http://ws.yash.mkyong.com/"
        xmlns:ns2="http://xml.apache.org/axis/wsdd/" soapAction="">
    </ns2:operation>
    
        <ns1:parameter name="className" value="com.mkyong.ws.HelloWorldImpl"/>
            <ns1:parameter name="allowedMethods" value="getHelloWorldAsString, getSampleText"/>
            
        <ns1:parameter name="wsdlServiceElement" value="HelloWorldImpl_Service"/>
        <ns1:parameter name="wsdlServicePort" value="HelloWorldImpl_Port"/>
        <ns1:parameter name="wsdlPortType" value="HelloWorldImpl_PortBinding"/>
        <ns1:parameter name="schemaQualified" value="http://ws.yash.mkyong.com/"/>
        <ns1:parameter name="wsdlTargetNamespace" value="http://ws.yash.mkyong.com/"/>
        
        <ns1:parameter name="typeMappingVersion" value="1.2"/>

    <!-- Pojo Class Mapping 
    <ns2:operation name="functionPojo" qname="ns1:functionPojo" xmlns:ns1="http://ws.yash.mkyong.com/"
        xmlns:ns2="http://xml.apache.org/axis/wsdd/" soapAction="">
        <ns2:parameter qname="ns1:arg0" type="ns1:MyPojo"/>
    </ns2:operation>
    
    <ns1:typeMapping type="java:com.mkyong.ws.MyPojo" qname="ns2:MyPojo"
        xmlns:ns2="http://ws.yash.mkyong.com/" 
        deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory" encodingStyle="" 
        serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
         />
    -->
</ns1:service>
<ns1:service name="AdminService" provider="java:MSG">
    <ns1:parameter name="allowedMethods" value="AdminService"/>
    <ns1:parameter name="enableRemoteAdmin" value="false"/>
    <ns1:parameter name="className" value="org.apache.axis.utils.Admin"/>
    <ns1:namespace>http://xml.apache.org/axis/wsdd/</ns1:namespace>
</ns1:service>
<ns1:service name="Version" provider="java:RPC">
    <ns1:parameter name="allowedMethods" value="getVersion"/>
    <ns1:parameter name="className" value="org.apache.axis.Version"/>
</ns1:service>
<ns1:transport name="http">
    <ns1:requestFlow>
      <ns1:handler type="URLMapper"/>
      <ns1:handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
    </ns1:requestFlow>
    <ns1:parameter name="qs:list"   value="org.apache.axis.transport.http.QSListHandler"/>
    <ns1:parameter name="qs:wsdl"   value="org.apache.axis.transport.http.QSWSDLHandler"/>
    <ns1:parameter name="qs.list"   value="org.apache.axis.transport.http.QSListHandler"/>
    <ns1:parameter name="qs.method" value="org.apache.axis.transport.http.QSMethodHandler"/>
    <ns1:parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler"/>
    <ns1:parameter name="qs.wsdl"   value="org.apache.axis.transport.http.QSWSDLHandler"/>
</ns1:transport>
<ns1:transport name="local">
    <ns1:responseFlow>
      <ns1:handler type="LocalResponder"/>
    </ns1:responseFlow>
</ns1:transport>
</ns1:deployment>

Server levelSecurity:

In web.xml we can use the following tags to provide the security to the specific resource:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

  <servlet> <display-name>Apache-Axis Servlet</display-name>
    <servlet-name>AxisServlet</servlet-name>
    <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
  </servlet>
    <servlet-mapping> <servlet-name>AxisServlet</servlet-name>
      <url-pattern>/servlet/AxisServlet</url-pattern>
    </servlet-mapping>
    <servlet-mapping> <servlet-name>AxisServlet</servlet-name>
      <url-pattern>*.jws</url-pattern>
    </servlet-mapping>
    <servlet-mapping> <servlet-name>AxisServlet</servlet-name>
      <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
  
  <servlet>
    <display-name>Axis Admin Servlet</display-name>
    <servlet-name>AdminServlet</servlet-name>
    <servlet-class>org.apache.axis.transport.http.AdminServlet</servlet-class>
    <load-on-startup>100</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>AdminServlet</servlet-name>
    <url-pattern>/servlet/AdminServlet</url-pattern>
  </servlet-mapping>
  
  <!-- DB Authentication -->
  <resource-ref>
    <description>Neon Oracle Datasource</description>
    <res-ref-name>jdbc/neonoracle</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Entire Application</web-resource-name>
      <url-pattern>/services/*</url-pattern>
    </web-resource-collection>
    <auth-constraint> <!-- This role is not in the default user directory -->
      <role-name>web-service-user</role-name>
     </auth-constraint>
  </security-constraint>    
  <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Axis Basic Authentication Area</realm-name>
  </login-config>
  <security-role> <description>The web-service-user has full access to all web services</description>
    <role-name>web-service-user</role-name>
  </security-role>
</web-app>
⚠️ **GitHub.com Fallback** ⚠️