Knowledge Base Article

Home Page > Knowledge Base > Spira Platform

Home Page > Knowledge Base > Spira Platform > SpiraPlan

Home Page > Knowledge Base > Spira Platform > SpiraTeam

Home Page > Knowledge Base > Spira Platform > SpiraTest

Article How to access Spira v4.0 SOAP web services using Java

by Adam S on Friday, May 3, 2013

This knowledge base article describes how to connect to the SpiraTest, SpiraPlan & SpiraTeam SOAP web services using Java code. It assumes that you've either generated the SOAP proxy classes using JAX-WS or are using the pre-compiled ones attached to this KB article.

1) Setting up the proxy classes

private static final String WEB_SERVICE_SUFFIX = "/Services/v4_0/ImportExport.svc"; //$NON-NLS-1$
private static final String WEB_SERVICE_NAMESPACE = "{http://www.inflectra.com/SpiraTest/Services/v4.0/}ImportExport"; //$NON-NLS-1$
private static final String WEB_SERVICE_NAMESPACE_DATA_OBJECTS = "http://schemas.datacontract.org/2004/07/Inflectra.SpiraTest.Web.Services.v4_0.DataObjects"; //$NON-NLS-1$

String serviceUrl = new URL(baseUrl + WEB_SERVICE_SUFFIX);
ImportExport service = new ImportExport(this.serviceUrl, QName.valueOf(WEB_SERVICE_NAMESPACE));

IImportExport soap = service.getBasicHttpBindingIImportExport();

//Make sure that session is maintained
Map<String, Object> requestContext = ((BindingProvider)this.soap).getRequestContext();
requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY,true);

2) Authenticate and connect to project

boolean success = soap.connectionAuthenticate(this.userName, this.password);
success = soap.connectionConnectToProject(projectId);

3) Create a new incident

RemoteIncident remoteIncident = objectFactory.createRemoteIncident();

remoteIncident.setIncidentTypeId(objectFactory.createRemoteIncidentIncidentTypeId(113));

remoteIncident.setIncidentStatusId(objectFactory.createRemoteIncidentIncidentStatusId(113));

remoteIncident.setName(objectFactory.createRemoteIncidentName("Test incident name"));

remoteIncident.setDescription(objectFactory.createRemoteIncidentDescription("Test description"));

remoteIncident.setCreationDate(objectFactory.createRemoteIncidentCreationDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar( 1976, Calendar.DECEMBER, 22 ))));

 

try {

      RemoteIncident i = soap.incidentCreate(remoteIncident);

} catch (IImportExportIncidentCreateServiceFaultMessageFaultFaultMessage e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

}

4) Retrieve Incidents

// Create RemoteFilter

RemoteFilter filter1 = objectFactory.createRemoteFilter();

mvf = objectFactory.createMultiValueFilter();

ArrayOfint array1 = objectFactory.createArrayOfint();

array1.getInt().add(1);

array1.getInt().add(2);

array1.getInt().add(3);

array1.getInt().add(4);

mvf.setValues(objectFactory.createMultiValueFilterValues(array1));

filter1.setPropertyName(objectFactory.createRemoteIncidentDescription("PriorityId"));

filter1.setMultiValue(objectFactory.createMultiValueFilter(mvf));

ArrayOfRemoteFilter filters = objectFactory.createArrayOfRemoteFilter();

filters.getRemoteFilter().add(filter1);

 

// Create RemoteSort

RemoteSort sort = objectFactory.createRemoteSort();

sort.setPropertyName(objectFactory.createRemoteFilterPropertyName("Name"));

sort.setSortAscending(true);

ArrayOfRemoteIncident incidents = soap.incidentRetrieve(filters, sort, 1, 10);

            

try{

      ArrayOfRemoteIncident incidents = soap.incidentRetrieve(filters, sort, 1, 10);

                  

} catch (IImportExportIncidentRetrieveServiceFaultMessageFaultFaultMessage e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

}


 

Attachments
Article Info
Last Updated: 5/3/2013
Article ID: KB48
# Views: 1747
Powered by KronoDesk v1.1.0.15 | © Copyright Inflectra Corporation 2011-2016 | Licensed to Inflectra Corporation.