1) Setting up the proxy classes
private static final String WEB_SERVICE_SUFFIX = "/Services/v3_0/ImportExport.svc"; //$NON-NLS-1$
private static final String WEB_SERVICE_NAMESPACE = "{https://www.inflectra.com/SpiraTest/Services/v3.0/}ImportExport"; //$NON-NLS-1$
private static final String WEB_SERVICE_NAMESPACE_DATA_OBJECTS = "http://schemas.datacontract.org/2004/07/Inflectra.SpiraTest.Web.Services.v3_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();
}