(2.08)
- Open up ANT build.xml file
to
and mac users should select the second option “2. Ant Build…”
and perform the following action:
- A window pops up a window.
- Go to the second to last tab “Environment” and create a variable AXIS2_HOME and provide the path
- Create another variable JAVA_HOME and provide JAVA_HOME path.
- Refresh the project and under lib you should be able to find “Services-test-client.jar” and “Beans-packaged.jar” files.Sample Asset Upload Program Demo :
- Create a new Java project
- Create a new folder and call it lib
- Copy the the two jar files “Services-test-client.jar” and “Beans-packaged.jar” into the lib folder
- Copy all the other necessary jar files.
go to libraries tab and “Add JARs…”
select only the jar files by filtering by *.jar. Also add jars from the “endorsed” folder too.
In source create a new package, say with the name “edu.uconn.aim”
Create a new java class in “edu.uconn.aim” package and make it the main class.
Coding
——–
Main class will be used to call methods. We create classes to implement the logics. Lets create another class called “AssetUpload” class.
Create a class called ‘AssestUpload’.
This class demonstrates how to call web services from java.
First, we set up authentication stuffs. The function ‘templateAssest’ implements authentication with in a try catch block. Please follow the steps below :
- Create object to authenticator class ‘HttpTransportProperties.Authenticator’.
- Set username and password for account.
- Create ‘TemplateAeAAssestEServiceStub’ class object and import the dependency for the class if required.
- Pass the web service end point as a parameter to the ‘TemplateAeAAssestEServiceStub’ object.
- To access the options in the service stub create object of class ‘Options’. This object holds the options that service offers
- Call ‘option.setProperty’ to set the properties to basic authentication and use the username and password.
- Set up ‘TemplateAeAAssetDocument’ object using ‘TemplateAeAAssetEDocument.Factory.newInstance()’.
- Set up authentication.
- Change the function signature to return ‘AeAAssetEDocument’ object and return the object.
- Call ‘templateAsset’ method from ‘WebServiceSample.java’ and print out the object returned by ‘templateAsset’
- Change the return type ‘AeAAssetEType’ and return ‘serviceStub.templateAeAAssetE(doc).getAeAAssetE()’ to return a message without soap envelope.
- Create a method ‘saveAsset’ to insert an asset. First tag in wsdl file is ‘insertAeAAssetE’. Since ‘insertAeAAssetE’ tag is not in the java code, we need to add this tag using ‘doc.addNewInsertAeAAssetE()’. The rest of SOAP body is the asset which is passed as a parameter to the current function. We set the asset using ‘doc.addNewInsertAeAAssetE().setAeAAssetE(asset)’