PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/content/server/jira/platform/creating-an-xml-rpc-client-4227133.md

https://bitbucket.org/mrzymski/jira-server-docs
Markdown | 215 lines | 156 code | 59 blank | 0 comment | 0 complexity | 3f5a573f88960698b9a2a08c647013e8 MD5 | raw file
  1. ---
  2. title: Creating an Xml Rpc Client 4227133
  3. aliases:
  4. - /server/jira/platform/creating-an-xml-rpc-client-4227133.html
  5. dac_edit_link: https://developer.atlassian.com/pages/editpage.action?cjm=wozere&pageId=4227133
  6. dac_view_link: https://developer.atlassian.com/pages/viewpage.action?cjm=wozere&pageId=4227133
  7. confluence_id: 4227133
  8. platform:
  9. product:
  10. category:
  11. subcategory:
  12. ---
  13. # JIRA Developer Documentation : Creating an XML-RPC Client
  14. {{% warning %}}
  15. JIRA's SOAP and XML-RPC remote APIs were deprecated in JIRA 6.0.
  16. [Read the announcement for more information.](/server/jira/platform/soap-and-xml-rpc-api-deprecation-notice)
  17. {{% /warning %}}
  18. <table>
  19. <colgroup>
  20. <col style="width: 50%" />
  21. <col style="width: 50%" />
  22. </colgroup>
  23. <tbody>
  24. <tr class="odd">
  25. <td><p>Available:</p></td>
  26. <td><p>JIRA 3.0 and later</p></td>
  27. </tr>
  28. </tbody>
  29. </table>
  30. JIRA ships with the JIRA XML-RPC plugin which enables remote access through XML-RPC and SOAP. Using this feature with XML-RPC is easy with some help from the <a href="http://ws.apache.org/xmlrpc/index.html" class="external-link">Apache XML-RPC</a>package.In this tutorial, we write a basic XML-RPC client (using <a href="http://ws.apache.org/xmlrpc/index.html" class="external-link">Apache XML-RPC</a>) that logs in, retrieves projects and then logs out again. A Python client is also demonstrated.You may also be interested in the [Creating a JIRA SOAP Client](/server/jira/platform/creating-a-jira-soap-client-4227095.html). More methods are exposed via SOAP than XML-RPC.
  31. {{% note %}}
  32. Getting the latest XML-RPC client
  33. You can download the latest XML-RPC client with the Atlassian Plugin SDK - see [Developing with the Atlassian Plugin SDK](https://developer.atlassian.com/display/DOCS/Developing+with+the+Atlassian+Plugin+SDK).
  34. {{% /note %}}
  35. The methods exposed via XML-RPC are listed in the <a href="http://docs.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/com/atlassian/jira/rpc/xmlrpc/XmlRpcService.html" class="external-link">RPC plugin Javadoc for the XmlRpcService class</a>. The [JIRA XML-RPC Overview](/server/jira/platform/jira-xml-rpc-overview-4227112.html) has more information (though not guaranteed to be up to date).
  36. To run the Java client in this tutorial, you'll need to <a href="http://ws.apache.org/xmlrpc/download.html" class="external-link">download the Apache XML-RPC libraries</a> and make them available in your classpath.
  37. ## Enabling the RPC plugin
  38. {{% note %}}
  39. {{% warning %}}
  40. ***This page has been archived, as it does not apply to the latest version of JIRA (Server or Cloud). The functionality described on this page may be unsupported or may not be present in JIRA at all.***
  41. {{% /warning %}}
  42. *JIRA's SOAP and XML-RPC remote APIs were removed in JIRA 7.0 for Server ( [see announcement](https://developer.atlassian.com/display/JIRADEV/SOAP+and+XML-RPC+API+Deprecation+Notice)).
  43. We encourage you to use JIRA's REST APIs to interact with JIRA remotely (see [migration guide](https://developer.atlassian.com/display/JIRADEV/JIRA+SOAP+to+REST+Migration+Guide)).*
  44. {{% /note %}}
  45. To invoke JIRA operations remotely, you should ensure that the RPC plugin is enabled on the JIRA installation you are targeting. If you simply want to create a client to <a href="http://jira.atlassian.com/" class="uri external-link">http://jira.atlassian.com/</a> then you can skip this step. First you need to check if the Accept Remote API Calls has been enabled in '**General Configuration**' under '**Global Settings**' in the left-hand menu:
  46. <img src="/server/jira/platform/images/rpc-remote-calls.png" class="image-center" />
  47. Then you need to enable the JIRA RPC Plugin in '**Plugins**' under '**System**' in the left-hand menu:
  48. <img src="/server/jira/platform/images/plugins-rpcplugin.png" class="image-center" />
  49. ![(warning)](/server/jira/platform/images/icons/emoticons/warning.png) To get the source code of the RPC plugin, see <a href="https://bitbucket.org/atlassian_tutorial/jira-rpc-plugin" class="uri external-link">https://bitbucket.org/atlassian_tutorial/jira-rpc-plugin</a>
  50. Your server should now be ready to accept remote procedure calls.
  51. Now that your server is ready to accept remote procedure calls, we begin creating a Java XML-RPC client.
  52. ## Building a Python XML-RPC client
  53. XML-RPC in Python is very easy. Here is a sample client that creates test issues on <a href="http://jira.atlassian.com" class="uri external-link">http://jira.atlassian.com</a>:
  54. ``` javascript
  55. #!/usr/bin/python
  56. # Sample Python client accessing JIRA via XML-RPC. Methods requiring
  57. # more than basic user-level access are commented out.
  58. #
  59. # Refer to the XML-RPC Javadoc to see what calls are available:
  60. # http://docs.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/com/atlassian/jira/rpc/xmlrpc/XmlRpcService.html
  61. import xmlrpclib
  62. s = xmlrpclib.ServerProxy('http://jira-stage.ironport.com/rpc/xmlrpc')
  63. print "Proxy exited"
  64. auth = s.jira1.login('opsengineer', 'opsengineer')
  65. print "login exited"
  66. newissue = s.jira1.createIssue(auth, { "project": "MONOPS",
  67. "type": 26,
  68. "summary": "Issue Created via XML-RPC",
  69. "description": "Issue created with Python client remotelly",
  70. "customFieldValues" :
  71. [
  72. {"customfieldId" : "customfield_10224", "values" : ["1 - Greater than 10,000 seats"]},
  73. {"customfieldId" : "customfield_10321", "values" : ["production"]},
  74. {"customfieldId" : "customfield_10320", "values" : ["capacity"]},
  75. {"customfieldId" : "customfield_10230", "values" : ["2 - Significant loss of customer productivity"]},
  76. ],
  77. "priority" : 1
  78. }
  79. )
  80. print "Created %s/browse/%s" % (s.jira1.getServerInfo(auth)['baseUrl'], newissue['key'])
  81. ```
  82. ## Building a Java client
  83. The goal of this tutorial is to create a client that makes three simple remote calls to JIRA. Here we log in, retrieve the project information and then log out again. You can take a look at the full source code [here (xmlrpc-2.x)](attachments/4227133/4390944.java) or [here (xmlrpc-3.x)](attachments/4227133/4390986.java).
  84. The first step is to configure your details.
  85. ``` javascript
  86. public static final String JIRA_URI = "http://jira.atlassian.com";
  87. public static final String RPC_PATH = "/rpc/xmlrpc";
  88. public static final String USER_NAME = "enteryourlogin@atlassian.com";
  89. public static final String PASSWORD = "yourpassword";
  90. ```
  91. All XML-RPC calls are invoked at with the path `/rpc/xmlrpc` by default. You need to configure your username and password appropriately.
  92. ``` javascript
  93. // Initialise RPC Client
  94. XmlRpcClient rpcClient = new XmlRpcClient(JIRA_URI + RPC_PATH);
  95. // Login and retrieve logon token
  96. Vector loginParams = new Vector(2);
  97. loginParams.add(USER_NAME);
  98. loginParams.add(PASSWORD);
  99. String loginToken = (String) rpcClient.execute("jira1.login", loginParams);
  100. ```
  101. Method calls to JIRA via XML-RPC need to be prefixed with "`jira1.`". Parameters to methods are passed as sequenced Objects in a Vector. In the above code, we log into jira.atlassian.com. We receive back a `loginToken` which will need to be passed to all subsequent method calls.
  102. ``` javascript
  103. // Retrieve projects
  104. Vector loginTokenVector = new Vector(1);
  105. loginTokenVector.add(loginToken);
  106. List projects = (List)rpcClient.execute("jira1.getProjectsNoSchemes", loginTokenVector);
  107. // Print projects
  108. for (Iterator iterator = projects.iterator(); iterator.hasNext();-)
  109. {
  110. Map project = (Map) iterator.next();
  111. System.out.println(project.get("name") + " with lead " + project.get("lead"));
  112. }
  113. ```
  114. The RPC client calls the getProjectsNoSchemes() method passing the loginToken. This returns with a Vector of *projects* which are represented by `HashTable` objects. For information on what methods are available as well as what properties are available on returned projects, you'll again need to look at the <a href="http://confluence.atlassian.com/pages/viewpage.action?pageId=1035" class="external-link">JIRA XML-RPC API Spec</a>.
  115. ``` javascript
  116. // Log out
  117. Boolean bool = (Boolean) rpcClient.execute("jira1.logout", loginTokenVector);
  118. System.out.println("Logout successful: " + bool);
  119. ```
  120. Lastly, we log out of the system, again passing the loginToken in a Vector form.
  121. There it is! A simple client for JIRA XML-RPC. If you wish to extend or customise the JIRA XML-RPC plugin itself, you can download the latest source from the <a href="http://repository.atlassian.com/atlassian-jira-rpc-plugin/distributions/" class="external-link">repository</a>.
  122. ## Building a Perl client
  123. Here's an XML-RPC client that uses the `XMLRPC::Lite` module (distributed with ActivePerl and available for free on <a href="http://cpan.org/" class="external-link">CPAN</a>).
  124. ``` javascript
  125. #!/usr/bin/perl
  126. # toy jira perl client using XMLRPC
  127. # logs in, creates an issue
  128. # handles failure or prints issue fields
  129. # logs out.
  130. use strict;
  131. use warnings;
  132. use XMLRPC::Lite;
  133. use Data::Dumper;
  134. my $jira = XMLRPC::Lite->proxy('http://localhost:8080/jira/rpc/xmlrpc');
  135. my $auth = $jira->call("jira1.login", "admin", "admin")->result();
  136. my $call = $jira->call("jira1.createIssue", $auth, {
  137. 'project' => 'CEL',
  138. 'type' => 2,
  139. 'summary' => 'Issue created via XMLRPC',
  140. 'assignee' => 'admin',
  141. 'fixVersions' => [{'id' => '10000'},{'id' => '10001'}],
  142. 'customFieldValues' => [{'customfieldId' => 'customfield_10000', 'values' => ['Blah', 'Bling']}],
  143. 'description' => 'Created with a Perl client'});
  144. my $fault = $call->fault();
  145. if (defined $fault) {
  146. die $call->faultstring();
  147. } else {
  148. print "issue created:n";
  149. print Dumper($call->result());
  150. }
  151. $jira->call("jira1.logout", $auth);
  152. ```
  153. **Note:**
  154. `XMLRPC::Lite` is poorly documented. Using it for this simple example required reading the code. We do not recommend it for newbie Perl hackers.
  155. ##### RELATED TOPICS
  156. [Creating a JIRA SOAP Client](/server/jira/platform/creating-a-jira-soap-client-4227095.html)