Hi Vidya,
Hope this code helps for you
////////////////////////////////////////////////////////////////////////////
// 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 : SampleCreateBRELResource.java
// Created : 2012/04/13 15:50: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 create a new record for a BREL
// attribute and in particular, how to add a new Log Comment to a Change
// Order ticket.
//
// The process for BLREL attributes is also the same. Create the record
// on the LREL resource, that is, the resource in the middle of the
// many-one-many relationship.
//
// For example, chg.asset is a BLREL attribute and is defined as follows:
// asset BREL <- lrel_asset_chgnr.chg (LREL nr) {chg = ?}
// To create a new relationship between a change order ticket and an asset,
// create a record in the lrel_asset_chgnr resource and provide the
// required attribute details.
//
// For info on how to retrieve details from a BREL/BLREL attribute,
// see sample file SampleGetQRELDetails.java. The process is the same.
//
/////////////////////////////////////////////////////////////////////////
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
/**
* This sample class demonstrates how to add a new Log Comment activity log
* to an existing Change Order ticket.
*
* @author valre03
* @version $Revision: ASPEN.0 $
*/
public class SampleCreateBRELResource
{
@SuppressWarnings("deprecation")
public SampleCreateBRELResource()
{
//--- CONFIGURABLE VARIABLES
// REST API base URI
String baseURI = "http://localhost:8050/caisd-rest";
// The Access Key obtained during authentication
String accessKey = "1174913924";
// Change Order id
String chgId = "400001";
//--- END OF CONFIGURABLE VARIABLES
HttpClient client = new HttpClient();
///////////////////////////////////////////////////////////////////
// POST OPERATION -- Add a Log Comment activity to the Change Order
///////////////////////////////////////////////////////////////////
String postBREL = baseURI + "/chgalg"; // Change Order Activity Log
String xmlPayload =
"<chgalg>" +
"<type REL_ATTR=\"LOG\"/>" +
"<change_id REL_ATTR=\"" + chgId + "\"/>" +
"<description>Activity Log created from REST API Java Samples code</description>" +
"</chgalg>";
PostMethod post = new PostMethod(postBREL);
post.addRequestHeader("X-AccessKey", accessKey);
post.addRequestHeader("Accept" , "application/xml");
post.addRequestHeader("Content-Type", "application/xml; charset=UTF-8");
post.setRequestBody(xmlPayload);
try {
System.out.println("Execute POST request for " + postBREL);
// 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();
}
}
public static void main(String[] args)
{
new SampleCreateBRELResource();
}
}