Tuesday, September 8, 2009

Web-Service

Web Services

What is Web Service? – It’s an solution for cross platform Data exchange leveraging power of SOAP to achieve easy interoperability.

Download presentation for basic fundamentals, examples & execution flow from below location.

http://sites.google.com/site/abhishekgondalia/Home/WebServicesin30mins.ppt?attredirects=0

Web Services has tremendous industry acceptance and hence there are high end tools available for effective development. We use Apache Axis 1.4

How to publish:

  • 1. It starts with web.xml, add axis servlet and namespace url mapping (if it doesn’t exists).
  • 2. Update server-config.wsdd file (located under same parent as web.xml), add your service specific configurations
    • a. Service configuration
    • b. Operation’s configuration (if any)
    • c. Type mappings (add exchanged Class’s configurations in request & response)
  • 3. access server url (server_url/services/MyService?wsdl)
  • 4. Update wsdl file if arrays are used
  • 5. update service configuration and add updated wsdl file (placed in local workspace)
  • 6. Service class should follow naming conventions given in presentation

How to consume WS:

  • 1. Get wsdl file or wsdl file url from publisher
  • 2. Run WSDL2Java tool which will generate client stubs

Sample WSDL Command: java -classpath .; org.apache.axis.wsdl.WSDL2Java -p com.csam.google -o .\Client_Stubs -t http://api.google.com/GoogleSearch.wsdl NOTE: "-t" option will create default TestCase for the service.

Security Aspect

  • Checklist:
    • 1. Rename AxisServlet & namespace (update web.xml)
    • 2. Stop Service Listing (set global configuration "axis.enableListQuery" as "false")
    • 3. Switch Axis to Deployment mode (set global configuration "axis.development.system" as "false")
    • 4. Stop providing autogenerated wsdl (set <wsdlFile></wsdlFile> in each service configuration )
    • 5. Remove all unnecessary Servlets of Axis from production system (default Axis configuration contains Servlet for Admin Monitoring & others. make sure only AxisServlet is there in web.xml)

Also refer http://ws.apache.org/axis/java/security.html

Monitoring SOAP Packets MyEclipse provides 'TCP/IP Monitor' - One can use this as proxy and can view exact data getting exchanged. This is not specific to SOAP, any activity can be applied by this proxy and can be monitored.

How to work with Arrays in AxisIts kind of work around that we have taken to deal with arrays in Axis, As of now there is no other way identified for the same.

<theatre>
       <movies>
     <movie>
            <name>Hero</name>
            <description>The story</description>
     </movie>   
     <movie>
           <name>Heroin</name>
           <description>Same story</description>
     </movie>
   <movies>
</theatre>

Class Structure

class Theatre {
       Movies movies;
}
class Movies {
       Movie[] movie;
}
class Movie {
       String name;
      String description;
}

Default WSDL Generated by AXIS:

<complexType name="Movies">
    <sequence>
        <element name="name" nillable="true" type="xsd:string"/>
        <element name="description" nillable="true" type="xsd:string"/>
    </sequence>
</complexType>
<complexType name="Movies">
    <sequence>
        <element name="movie" nillable="true" type="impl:ArrayOf_tns1_Movie"/>
    </sequence>
</complexType>

 

<complexType name="ArrayOf_tns1_Movie">
    <sequence>
        <element maxOccurs="unbounded" minOccurs="0" name="movie" type="tns1:Movie"/>
    </sequence>
</complexType>

 

<complexType name="ArrayOf_tns1_Movie">

    <sequence>
<element maxOccurs="unbounded" minOccurs="0" name="movie" type="tns1:Movie"/>
</sequence>
</complexType>


Update as:



Update as:



   <complexType name="Movies">

    <sequence>


     <element name="name" nillable="true" type="xsd:string"/>


     <element name="description" nillable="true" type="xsd:string"/>


    </sequence>


   </complexType>



<complexType name="Movies"> <sequence> <element maxOccurs="unbounded" minOccurs="0" name="movie" type="tns1:Movie"/> </sequence> </complexType>



References:



1 comment:

Bhavin said...

Really appreciating your work.. Abhi.. All The Best!!