J tricks - Little JIRA Tricks
  • Home
  • Plugins ↓
    • JQL Tricks Plugin
      • JQL Tricks Plugin - Cloud
        • JQLT Cloud Installation
        • JQLT Cloud Configuration
        • JQLT Cloud Usage
        • JQLT Cloud License
        • JQLT Cloud FAQ
      • JQL Tricks Plugin - DC
        • JQLT DC Installation
        • JQLT DC Configuration
        • JQLT DC Usage
          • JQLT Issue Functions
          • JQLT Subtask Functions
          • JQLT Links Functions
          • JQLT Development Functions
          • JQLT Worklog Functions
          • JQLT Project Functions
          • JQLT Component Functions
          • JQLT Version Functions
          • JQLT Group Functions
          • JQLT User Functions
          • JQLT Date Functions
        • JQLT DC License
        • JQLT DC FAQ
        • JQLT DC Known Issues
        • JQLT DC Performance
      • JQL Tricks Cloud Migration
    • Simplified Planner
      • J-Planner Installation
      • J-Planner Configuration
      • J-Planner Usage
        • Creating a plan
        • Editing a plan
        • Deleting a plan
        • Viewing a plan
        • Modifying a plan
      • J-Planner FAQ
    • Atla-Search Plugin
      • Atla-Search Installation
      • Atla-Search Configuration
      • Atla-Search Usage
      • Atla-Search License
      • Atla-Search FAQ
    • Heroku for Compass App
      • Heroku for Compass Installation
      • Heroku for Compass Configuration
      • Heroku for Compass Usage
    • Copy to subtask Plugin
    • All Plugins
  • Tutorials
  • The Book
  • Contact Us
  • Home
  • Plugins ↓
    • JQL Tricks Plugin
      • JQL Tricks Plugin - Cloud
        • JQLT Cloud Installation
        • JQLT Cloud Configuration
        • JQLT Cloud Usage
        • JQLT Cloud License
        • JQLT Cloud FAQ
      • JQL Tricks Plugin - DC
        • JQLT DC Installation
        • JQLT DC Configuration
        • JQLT DC Usage
          • JQLT Issue Functions
          • JQLT Subtask Functions
          • JQLT Links Functions
          • JQLT Development Functions
          • JQLT Worklog Functions
          • JQLT Project Functions
          • JQLT Component Functions
          • JQLT Version Functions
          • JQLT Group Functions
          • JQLT User Functions
          • JQLT Date Functions
        • JQLT DC License
        • JQLT DC FAQ
        • JQLT DC Known Issues
        • JQLT DC Performance
      • JQL Tricks Cloud Migration
    • Simplified Planner
      • J-Planner Installation
      • J-Planner Configuration
      • J-Planner Usage
        • Creating a plan
        • Editing a plan
        • Deleting a plan
        • Viewing a plan
        • Modifying a plan
      • J-Planner FAQ
    • Atla-Search Plugin
      • Atla-Search Installation
      • Atla-Search Configuration
      • Atla-Search Usage
      • Atla-Search License
      • Atla-Search FAQ
    • Heroku for Compass App
      • Heroku for Compass Installation
      • Heroku for Compass Configuration
      • Heroku for Compass Usage
    • Copy to subtask Plugin
    • All Plugins
  • Tutorials
  • The Book
  • Contact Us

Creating a SOAP RPC Plugin

10/23/2010

13 Comments

 

I thought I would attack this topic next given its growing popularity in the forums !. So why is this so popular? The context is pretty much given in the earlier tutorial for creating a SOAP client.

There are at least a couple of ways for extending the given, out of the box SOAP capabilities of JIRA. Those will be writing an RPC plugin (thanks to JIRA for giving that option) and re-building the RPC plugin.

I prefer writing a new RPC Plugin. The one problem I see with it is that it introduces a new web service. So you end up connecting to the JIRA native one for the all the methods JIRA already exposes and to the new custom one for the new methods that is written. But re-building RPC plugin appears more painful for me because 
  1. it is painful ;) 
  2. we will have keep doing this for all future release of JIRA to make sure we have the recent list of JIRA supported methods.

So, let me assume that you are with me on writing a new RPC plugin. Here is how you write your descriptor to define the new RPC module. I am writing a v1 plugin here as I haven't worked on a v2 rpc plugin yet! As the JIRA rpc plugin is a v1 plugin, I guess it makes sense to keep this one also as v1.

<rpc-soap key="jtricks-soap-service" name="JTricks SOAP Service" class="com.jtricks.JTricksSoapServiceImpl">
    <description>JTricks SOAP service.</description>
    <service-path>jtricksservice</service-path>
    <published-interface>com.jtricks.JTricksSoapService</published-interface>
</rpc-soap>

Let us have a look in detail.

You need a new interface for your SOAP module and an implementation class for this. In our case we have JTricksSoapService and JTricksSoapServiceImpl. Now we need to define both of these in the rpc-soap module. As usual, the module should have a unique key along with the other details. Now define the method you want to expose, inside the interface.

