DX Unified Infrastructure Management

 View Only
  • 1.  JAVA SDK - Request return code

    Posted Apr 13, 2017 05:31 AM

    Hi,

     

    Do we have a way with the JAVA SDK to retrieve the return code of the request like we do for all others SDK ? (C,Perl,.Net etc..).

     

    Like this : 

     

    RC = request('...blabla'); 

    if(RC == CONSTANT) { 

    }

    Where the constant is the return code numbers.

     

    If i take the example from the JAVA SDK documentation :

     

          PDS pds = new PDS();       pds.put("id",84);       pds.put("text","alfa");       NimRequest request = new NimRequest("myname","test_mymethod",pds);         PDS pdsret = request.send();

    Even with a try / catch, if the request fail my catch block is not executed ( experienced on my latest JAVA probe ).

    CC :
    BryanKMorrow

    Best Regards,
    Thomas



  • 2.  Re: JAVA SDK - Request return code

    Posted Apr 13, 2017 05:37 AM

    Ok i think i have to getCode() on my NimException in the Catch block if i have right.

     

    But i have case where the callback fail for communication error but the try success. Weird i have to check this (Maybe an issue).



  • 3.  Re: JAVA SDK - Request return code
    Best Answer

    Posted Apr 13, 2017 08:20 AM

    Here is the try catch block I always use for NimRequests. The catch block will return the error code.

     

    public static String getHubAddress() throws NimException {
            NimRequest getHubRequest = null;
            PDS getHubPds = null;
            try {
                getHubRequest = new NimRequest("controller", "gethub");
                getHubPds = getHubRequest.send();
            } catch (NimException e) {
                logger.error("Failed to contact local robot to get hub information. Cause: " + e.getMessage());
                // there is no point to keep on going.
            } finally {
                if (getHubRequest != null) {
                    getHubRequest.disconnect();
                    getHubRequest.close();
                }
            }
            String hubAddress = "/" + getHubPds.getString("hubdomain") + "/" + getHubPds.getString("hubname") + "/" + getHubPds.getString("hubrobotname");
            domain = getHubPds.getString("hubdomain");
            return hubAddress;
        }