Showing posts with label Web Service. Show all posts
Showing posts with label Web Service. Show all posts

Wednesday, September 12, 2012

Create JAVA Web Service using Axis2

[i] Environment Setup :

         1. JDK
         2. Eclipse
         3. Apache Tomcat
         4. Axis2

   Step 1 : Install JDK and Eclipse and setup Java Environment 
                 in Eclipse.
   Step 2 : Add Apache Tomcat  as Follows,
                 Window > Preferences > Serever > Runtime Environments > Add

   Step 3 :  Add  Axis2 as Follows,
                  Window >> Preferences >> Web Services >> Axis2 Preferences    

    Step 4 :  Set Server and Run-time



[ii] Web Service Project Creation :    

    Step 1 : Create Dynamic Web Project 

    Step 2 : Click on Modify button in Configuration section in above
                   window and tick Axis2 web service and ok.



[iii] Web Service Class :          

           Step 1 : Create a Java Class within a package in Java SRC package 
                         in web service project and add following code.  

                           package com.jayan.ws;

                                  public class HelloWorldWS {
                                              public String serviceHello(String name) {
                                                                                    return "Hi !!! " + name;
                                               }
                                   }
        

           Step 2 : Then right click on that class and go to web service
                         and select create web service and on popup window 
                         then  tick  monitor the web service as follows,

           Step 3 : Then go though that window using next button and ok 
                         and finally  run the project using Run on Server and 
                         then get your web service as follows,
      
           Step 4 : Then click on services and that will display your available 
                         services


-- -- > That's all folks.... Again meet you with a web service client.                         

                        
                                                 

                               
                                         

Thursday, July 21, 2011

Creating a Jira Soap Client

Mainly there are two ways of remote accessing for JIRA instance either using SOAP or XML-RPC.But easy way is to use SOAP Api.Because Atlassian Pages supply a SOAP Interface to work with more operations on remote accessing.

So following are the steps for creating Jira Soap client.

step 1 :
To work with Soap client, First you have to enable JAVA and MAVEN2 on linux environment.For that open ~/.bashrc file in your home directory and set the following variables.

export JAVA_HOME=path to Java dir
export M2_HOME=path to Maven2 dir
export PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin

step 2 :
Then open a terminal and go to your project home directory.Then use following command to retrieve svn checkout from demo soap client distribution.

$ svn co http://svn.atlassian.com/svn/public/atlassian/rpc-jira-plugin/tags/atlassian_jira_4_1_1_1/jira-soapclient/

step 3 :
After that you must change the pom.xml of jira-soapclient project as follows,

<properties>
          <jira.soapclient.jiraurl>your_jira_url</jira.soapclient.jiraurl>
</properties>

Then add following repositories to pom.xml file.

<repositories>
      <repository>
         <id>atlassian</id>
         <name>Atlassian Repository</name>
         <url>https://maven.atlassian.com/content/groups/public</url>
      </repository>
    </repositories>


  <pluginRepositories>
       <pluginRepository>
                <id>atlassian</id>
                <name>Atlassian Repository</name>
                <url>https://maven.atlassian.com/content/groups/public</url>
       </pluginRepository>
   </pluginRepositories>



step 4 :
Then download the .WSDL file relevant to your jira instance to your project /src/main/wsdl directory using following command.

mvn -Pfetch-wsdl -Djira.soapclient.jiraurl=http://{your_jira_instance}/

step 5 :
After downloading .wsdl file, now generate/download all the dependencies(.jar s) and other needed classes for Soap client.run following,

mvn -Pbuildclient

step 6 :
Then create your jira-soapclient project as a Eclipse project or Idea project.use following,

mvn eclipse:eclipse        or     mvn idea:idea

and then using File -> import -> Existing project to workspace, import your project to Eclipse IDE.

step 7 :
Let's code the Jira Soap Client.
For that create your class in com.atlassian.jira_soapclient package and then try with following codes.

 //setting base URL
                String baseUrl="<your_jira_url>/rpc/soap/jirasoapservice-v2";

// get  handle to the JIRA SOAP Service from a client point of view
                SOAPSession soapSession = new SOAPSession(new URL(baseUrl));

//Connect to jira
                soapSession.connect(LOGIN_NAME, LOGIN_PASSWORD);

//JIRA SOAP Service, authentication token are used to make authentication calls
                JiraSoapService jiraSoapService = soapSession.getJiraSoapService();

                String authToken = soapSession.getAuthenticationToken();

step 8 :               
After getting authentication to the Jira system, then test the connection with retrieving all the project names under your jira system using following code samples. 

   List<String> names = new ArrayList<String>();

   RemoteProject[] Projects = jiraSoapService.getProjectsNoSchemes(authToken);

            for (RemoteProject project : Projects) {

                names.add(project.getKey());

            }
           
            System.out.print(names);

Then build project and check whether the code samples are working.If not don't forget to make a comment.Now you can also extend this using your functionalities And try to work with different code samples to be with Jira Soap Client practice.

So I think, this doc will become a nice tutorial for who are using JIRA SOAP CLIENT first time.