TrustedRequest for bamboo REST call returns 401 error code

I am trying to execute a bamboo REST call to clone a plan via TrustedRequest for a bamboo plugin, but I get 401 status code.

Is TrustedRequest not supported by Bamboo ?

Following is the code I am working with

final String baseUrl = applicationProperties.getBaseUrl(UrlMode.CANONICAL) ;
     final String url = baseUrl+

     String hostString = "localhost";
     try {
        URL hostUrl = new URL(baseUrl);
        hostString = hostUrl.getHost();
     } catch (MalformedURLException e) {
        LOG.error("Error trying to get host from the base url.\n\n" + e);

     try {
        //here requestFactory is referencing the instance of com.atlassian.sal.bamboo.trusted.BambooHttpClientTrustedRequestFactory@7cb03893
        //and request is referencing the instance of
        TrustedRequest request =
           requestFactory.createTrustedRequest(MethodType.PUT, url);
        // add machine name

        request.execute(new ResponseHandler<Response>() {

           public void handle(
              final Response response) throws ResponseException {
              if (response.getStatusCode() != HttpStatus.SC_OK) {
       "REST call " + url + " response text - " +
     } catch (ResponseException e) {
        LOG.error("Exception calling bamboo plan clone REST API:", e);

The response body text I receive is

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
         <message>Client must be authenticated to access this resource.

I am using Atlassian SDK 6.2.14 with AMPS version 6.2.11. The bamboo version I am working with is 6.5.1