AnsweredAssumed Answered

Create an Incident Ticket Using REST Web Services

Question asked by Balram.Deswal on Jul 23, 2015
Latest reply on Aug 18, 2015 by Balram.Deswal

Hi Team,

 

I am using REST Web Services of CA Service Desk Manager to create an incident ticket. I have used only POST Operation in SampleCRUDOperations.java that is used for incident creation. The contents of this file are as follows:

 

////////////////////////////////////////////////////////////////////////////

// Copyright (c) 2011 CA.  All rights reserved.

// 

// This software and all information contained therein is confidential and

// proprietary and shall not be duplicated, used, disclosed or disseminated

// in any way except as authorized by the applicable license agreement,

// without the express written permission of CA. All authorized

// reproductions must be marked with this language. 

//

// EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT

// PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT WARRANTY

// OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF

// MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT WILL

// CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY LOSS OR DAMAGE,

// DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE, INCLUDING WITHOUT

// LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION, GOODWILL, OR LOST DATA,

// EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR DAMAGE.

///////////////////////////////////////////////////////////////////////////

// $Id: $

// Module     : SampleCRUDOperations.java

// Created    : 2012/03/14 11:32:24

// Java Ver   : 1.6

// Description:

//

///////////////////////////////////////////////////////////////////////////

// README!  README!  README!  README!  README!  README!

//

// Description:

//  This class file contains sample code for invoking Service Desk REST Web Services.

//

//  THIS SHOULD BE RUN IN A TEST ENVIRONMENT AGAINST A TEST SERVICE DESK SERVER!

//  The routines in this file will create and modify Service Desk objects!

//

//  This sample class demonstrates how to perform all 4 CRUD operations supported

//  by SDM REST Web Services. It demonstrates the use of basic simple data type attributes.

//  More advanced attributes such as SRELs can be found in the xrels folder.

//

/////////////////////////////////////////////////////////////////////////

 

 

 

 

import java.io.IOException;

 

 

import org.apache.commons.httpclient.HttpClient;

import org.apache.commons.httpclient.HttpException;

import org.apache.commons.httpclient.methods.DeleteMethod;

import org.apache.commons.httpclient.methods.GetMethod;

import org.apache.commons.httpclient.methods.PostMethod;

import org.apache.commons.httpclient.methods.PutMethod;

 

 

 

 

/**

* Sample class goes through all 4 supported CRUD operations.

*

* It uses the GET method to retrieve a list of Incident tickets,

* the POST method to create a new Incident ticket,

* the PUT method to update an existing ticket,

* and uses the DELETE method to try to delete the ticket but

* it successfully fails since tickets can't be deleted.

*

* @author valre03

* @version $Revision: ASPEN.0 $

*/

public class SampleCRUDOperations

{

  @SuppressWarnings("deprecation")

  public SampleCRUDOperations()