public interface JTricksSoapService {
   
    String login(String username, String password);
   
    // Method to return Project Categories
    RemoteCategory[] getProjectCategories(String token) throws RemoteException;
}

Before we move on to the Implementation, we need to define what is a RemoteCategory. Let us assume we need only the name for now. RemoteCategory will then look like this:

public class RemoteCategory extends AbstractNamedRemoteEntity {

    private String name;

    public RemoteCategory(GenericValue value) {
        super(value);
        this.name = value.getString("name");
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

It should extend AbstractNamedRemoteEntity class. Make sure you add the following dependency in the pom.xml for that:

<dependency>
    <groupId>atlassian-jira-rpc-plugin</groupId>
    <artifactId>atlassian-jira-rpc-plugin</artifactId>
    <version>3.13-1</version>
    <scope>provided</scope>
</dependency>

Use the appropriate version. You will find the jars in your jira distribution or in the maven repository.

Now we create the implementation. Here is how the getProjectCategories look like in the implementation class:

public RemoteCategory[] getProjectCategories(String token) throws RemoteException {

    validateToken(token);

    Collection<GenericValue> categories = projectManager.getProjectCategories();
    RemoteCategory[] remoteCategories = new RemoteCategory[categories.size()];

    int i = 0;
    for (GenericValue category : categories) {
        remoteCategories[i++] = new RemoteCategory(category);
    }
    return remoteCategories;
}

Make sure you validate the token first using the tokenManager. You can inject the manager in the constructor.

private void validateToken(String token) {
    try {
        User user = tokenManager.retrieveUser(token);
    } catch (RemoteAuthenticationException e) {
        throw new RuntimeException("Error Authenticating!,"+e.toString());
    } catch (RemotePermissionException e) {
        throw new RuntimeException("User does not have permission for this operation,"+e.toString());
    }
}

You create the token using the initial method in the SOAP module which will look like this:

public String login(String username, String password) {
    try {
        return tokenManager.login(username, password);
    } catch (RemoteAuthenticationException e) {
        throw new RuntimeException("Error Authenticating!,"+e.toString());
    } catch (com.atlassian.jira.rpc.exception.RemoteException e) {
        throw new RuntimeException("Couldn't login,"+e.toString());
    }
}

Coming back to the getProjectCategories method, Once the token is validated, just retrieve all the categories using ProjectManager, populate the array of RemoteCategory and return it! Simple, isn't it?

All you need now is to build the plugin and put it under WEB-INF/lib. You can reach your new awesome webservice at {your_jira_url}/rpc/soap/jtricksservice?WSDL .

You can similarly extend the XPM-RPC methods as well. Read more about all these in the Atlassian docs . And find the source code for this tutorial  below.

Let us know how it went! And feel free to add any comments / feedbacks.
soap-plugin.zip
File Size: 4 kb
File Type: zip
Download File

13 Comments
Matt Doar link
10/25/2010 06:33:10 am

"The system RPC plugin is still version one? No way!" I thought so I checked the source and you're right. Then I filed a bug with Atlassian: http://jira.atlassian.com/browse/JRA-22596

This is a good introductory tutorial. Other tips:

Make sure your API methods in the Impl class are marked public.

Some clients such as suds python cache the list of methods so you have to change the version number in your endpoint to see newly added methods.

Don't forget to enable Remote Calls in Admin, General Configuration

Reply
J-Tricks
10/25/2010 07:10:16 am

Thanks Matt. Very valid points.

And you have my vote on JIRA-22596 :)

Reply
Raj
1/24/2011 05:53:40 pm

Hi,
Thanks for such a good tutorial ..

I deployed this to make own soap plugin extension .. and after compiling everything using atlas-run , i get the jar file ..

Now , if I start te local jira server ( using atlas-run on the local sdk), the weblink "{your_jira_url}/rpc/soap/jtricksservice?WSDL" works just fine ..

But if I place that jar in the WEB-INF/lib directory .. on my jira standalone server and restar the jira webservice, the weblink does not work ..

I thought that as my plgin is now version 2(which is by default the plugin created by atlas-create-jira-plugin), I should try placing that in the installed-plugins directory , and restarting the service .. but that also did not help me ..

could someone shed some light on what i am doing wrong here , and help me solve that problem please ..

THanks,
Raj

Reply
J-Tricks
1/24/2011 06:16:22 pm

Raj,

Did you try making your plugin v1 and deploying it under WEB_INF/classes? I have tried only v1 SOAP plugin and that works like a charm.

You can make your plugin v1 just by removing the version attribute from your atlassian-plugin.xml.

Let me know if that works.

Regards,
Jobin

Reply
Raj
1/24/2011 06:33:31 pm



Hey Jobin,
THanks for your prompt response.

Please disregard my previous comment .. somehow the plugin was recognized now , after enabling it in the plugins section of the JIRA server .. I swear , I had done it before , and it didnt work at that time ..

My follow up quetion though is -:

If I connect now the jira soap client given by atlassian ( http://confluence.atlassian.com/display/JIRA/Creating+a+SOAP+Client ) , and use the wsdl of the new soap plugin I created to access to functions of my soap plugin .. Do i need to import another wsdl to use the functions of the standard soap services , or can I use a single wsdl ( of my new soap plugin service) to access both the standard and the new soap functions ?

Thanks,
Raj

Reply
J-Tricks
1/24/2011 06:48:52 pm

Raj,

Good to know.

You will need to import both the WSDLs for the operations to work. That is one drawback of the SOAP plugin bt a minor one I would say given its advantages :)

Regards.
Jobin

Reply
Christina
6/16/2011 01:34:15 pm

Hi,

Your tutorial is really helpful! But I'm stuck on the actual usage of this extended SOAP service.

To use my new methods, I have to pass a token in as the parameter. But is this token from the original Jira RPC web service or the new extended one?

To get the original RPC token, I have this:
JiraWS.SoapExtensionClient jiraClient = new SoapExtensionClient();
string jiraToken = jiraClient.login("userABC", "pass");

However, using the new web service, I cannot seem to find the SoapExtensionClient. What should I be doing to get the token to pass in as the param?

Thanks so much!
Christina

Reply
J-Tricks
6/16/2011 07:23:10 pm

Christina,

You can create a login method as explained above in your new RPC plugin and we can then invoke that login method to retrieve the token.

It is possible to invoke the login method on the original JIRA SOAP plugin and use the token in your custom plugin methods but it is more work as it needs clients to be created for both the plugins.

I would go with the first approach!

Reply
Christina
6/17/2011 06:25:30 am

Hi again!

Sorry I don't know how I overlooked that! I was so into the whole thing being done in the client-side.

Anyway, to user the login method in your tutorial, we would need to set up the web service client (I'm using ASP.NET and C#). Currently I have this line:
JiraWSext.SoapServiceClient jiraClient = new SoapExtensionClient();

My JiraWSext only gives me these options: SoapService, SoapServiceChannel, and SoapServiceClient. However, from the original RPC plugin, I have these: SoapExtension, SoapExtensionChannel, SoapExtensionClient. Basically, I'm having trouble instantiating my jiraClient. It seems like it's something simple but Google isn't helping much here.

Thanks again for your help!
Christina

Reply
J-Tricks
6/17/2011 07:52:05 am

Christina,

I am not an expert in .NET either. However it shouldn't be too different from how JAVA works. You can read more about creating a JAVA client in my other tutorial: http://www.j-tricks.com/1/post/2010/08/jira-soap-client.html

Reply
Christina
6/20/2011 06:56:08 am

Hi,

I've got the last problem resolved too, but it seems like my Jira is encountering some problems with the new extended SOAP service. Basically, I get a long error message in the log as follows:

AxisFault
faultCode: {http://xml.apache.org/axis/}Client.NoSOAPAction
faultSubcode:
faultString: no SOAPAction header!
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:no SOAPAction header!

It seems like I'm missing some little details so Jira can't recognize the new plugin?

If you've seen this before, any pointer would be great! Thanks again =)
Christina

Reply
J-Tricks
6/20/2011 09:18:22 pm

Christina, Seems the SOAP Header is not constructed properly. You might be encountering something specific to .NET invocation.

I found a related issue at https://jira.atlassian.com/browse/JRA-22771

Reply
check this site link
6/26/2013 12:56:25 am

Awesome post! This is an informative article for all the SOAP clients. This can really make them confident in building an RPC plug in. These instructions can speed up the implementation of SOAP module. I will continue looking after your blog for more such instructions. Thank you!

Reply

Your comment will be posted after it is approved.


Leave a Reply.

    Enter your email address:

    Author

    Jobin Kuruvilla - Works in Adaptavist as Head of DevOps Professional Services. 

    Author of JIRA Development Cookbook and JIRA 5.x Development Cookbook.


    RSS Feed

    Categories

    All
    Acive Objects
    Ajs
    Book
    Components
    Condition
    Custom Fields
    Customization
    Events
    Gadgets
    Javascript
    Jql
    Listener
    Mail
    Permissions
    Plugin Framework
    Post Function
    Properties
    Remote Invocation
    Reporting
    Rest
    Scheduled Tasks
    Search
    Services
    Soap
    Summit
    User Interface
    Validator
    Webwork Actions
    Workflow

    Archives

    October 2016
    August 2016
    March 2016
    January 2016
    December 2015
    May 2014
    December 2013
    November 2013
    July 2013
    June 2013
    April 2013
    October 2012
    September 2012
    August 2012
    July 2012
    May 2012
    March 2012
    February 2012
    January 2012
    December 2011
    November 2011
    June 2011
    May 2011
    April 2011
    March 2011
    February 2011
    January 2011
    November 2010
    October 2010
    September 2010
    August 2010

SUPPORT
APPS
TUTORIALS
THE BOOK
© J-Tricks