Knowledgebase

Search the Rally Knowledgebase to find solutions to your Rally product questions.

This is a public Hive  publicRSS

How To

    Sample basic REST client operations in Java
    How To posted 10/28/08 by Dave Smith , tagged Web Services API
    18883 Views, 1 Comment
    Title:
    Sample basic REST client operations in Java
    Product:
    Rally Enterprise
    Abstract:

    Attached is a sample Java client that does various REST operations using local files. This client basically reproduces some of the functionality that the curl application has ( http://curl.haxx.se/ ).

    How To:

    Attached is a sample Java client that does various REST operations using local files. This client basically reproduces some of the functionality that the curl application has ( http://curl.haxx.se/ ).

    You can make things as complicated or as simple as you like, but it boils down to needing to be able to issue various HTTP requests, and being able to interpret XML that comes back.

    The basics to think about with REST are that HTTP methods translate to different operations, so:

    HTTP PUT == create new object
    HTTP GET == read object
    HTTP POST == update object
    HTTP DELETE == delete object

    All objects in REST have a URI. So, every defect in the system has a unique URI. Queries have unique URIs, etc.. If I want to update some defect, I POST an XML document to that defect's URI. If I want to delete a particular defect, I issue an HTTP DELETE request to that URI, etc.

    Our web services docs ( https://rally1.rallydev.com/slm/doc/webservice ) explains most of this in pretty good detail (click on the "REST" link on the left).

    Code:

    Comments

    • posted 11/19/08 by Eddie

      On updates I was getting the following error using this RESTClient code for a POST (update)

      <?xml version="1.0" encoding="UTF-8"?>

      <OperationResult rallyAPIMajor="1" rallyAPIMinor="9">

        <Errors>

          <OperationResultError>Cannot parse input stream as XML document: Error on line -1: Premature end of file.</OperationResultError>

        </Errors>

        <Warnings />

      </OperationResult>

      To fix this problem I set the content type to "text/xml" with the following line just after the "Authorization" property is set:

      connection.setRequestProperty("Content-Type","text/xml");