  {

  //--- CONFIGURABLE VARIABLES

 

 

  // REST API base URI

  String baseURI = "http://localhost:8050/caisd-rest";

 

 

  // The Access Key obtained during authentication

  String accessKey = "425709217";

 

 

  //--- END OF CONFIGURABLE VARIABLES

 

 

 

 

  // Use Apache HTTP Client for all operations

  HttpClient client = new HttpClient();

 

 

  //////////////////////////////////////////////////

  // GET OPERATION -- Get a list of Incident tickets

  //////////////////////////////////////////////////

 

 

  /*String endpointGET  = baseURI + "/in";

 

 

  GetMethod get = new GetMethod(endpointGET);

  get.addRequestHeader("X-AccessKey", accessKey);

  get.addRequestHeader("Accept" , "application/xml");

  get.addRequestHeader("X-Obj-Attrs" , "ref_num, status, summary");

 

 

  try {

  System.out.println("Execute GET request for " + endpointGET);

  // Execute GET request

  int result = client.executeMethod(get);

 

 

  System.out.println("Response status code: " + result);

  System.out.println("Response body: ");

  System.out.println(get.getResponseBodyAsString());

  System.out.println();

 

 

  } catch (HttpException e) {

  e.printStackTrace();

  } catch (IOException e) {

  e.printStackTrace();

  } finally {

  get.releaseConnection();

  }*/

 

 

  /////////////////////////////////////////////////

  // POST OPERATION -- Create a new Incident ticket

  /////////////////////////////////////////////////

 

  String endpointPOST = baseURI + "/in";

 

 

  PostMethod post = new PostMethod(endpointPOST);

  post.addRequestHeader("X-AccessKey", accessKey);

  post.addRequestHeader("Accept" , "application/xml");

  post.addRequestHeader("Content-Type", "application/xml; charset=UTF-8");

  post.setRequestBody(

  "<in>" +

  "<customer COMMON_NAME=\"System_SD_User\"/>" +

  "<description>Created from REST API Java Samples code</description>" +

  "</in>"

  );

 

 

  try {

  System.out.println("Execute POST request for " + endpointPOST);

  // Execute POST request

  int result = client.executeMethod(post);

 

 

  System.out.println("Response status code: " + result);

  System.out.println("Response body: ");

  System.out.println(post.getResponseBodyAsString());

  System.out.println();

 

 

  } catch (HttpException e) {

  e.printStackTrace();

  } catch (IOException e) {

  e.printStackTrace();

  } finally {

  post.releaseConnection();

  }

 

 

  //////////////////////////////////////////////////////

  // PUT OPERATION -- Update an existing Incident ticket

  //////////////////////////////////////////////////////

 

 

  /*String endpointPUT = baseURI + "/in/400001";

 

 

  PutMethod put = new PutMethod(endpointPUT);

  put.addRequestHeader("X-AccessKey", accessKey);

  put.addRequestHeader("Accept" , "application/xml");

  put.addRequestHeader("Content-Type", "application/xml; charset=UTF-8");

  put.setRequestBody(

  "<in>" +

  "<summary>Updated from REST API Java Samples code</summary>" +

  "</in>"

  );

 

 

  try {

  System.out.println("Execute PUT request for " + endpointPUT);

  // Execute PUT request

  int result = client.executeMethod(put);

 

 

  System.out.println("Response status code: " + result);

  System.out.println("Response body: ");

  System.out.println(put.getResponseBodyAsString());

  System.out.println();

 

 

  } catch (HttpException e) {

  e.printStackTrace();

  } catch (IOException e) {

  e.printStackTrace();

  } finally {

  put.releaseConnection();

  }

 

 

  ///////////////////////////////////////////////////////////////////////////////////

  // DELETE OPERATION -- Attempt to delete an existing Incident ticket ; should fail!

  ///////////////////////////////////////////////////////////////////////////////////

 

 

  String endpointDELETE = baseURI + "/in/400001";

 

 

  DeleteMethod delete = new DeleteMethod(endpointDELETE);

  delete.addRequestHeader("X-AccessKey", accessKey);

  delete.addRequestHeader("Accept" , "application/xml");

 

 

  try {

  System.out.println("Execute DELETE request for " + endpointDELETE);

  // Execute DELETE request

  int result = client.executeMethod(delete);

 

 

  System.out.println("Response status code: " + result);

  System.out.println("Response body: ");

  System.out.println(delete.getResponseBodyAsString());

  System.out.println();

 

 

  } catch (HttpException e) {

  e.printStackTrace();

  } catch (IOException e) {

  e.printStackTrace();

  } finally {

  get.releaseConnection();

  }*/

 

 

  }

 

 

  public static void main(String[] args)

  {

  new SampleCRUDOperations();

  }

 

 

}

 

 

When I am running this web service, it is giving the following error:

Error.png

 

Kindly suggest me the changes I need to do in the SampleCRUDOperations.java that will rectify this error.

 

Regards,

Balram Singh Deswal

Outcomes