This post illustrates, how to create Java stub using Exchange Web services. Generally stub creation is an easy process since it is available in most of the IDE (Integrated development environment) and you need to use some clicks on IDE and you will get stub (Java source files) available in IDE.
As of My experience which I have had with Exchange Web services, it is not an easy approach. I had passed around 14 working days to get right Java stub. Here, I am sharing my experience and trying to cover all points which are required for preparing Java stub.
Services.wsdl- Describes the contract between client and server.
Messages.xsd- Defines the request and response SOAP messages.
Types.xsd- Defines the elements that are used in the SOAP messages.
Use the URLs below for downloading these files,
Examples are,
Download files from above links and save it by names. The names are,
<wsdl:service name="ExchangeServices">
<wsdl:port name="ExchangeServicePort" binding="tns:ExchangeServiceBinding">
<soap:address location="https://<Exchange server host>/EWS/Exchange.asmx"/>
</wsdl:port>
</wsdl:service>
In these lines, you can change following attribute according to your requirement. These are,
In types.xsd file, you need to change the definition of element which is used for updating the Exchange server's item. You need to change 'Path' definition to 'FieldURI'. This changes are recommendation by MSDN in which we should pass FieldURI instead of Path in update process.
As of My experience which I have had with Exchange Web services, it is not an easy approach. I had passed around 14 working days to get right Java stub. Here, I am sharing my experience and trying to cover all points which are required for preparing Java stub.
Required software for creating Java Stub
- Eclipse Java EE IDE 1.2.0 (Galileo)
- JDK 1.6
- Axis2 eclipse code generation plugin
Configuring Axis2 tool for Eclipse
- Download ZIP file named 'axis2-eclipse-codegen-plugin-1.5.4.zip', unzip it and copy the JAR file (inside UNZIP folder) named 'org.apache.axis2.eclipse.codegen.plugin_1.5.4.jar’ inside ‘plugins’ folder of Eclipse.
- Restart Eclipse IDE.
Download Exchange 2007 Web-services
Exchange server provides three XML files which are required for preparing client stub. These files are,Services.wsdl- Describes the contract between client and server.
Messages.xsd- Defines the request and response SOAP messages.
Types.xsd- Defines the elements that are used in the SOAP messages.
Use the URLs below for downloading these files,
- <protocol>://<exchange dns="" fully="" qualified="" server="">:<exchange port="" server="">/EWS/Services.wsdl
- <protocol>://<exchange dns="" fully="" qualified="" server="">:<exchange port="" server="">/EWS/messages.xsd
- <protocol>://<exchange dns="" fully="" qualified="" server="">:<exchange port="" server="">/EWS/types.xsd
Examples are,
- https://<Exchange server host>/EWS/Services.wsdl
- https://<Exchange server host>/EWS/messages.xsd
- https://<Exchange server host>/EWS/types.xsd
Download files from above links and save it by names. The names are,
- services.wsdl
- messages.xsd
- types.xsd
Changes needed in Services.wsdl and types.xsd file
Add the below lines of code in Services.wsdl file just above the last line i.e. <wsdl:service name="ExchangeServices">
<wsdl:port name="ExchangeServicePort" binding="tns:ExchangeServiceBinding">
<soap:address location="https://<Exchange server host>/EWS/Exchange.asmx"/>
</wsdl:port>
</wsdl:service>
In these lines, you can change following attribute according to your requirement. These are,
- wsdl service name.
- wsdl port name.
- soap location: Represents Exchange.asmx location of Exchange server.
In types.xsd file, you need to change the definition of element which is used for updating the Exchange server's item. You need to change 'Path' definition to 'FieldURI'. This changes are recommendation by MSDN in which we should pass FieldURI instead of Path in update process.
Steps used with Eclipse
- Start Eclipse and create a Java project.
- Create a ‘wsdl’ folder inside project and copy the Web-services files which you have downloaded in previous point.
- Create a ‘lib’ folder inside project and copy following JARS.
- axiom-api-1.2.10.jar
- axiom-dom-1.2.10.jar
- axiom-impl-1.2.10.jar
- axis2-adb-1.5.4.jar
- axis2-adb-codegen-1.5.4.jar
- axis2-codegen-1.5.4.jar
- axis2-java2wsdl-1.5.4.jar
- axis2-jibx-1.5.4.jar
- axis2-kernel-1.5.4.jar
- axis2-transport-http-1.5.4.jar
- axis2-transport-local-1.5.4.jar
- axis2-xmlbeans-1.5.4.jar
- bcel-5.1.jar
- commandline.jar
- commons-codec-1.3.jar
- commons-fileupload-1.2.jar
- commons-httpclient-3.1.jar
- commons-logging-1.1.jar
- geronimo-jta_1.1_spec-1.1.jar
- geronimo-ws-metadata_2.0_spec-1.1.2.jar
- httpcore-4.0.jar
- javax.mail-1.3.3.01.jar
- jaxen-1.1.1.jar
- jibx-bind-1.2.1.jar
- jibx-run-1.2.1.jar
- log4j-1.2.14.jar
- mail.jar
- neethi-2.0.4.jar
- regexp-1.2.jar
- servlet-api-2.3.jar
- woden-api-1.0M8.jar
- woden-impl-dom-1.0M8.jar
- wsdl4j-1.6.2.jar
- xalan-2.7.0.jar
- xercesImpl-2.8.1.jar
- xmlbeans-2.3.0.jar
- XmlSchema-1.4.3.jar
- Project directory structure is shown below.
- Right click on project and click File -> New -> Other -> Axis2 Wizards -> Axis2 Code Generator.
- Locate ‘Services.wsdl ‘ file and click ‘Next’ button.
- Fill the options page in Axis2 Codgen Wizard as Figure below. Select the options carefully mentioned as figure below,
- Set the output location of code which is generated by Axis2 tool. Select the options carefully mentioned as figure below.
- Finally, you will receive below message if everything is fine.
There are some nice links which I have used for Java stub creation.
- Axis2_Codegen_Wizard_1.4.0 : Solution for issue of stub creation.
- Axis2 code generation : Code Generator Wizard Guide for Eclipse Plug-in
- Axis2 Stub creation error : org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized.