P-II: Retrieve a CSR Attachment with Java Web Service Calls

Intended Audience: Technical Users and Administrators of Stat

Intended Subject: Retrieve CSR Attachments via Java Web Service calls

Intended Reaction: Happy Stat Customers

Keywords: Stat, Web Services, Java, CSR, Attachments

Hello fellow Stat Technical Users & Administrators!

Welcome to a new year and a new series of Blog posts!

This series will focus on getting the most out of Stat integration with other systems such as keeping documents synchronized as they are added, updated or deleted in different locations or applications.

What’s the goal of this Post?

The goal of this post is to enable your technical team to quickly setup things for documentation synchronization across various applications and/or locations by being able to retrieve a CSR attachment.

Examples of this may be:

  • When a document gets updated in a CSR, retrieve and update the document in another location or vise-versa
  • Retrieve Log Files, Screenshots, Change Control Visio diagrams and the like
  • Retrieve an attachment from a CSR to view in another application

Caution & User Reference:

If you have not worked with Stat Web Services in the past, this is not the place to begin. You’ll need to setup your environment and ensure other settings are verified.

If you are not familiar with Stat Web Services, please refer to “Appendix G: Stat Web Services” in the Stat System Administrators Guide.

You can also find sample code and further documentation on the Stat Installation CD. On the CD you will see a directory called “web_services_sample“.

In this directory is a PDF on Stat Web Services along with a Zip file called StatWS.zip The zip file contains the sample code and additional instructions on setting
up your environment and running the samples included.


Let’s Go!

For this specific post we will look at adding an attachment to a CSR.

Retrieve a CSR attachment:

To retrieve an existing attachment from a CSR we need to make the following Web Service call: retrieveCSRAttachments()

For this, I’m using a Java Source/Class file named = StatWSCSRAttachCalls.java, and StatWSCSRAttachCalls.class respectively.

In this class there are three calls available to me:

/* StatWSCSRAttachCalls CSR Attachment Related Calls:

1 - retrieveCSRAttachments

2 - addCSRAttachments

3 - deleteCSRAttachments


Remembering that we need to first establish a connection to the Stat Web Service as part of the process, we will pass in our User Id and Password along with the call to make.

For the test environment that would be:


My actual call is %JAXWS_RUN_COMMAND% StatWSCSRAttachCalls WIN-52C9JR1VJH7 8080 MyUserID MyPassword 1

Here’s a screenshot of the Java call running:


Let’s see the results within Stat:

Before retrieving the attachment we can see the CSR currently has two existing attachments.

Attachment #2, “BillAttached_1.txt” was the one we added in Part-I. Let’s grab “Attachment1.txt” for this example.


Now let’s see what’s happening in the code:

Here’s the Attachment Type Bean:

// --------------------------------------------------

// Begin AttachmentType:

<complexType name="AttachmentType">


<element name="fileId" type="xsd:long"/>

<element name="filename" type="xsd:string"/>

<element name="contentType" type="xsd:string"/>

<element name="comments" type="xsd:string"/>

<element name="content" type="xsd:base64Binary" xmime:expectedContentTypes="application/octet-stream"/>



// End AttachmentType
// --------------------------------------------------

Here’s the call: *1, *2

%JAXWS_RUN_COMMAND% StatWSCSRAttachCalls WIN-52C9JR1VJH7 8080 MyUserID MyPassword 1


public static void main(String[] args) throws Exception {


… Set Variables and the like…


// ----------------------------------------------------

// Establish a Connection to Stat Web Services Central Agent:

try {

connectId = loginPort.connect(user, pass);

System.out.println(" ");

System.out.println("Stat Web Service ConnectId = " + connectId);

System.out.println(" ");

} catch(WSLoginFault e) {

WSLoginFaultType ue = e.getFaultInfo();

System.out.println(" ");

System.out.println("Stat Web Service ERROR: " + ue.getMessage());

System.out.println(" ");



… Set CSR ID, Service Domain Variables and the like…


case 1: // Do retrieveCSRAttachments

// ===================================================================================

// 1 = retrieveCSRAttachments(long connectId, String sdcd, long csrId) throws WSCsrFault;

// This method retrieves a list of attachments in a CSR.

// If there are no attachments in the CSR, a null value is returned.

// Input Parameters:

// connectId - A valid connect Id obtained by calling WSLoginService.connect.

// sdcd – Service Domain Code.

// csrId – a valid CSR Number (Integer).

// Return Parameter:

// List of type Attachment Type. - A List of Attachments for the CSR.

// ===================================================================================

System.out.println(" ");

System.out.println("Call #" + calltorun + ": retrieveCSRAttachments...");

System.out.println(" ");


// --------------------------------------------------

try {

// --------------------------------------------------

// Set AttachmentType attachments:

List<AttachmentType> attList = new ArrayList<AttachmentType>();

AttachmentType att = new AttachmentType();


// --------------------------------------------------

// Do Call: csrPort.retrieveCSRAttachments(connectId, sdcd, csrId);

attList = csrPort.retrieveCSRAttachments(connectId, sdcd, csrId);

// Check for No Attachments Found:

if (attList.size() < 1) {


System.out.println(" No Attachments Found for CSR ID: " + csrId );




// Retrieve attachments to att list.

att = attList.get(1);


System.out.println(" Attachments Returned for CSR ID: " + csrId + " Attachments Count = " + attList.size() + " - Filename #1 = " + att.getFilename());


} catch(WSCsrFault e) {

WSCsrFaultType ue = e.getFaultInfo();

// Weed out 'No Rows Returned' as Non-Error.

String strOrig = ue.getMessage();

int intIndex = strOrig.indexOf("NoResultException");

System.out.println(" ");

if(intIndex == - 1){

System.out.println("ERROR: Call = retrieveCSRAttachments. Error = " + ue.getMessage());




System.out.println("Attachments Returned for CSR ID: " + csrId + " = NO Rows Returned.");



System.out.println(" ");



// … Next set of calls and end of app.


} // end switch (calltorun)

System.out.println(" ");

System.out.println("Java Web Service Call Completed Successfully.");

System.out.println(" ");



And that’s it!

With less than 100 lines of code we set and established a connection to Stat. We then retrieved an attachment from our CSR - taking into consideration error control and user feedback/output.

The above code set is not a complete standalone app. With the proper imports, variables, and a few other wrappers, it would still not be more than 100 lines or so.

*1 If you would like a copy of the sample code used here, please see the Documents section of the Stat User Community.

*2 I do not profess to be a pro at Java, but more of a Java noob. Please excuse any blatant coding mishaps.

In Closing…

In the next post we will continue with the Attachment theme and look at retrieving and deleting attachments. Stay Tuned!

Thank you for taking the time to read this post. I hope you found it informative.



William R. Hart

Solutions Architect


Dell | Quest Group, Pre-Sales