Openfire act as a client for SynchronaWS. In the previous blog post i have explained how a client can be written using SAAJ client implementation method. when we dig more in to the details on client implementation we found that there are technologicaly more advance client side implemenations availale for webservices, those are JAXM and client implementation using AXIS2. i have explained the steps for implementing client using axis2 for Synchrona webservice.
create a dynamic webproject called SynchronaWebService
File - > new -> Other -> select web -> select dynamic webproject.
crealte packe stucture com.synchrona.communication and four classes Communication.java , Synchrona.java , Twitter.java and Bloger.java as in the following image.
(--
for creating dynamic webproject follow the following tutorial
http://24bytes.com/helloworlds/WebService/hellowebservice.html
--)
Make sure to use apache tomcat 6.0 and axis2 1.4 for tutorial Make sure to set Dynamic web module version to 2.4 Make sure to click on default configuration and select axis2 from the pop up window and apply the settings in the process of crating dynamic web project
Now you have created dynamic webproject !!!
----------------------------------------------------------------------------------------------------------------------------------------
next step is to convert it in to webservice.
File -> new -> other -> select webservices -> select webservice and clieck OK
in the pop up window set the following configuration details.
set the service implementation :- com.synchrona.communicaton.Communication check whether server is tomcat :- 6.0 check whether axis :- 1.4 check whether serviceProject - SynchronaWebService click on webservice runtime and select the option :- start axis before tomcat server
click next -> next -> ...
you will find a button to start server click on it and click finish.
Right Click on SynchronaWebService -> select run -> select run on server
Now You Have Created SynchronaWS !!!
you will get following out put on eclipse browser window
Click on Communication , you will get the wsdl file generated for your webservice.
http://localhost:8080/SynchronaWebService/services/Communication?wsdl
you will need if for creating client stubs.
----------------------------------------------------------------------------------------------------------------------------------------
Creating Stubs for SynchronaWS
start terminal
if you haven't set the $JAVA_HOME
type following command in the terminal
$export $JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.16
if you haven't set the $AXIS_HOME
type following command in the terminal
$export $AXIS_HOME=/home/kapila/Desktop/axis2-1.4.1
now follow the following steps to create client stubs
sh $AXIS2_HOME/bin/wsdl2java.sh -uri http://localhost:8080/SynchronaWebService/services/Communication?wsdl
-o SynchronaClient -u
kapila@kapila-laptop:~$ sh $AXIS2_HOME/bin/wsdl2java.sh -urigo to home folder and find the generated stub in SynchronaClient folder.
http://localhost:8080/SynchronaWebService/services/Communication?wsdl
-o SynchronaClient -u
Using AXIS2_HOME: /home/kapila/Desktop/axis2-1.4.1
Using JAVA_HOME: /usr/lib/jvm/java-6-sun-1.6.0.16
Retrieving document at 'http://localhost:8080/SynchronaWebService/services/Communication?wsdl'.
kapila@kapila-laptop:~$
Stub will be saved to a folder called SynchronaClient
before importing generated stubs in to openfire test it on simple java applicatoin as follows.
File -> new -> Other -> JavaPrject
name the project as SynchronaClientTester
copy the src folder in the stubs generated folder to the SynchronaClientTester folder.
Refresh the SynchronaClientTester project
you should get following output
right click on the SynchronaClientTester Package and add new class called Tester.java
YOU WILL GET BUNCH OF ERRORS
right click on SynchronaClientTester and select properties and select buildpath and select libraries tab and click on add external jars. add libraries which are there in AXIS2 lib folder in to SynchronaClientTester.
if you still get the errors , go to Project -> Clean -> select SynchronaClientTester and click clean
now put following code in to the class (just copy paste)
public static void main(String arg[]) {
try {
CommunicationStub sample1ServiceStub = new CommunicationStub();
sample1ServiceStub
._getServiceClient()
.getOptions()
.setProperty(Constants.Configuration.TRANSPORT_URL,
"http://localhost:8080/SynchronaWebService/services/Communication");
sample1ServiceStub._getServiceClient().getOptions().setProperty(
HTTPConstants.CHUNKED, Constants.VALUE_FALSE);
SynchronizeData syncData = new SynchronizeData();
syncData.setUpdate("Synchrona Test with new webservice");
SynchronizeDataResponse response = sample1ServiceStub
.synchronizeData(syncData);
System.out.println("Got param ==> " + response.get_return());
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
} catch (java.rmi.RemoteException e) {
e.printStackTrace();
}
}
Tester class should look like follows
Run it and see the output
you will get following output on eclipse console , YOU HAVE DONE THE HARD PART !!!
WARN No appenders could be found for logger (org.apache.axis2.description.AxisService).
log4j:WARN Please initialize the log4j system properly.
Got param ==> Synchrona Test with new webservice
right click on motd package and select refactor and copy the package stuructur
org.jivesoftware.openfire.plugin
go back to SynchronClientTester and click on package and select refactor and paste the org.jivesoftware.openfire.plugin there. now SynchronaClientTester will get package structre similar to motd in openfire.
Copy copy and paste following classes in to motd package. YES DO IT
YOU WILL AGAIN GET BUNCH OF ERRORS!!!
now go to motd implementation folder and creae lib foder there
add all the libraries in axis2/lib folder in to that folder.
right click on project openfire -> select properties -> select build path -> select libraries -> click on add external jars -> all all the libraires that you put in to motd lib folder
affter this is done copy the code in inside Tester class in to MotdPlugin.java 's packetIntercepter method.
NOW EVERY THIS IS DONE!!!
you shoudl get a window as follows
Run -> External Tools -> motd
this will create motd jar in the following works folder of openfire project.
upload that jar to openfire server and enjoy!!!!
Comments (0)
Post a Comment