TestTrack SOAP SDK Tutorial - NetBeans Java (JAX-RPC)
TestTrack SOAP SDK Tutorial - NetBeans Java (JAX-RPC)
While Axis is a very powerful and popular tool, there are some parsing issues with Axis version 1.4 that can
make it very frustrating and as of the time of this writing, the latest version of Axis2 is not able to create the
Java classes from TestTrack WSDL.
A relatively easy way to create SOAP applications using Java is with NetBeans. The following is a tutorial
that will take you step by step on how to create a simple Java application that you can use to get a list of
defects, updates a defect, among other actions.
NOTE: This is not a tutorial on how to use NetBeans or write Java applications. The sole purpose of this
article is to show how to use the TestTrack SOAP based SDK in NetBeans. You may find a different and
maybe better way to use NetBeans for developing SOAP applications.
This is meant as an example only and Seapine does not offer support for this.
Contents
1 Don't want to use NetBeans?
2 The environment
3 Creating the project
4 Setting up the web service interface
4.1 Handling a known issue
4.2 Editing the WSDL file
5 Handling a requirement
6 Creating the web service client
6.1 Getting the files in the
package
6.2 Editing the classes
7 Writing Code
7.1 Invoking a web service
operation
7.2 Setting the ttsoapcgi url
7.3 Sample Methods
7.4 Logging into a project
7.5 Getting a defect list array
(CRecordListSoap)
7.6 Get defect for edit
7.7 Save Defect
8 Download
Contents
TestTrack_SOAP_SDK_Tutorial__NetBeans_Java_(JAXRPC)
The environment
The following example uses TestTrack 2008.1.2 and NetBeans IDE 6.1 (Build 200805300101). Older
versions of TestTrack or NetBeans should also work.
Screenshots included in this article are of NetBeans or TestTrack in a Windows environment.
1. Choose Project Under Categories select Java and under Projects: select Java Application.
2. Name and Location Under Project Name: enter the name of the project. In this example we will use the
name "ttSoapSample". You can leave the location as is or you can change it to a different location. Leave the
box checked next to Create Main Class. Optionally you can leave the Set as Main Project box checked.
This really should only be left checked if this is the project you are going to be spending most of your time.
TestTrack_SOAP_SDK_Tutorial__NetBeans_Java_(JAXRPC)
NOTE: You can always just download the Generated Java Classes.
Other Java utilities like Axis remove the dashes when declaring the Java variables.
These variables are used mainly when creating a defect object. They are used both for the list of source code
files (CSCCFileRecord) and file attachments (CFileAttachment).
TestTrack 2010 note: In 2010, a new object called CFile was instroduced. This one must also be adjusted.
Here is a list of these variables:
CSCCFileRecord
mstrFileName
mstrFixedRevision
mdateFixedTimestamp
mstrType
mscriptOrder
mpFileData
CFileAttachment
mstrFileName
mstrArchiveName
mstrType
mscriptOrder
mstrScriptState
TestTrack_SOAP_SDK_Tutorial__NetBeans_Java_(JAXRPC)
Keep in mind that the dashes need only to be handled while processing Java code. When the XML file is built,
those variables will need to have dashes in them, as defined in the WSDL file.
1. Edit the WSDL file and remove the dashes for those variables, and then edit the XML serializer classes to
include the dashes when building the XML files.
2. Create the classes using the standard WSDL, let NetBeans complain about the syntax issues and manually
fix the variable names. There are about 100 edits required and you may have to do this every time the client
refreshes itself.
By far the easiest is to go with option #1 and that is what will be done in this example.
NOTE: This is only required if you need to build a defect, test case or test run object. If your application only
needs to retrieve a list of defects, for example, you do not need to worry about editing the SOAP serializer
classes.
<complexType name="CSCCFileRecord">
<complexContent>
<extension base="ttns:CItemWithDBRecordId">
<sequence>
<element name="mstrFileName" type="xsd:string" minOccurs="1" maxOccurs="1" nillable="false"
<element name="mstrFixedRevision" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="t
<element name="mdateFixedTimestamp" type="xsd:dateTime" minOccurs="0" maxOccurs="1" nillabl
<element name="mstrType" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<element name="mscriptOrder" type="xsd:long" minOccurs="0" maxOccurs="1"/>
<element name="mstrScriptState" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="tru
</sequence>
</extension>
</complexContent>
</complexType>
TestTrack_SOAP_SDK_Tutorial__NetBeans_Java_(JAXRPC)
<sequence>
<element name="mstrFileName" type="xsd:string" minOccurs="1" maxOccurs="1" nillable="false"/
<element name="mstrFixedRevision" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="tr
<element name="mdateFixedTimestamp" type="xsd:dateTime" minOccurs="0" maxOccurs="1" nillable
<element name="mstrType" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<element name="mscriptOrder" type="xsd:long" minOccurs="0" maxOccurs="1"/>
<element name="mstrScriptState" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true
</sequence>
</extension>
</complexContent>
</complexType>
The next section where you will find the variables is here:
<complexType name="CFileAttachment">
<sequence>
<element name="mpFileData" type="xsd:base64Binary" minOccurs="0" maxOccurs="1" nillable="tr
<element name="mstrFileName" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/
<element name="mstrArchiveName" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="tru
<element name="mstrType" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<element name="mscriptOrder" type="xsd:long" minOccurs="0" maxOccurs="1"/>
<element name="mstrScriptState" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="tru
</sequence>
</complexType>
After doing the same with these variables, the section now looks like this:
</complexType>
<complexType name="CFileAttachment">
<sequence>
<element name="mpFileData" type="xsd:base64Binary" minOccurs="0" maxOccurs="1" nillable="tru
<element name="mstrFileName" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<element name="mstrArchiveName" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true
<element name="mstrType" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<element name="mscriptOrder" type="xsd:long" minOccurs="0" maxOccurs="1"/>
<element name="mstrScriptState" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true
</sequence>
</complexType>
Handling a requirement
The WSDL is rpc encoded and you will need to download the JAXRPC Web Service plugin for NetBeans.
TestTrack_SOAP_SDK_Tutorial__NetBeans_Java_(JAXRPC)
Click on Next.
The WSDL and Client Location appears. Choose the location of the WSDL file. If the WSDL file is located
on your machine, you may select "Local File" and browse for the file. If the file is on a web server, choose the
WSDL URL option.
In this example, the ttsoapcgi.wsdl is installed on the C:\inetpub\wwwroot\ folder on the same machine.
Therefore either Local File: (C:\inetput\wwwroot\ttsoapcgi.wsdl) or WSDL URL
(http://localhost/ttsoapcgi.wsdl) options are valid.
Next, select "JAXRPC Style" from the Client Side drop down. This selection will in turn enable you to
select the package to include the client in. Select the package you created to store the web service client files.
Click on Finish
TestTrack_SOAP_SDK_Tutorial__NetBeans_Java_(JAXRPC)
Browse to the folder where your project is stored and find the \build\generated\wsclient directory. There you
will see a folder with the pacakage name. Copy the folder and replace the empty folder with the same name
under the \src directory.
The package in NetBeans now shows all of the Java classes created by the Web Service Client.
CFileAttachment_SOAPSerializer.java
In each file you will find a section where it builds the section of the XML file for the file attachments and
source code files.
TestTrack_SOAP_SDK_Tutorial__NetBeans_Java_(JAXRPC)
After making the changes, the same section now looks like:
Writing Code
Now the real fun begins, we are ready to actually start writing code.
On the Main.java file, place your cursor under the "// TODO code application logic " comments, right click
Editing the classes
TestTrack_SOAP_SDK_Tutorial__NetBeans_Java_(JAXRPC)
and select Web Service Client Resources > Call Web Service Operation. The Select Operation to Invoke
dialog appears.
try { // This code block invokes the Ttsoapcgi:getProjectList operation on web service
testtrack_Interface.Ttsoapcgi ttsoapcgi = new testtrack_Interface.Ttsoapcgi_Impl();
testtrack_Interface.TtsoapcgiPortType _ttsoapcgi = ttsoapcgi.getTtsoapcgi();
_ttsoapcgi.getProjectList(/* TODO enter operation arguments*/);
} catch(javax.xml.rpc.ServiceException ex) {
java.util.logging.Logger.getLogger(testtrack_Interface.Ttsoapcgi.class.getName()).log(jav
} catch(java.rmi.RemoteException ex) {
java.util.logging.Logger.getLogger(testtrack_Interface.Ttsoapcgi.class.getName()).log(jav
} catch(Exception ex) {
java.util.logging.Logger.getLogger(testtrack_Interface.Ttsoapcgi.class.getName()).log(jav
}
All you have to do now is fill out the parameters where the comments /* TODO enter operation arguments*/
appear. However, after you get the list of projects you may want to do something with them, so other code
may also be necsessary.
The following is the same piece of code but with the following additions:
Imports the testtrack_Interface package (to avoid having to prepend each object with the package name) and
removes 'testtrack_Interface' from object definintions.
Passes username and password to the getProjecList method.
Loops through each project and prints out each name.
package ttsoapsample;
import testtrack_Interface.*;
/**
*
TestTrack_SOAP_SDK_Tutorial__NetBeans_Java_(JAXRPC)
* @author cremerf
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic
try
{ // This code block invokes the Ttsoapcgi:getProjectList operation on web service
Ttsoapcgi ttsoapcgi = new Ttsoapcgi_Impl();
TtsoapcgiPortType _ttsoapcgi = ttsoapcgi.getTtsoapcgi();
CProject[] projectList = _ttsoapcgi.getProjectList("Administrator","password");
for (int i =0; i < projectList.length;i++)
{
System.out.println(projectList[i].getDatabase().getName());
}
}
catch(javax.xml.rpc.ServiceException ex)
{
java.util.logging.Logger.getLogger(testtrack_Interface.Ttsoapcgi.class.getName()).log(
}
catch(java.rmi.RemoteException ex)
{
java.util.logging.Logger.getLogger(testtrack_Interface.Ttsoapcgi.class.getName()).log(
}
catch(Exception ex)
{
java.util.logging.Logger.getLogger(testtrack_Interface.Ttsoapcgi.class.getName()).log(
}
}
}
10
TestTrack_SOAP_SDK_Tutorial__NetBeans_Java_(JAXRPC)
Sample Methods
The following are excerpts from a class created to handle all calls made to the web service.
The TtsoapcgiPortType object (_ttsoapcgi) is generated when the class is instantiated and therefore can be
reused each time the same instance of the _ttsoapcgi object is used.
NOTE: The following variables are declared as public and therefore are accessible to all of the methods:
ttCookie(long)
ttUsername(String)
ttPassword(String)
ttProjectName(String)
_ttsoapcgi(TtsoapcgiPortType)
Sample Methods
11
TestTrack_SOAP_SDK_Tutorial__NetBeans_Java_(JAXRPC)
result = true;
}
}
catch(Exception ex)
{
java.util.logging.Logger.getLogger(testtrack_Interface.Ttsoapcgi.class.getName()).lo
}
return result;
}
}
catch (Exception fcc)
{
java.util.logging.Logger.getLogger(Ttsoapcgi.class.getName()).log(java.util.loggi
}
return m_Records;
}
12
TestTrack_SOAP_SDK_Tutorial__NetBeans_Java_(JAXRPC)
Save Defect
Download
I have posted below a project I created following the steps in this article. It includes everything, including the
.class files created by NetBeans. Note that this example does not employ the method that allows you to change
the URL prgramatically.
It does contain the .java and .class files created from the WSDL.
NetBeans Project
13