Example code on how to use spira Team web services

Wednesday, July 4, 2012
Avatar
I have found the WSDL of the spira Team web services. I notice that it contains numerous get methods and two authentication methods.
It  would be helpful to have a document to say how to use the web services in general.
Eg open a connection using either of these methods. Then call your methods to get your data then close the connection.

Specifically I want to get all the incident number, descriptions for the incidents fixed in a specific release so I can generate some release notes.
So I need to do what?
2 Replies
Thursday, July 5, 2012
Avatar
re: alan.heath Wednesday, July 4, 2012

Hi Alan

We've typed up a quick KB article for you - https://www.inflectra.com/Support/KnowledgeBase/KB3.aspx

Let us know if you have any questions.

Wednesday, July 11, 2012
Avatar
re: inflectra.david Thursday, July 5, 2012
Thanks Adam that was helpful.
I have replicated your c# code in java. I used eclipse and axis to convert the WSDL into java stubs then called those stubs as follows.

import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import org.datacontract.schemas._2004._07.Inflectra_SpiraTest_Web_Services_v3_0.ServiceFaultMessage;
import org.datacontract.schemas._2004._07.Inflectra_SpiraTest_Web_Services_v3_0_DataObjects.RemoteFilter;
import org.datacontract.schemas._2004._07.Inflectra_SpiraTest_Web_Services_v3_0_DataObjects.RemoteIncident;
import org.datacontract.schemas._2004._07.Inflectra_SpiraTest_Web_Services_v3_0_DataObjects.RemoteRelease;
import org.datacontract.schemas._2004._07.Inflectra_SpiraTest_Web_Services_v3_0_DataObjects.RemoteSort;

import com.inflectra.www.SpiraTest.Services.v3_0.IImportExport;
import com.inflectra.www.SpiraTest.Services.v3_0.ImportExportLocator;

public class SpiraTeamClient
{
    /**
     * Print the release notes for a particular release.
     *
     * @param p_projectId the project id, in SpiraTeam if a project is PR000062 then use 62
     * @param p_releaseVersion the release Version, in spiraTeam is shown as Version #
     * @param p_user user name used for authentication
     * @param p_passwd password used for authentication
     * @throws ServiceException
     * @throws ServiceFaultMessage
     * @throws RemoteException
     */
    private static void printReleaseNotes(int p_projectId, String p_releaseVersion, String p_user, String p_passwd) throws ServiceException, ServiceFaultMessage, RemoteException
    {
        int releaseId = 0; // spira team release id
        IImportExport spiraImportExport = null;
        try
        {
            ImportExportLocator spiraTeamLocator = new ImportExportLocator();
            spiraTeamLocator.setMaintainSession(true); // enable cookies
            spiraTeamLocator.setEndpointAddress(spiraTeamLocator.getBasicHttpBinding_IImportExportWSDDServiceName(), spiraTeamLocator.getBasicHttpBinding_IImportExportAddress());
            spiraImportExport = spiraTeamLocator.getBasicHttpBinding_IImportExport();
            spiraImportExport.connection_Authenticate(p_user, p_passwd);
            spiraImportExport.connection_ConnectToProject(p_projectId);
           
            // get the release id
            RemoteFilter[] releaseFilters = new RemoteFilter[1];
            releaseFilters[0] = getStringFilter("VersionNumber", p_releaseVersion);
            RemoteRelease[] releases = spiraImportExport.release_Retrieve2(releaseFilters, 1, 4);
            if (releases.length != 1)
            {
                System.err.println("Web service found " + releases.length + " releases for version: " + String.valueOf(p_releaseVersion));
                return;
            }
            releaseId = releases[0].getReleaseId();
           
            // only want incidents resolved in a single release
            RemoteFilter[] incidentFilters = new RemoteFilter[1];
            incidentFilters[0] = getIntFilter("ResolvedReleaseId", releaseId);
           
            // want the list of incidents sorted by Incident number, lowest
            // incident number first
            RemoteSort remoteSort = new RemoteSort();
            remoteSort.setPropertyName("IncidentId");
            remoteSort.setSortAscending(true);
           
            // make the web service call to get the incidents
            RemoteIncident[] remoteIncidents = spiraImportExport.incident_Retrieve(incidentFilters, remoteSort, 1, 9999);
           
            // Loop through and display ID, and name
            for (RemoteIncident remoteIncident : remoteIncidents)
            {
                System.out.print(remoteIncident.getIncidentId().toString());
                System.out.print("  ");
                System.out.println(remoteIncident.getName().toString());
            }
        }
        finally
        {
            if (spiraImportExport != null)
            {
                spiraImportExport.connection_Disconnect(); // tidy up
            }
        }
    }
   
    private static RemoteFilter getStringFilter(String p_name, String p_value)
    {
        RemoteFilter filter = new RemoteFilter();
        filter.setPropertyName(p_name);
        filter.setStringValue(p_value);
        return filter;
    }
   
    private static RemoteFilter getIntFilter(String p_name, int p_value)
    {
        RemoteFilter filter = new RemoteFilter();
        filter.setPropertyName(p_name);
        filter.setIntValue(p_value);
        return filter;
    }
   
    public static void main(String[] args) throws Exception
    {
        int projectId = 28    // PR000028; 
        String user = "username";
        String passwd = "password";
        String releaseVersion = "2.1.0__13";  // Version #
        if (args.length == 1)
        {
            releaseVersion = args[0];
        }
        printReleaseNotes(projectId, releaseVersion, user, passwd);
    }

       
}

Spira Helps You Deliver Quality Software, Faster and With Lower Risk

And if you have any questions, please email or call us at +1 (202) 558-6885

 

Statistics
  • Started: Wednesday, July 4, 2012
  • Last Reply: Wednesday, July 11, 2012
  • Replies: 2
  • Views: 4557