com.thetransactioncompany.jsonrpc2
Class JSONRPC2Error

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by com.thetransactioncompany.jsonrpc2.JSONRPC2Error
All Implemented Interfaces:
java.io.Serializable

public class JSONRPC2Error
extends java.lang.Exception

Represents a JSON-RPC 2.0 error that occured during the processing of a request.

The protocol expects error objects to be structured like this:

Note that the "Error" word in the class name was put there solely to comply with the parlance of the JSON-RPC spec. This class doesn't inherit from java.lang.Error. It's a regular subclass of java.lang.Exception and, if thrown, it's to indicate a condition that a reasonable application might want to catch.

This class also includes convenient final static instances for all standard JSON-RPC 2.0 errors:

Note that the range -32099..-32000 is reserved for additional server errors.

The mapping between JSON and Java entities (as defined by the underlying JSON.simple library):

     true|false  <--->  java.lang.Boolean
     number      <--->  java.lang.Number
     string      <--->  java.lang.String
     array       <--->  java.util.List
     object      <--->  java.util.Map
     null        <--->  null
 

The JSON-RPC 2.0 specification and user group forum can be found here.

Version:
1.9.1 (2010-03-15)
Author:
Vladimir Dzhuvinov
See Also:
Serialized Form

Field Summary
static JSONRPC2Error INTERNAL_ERROR
          Internal JSON-RPC 2.0 error (-32603)
static JSONRPC2Error INVALID_PARAMS
          Invalid parameters error (-32602)
static JSONRPC2Error INVALID_REQUEST
          Invalid JSON-RPC 2.0 request error (-32600)
static JSONRPC2Error METHOD_NOT_FOUND
          Method not found error (-32601)
static JSONRPC2Error PARSE_ERROR
          JSON parse error (-32700)
 
Constructor Summary
JSONRPC2Error(int code, java.lang.String message)
          Creates a new JSON-RPC 2.0 error with the specified code and message.
JSONRPC2Error(int code, java.lang.String message, java.lang.Object data)
          Creates a new JSON-RPC 2.0 error with the specified code, message and data.
 
Method Summary
 int getCode()
          Gets the JSON-RPC 2.0 error code.
 java.lang.Object getData()
          Gets the JSON-RPC 2.0 error data.
static void main(java.lang.String[] args)
           
 org.json.simple.JSONObject toJSON()
          Gets a JSON representation of the JSON-RPC 2.0 error.
 java.lang.String toString()
          Serialises the error object to a JSON string.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PARSE_ERROR

public static final JSONRPC2Error PARSE_ERROR
JSON parse error (-32700)


INVALID_REQUEST

public static final JSONRPC2Error INVALID_REQUEST
Invalid JSON-RPC 2.0 request error (-32600)


METHOD_NOT_FOUND

public static final JSONRPC2Error METHOD_NOT_FOUND
Method not found error (-32601)


INVALID_PARAMS

public static final JSONRPC2Error INVALID_PARAMS
Invalid parameters error (-32602)


INTERNAL_ERROR

public static final JSONRPC2Error INTERNAL_ERROR
Internal JSON-RPC 2.0 error (-32603)

Constructor Detail

JSONRPC2Error

public JSONRPC2Error(int code,
                     java.lang.String message)
Creates a new JSON-RPC 2.0 error with the specified code and message. The optional data is omitted.

Parameters:
code - The error code (standard pre-defined or application-specific)
message - The error message

JSONRPC2Error

public JSONRPC2Error(int code,
                     java.lang.String message,
                     java.lang.Object data)
Creates a new JSON-RPC 2.0 error with the specified code, message and data.

Parameters:
code - The error code (standard pre-defined or application-specific)
message - The error message
data - Optional error data, must map to a valid JSON type.
Method Detail

getCode

public int getCode()
Gets the JSON-RPC 2.0 error code.

Returns:
The error code.

getData

public java.lang.Object getData()
Gets the JSON-RPC 2.0 error data.

Returns:
The error data, null if none was specified.

toJSON

public org.json.simple.JSONObject toJSON()
Gets a JSON representation of the JSON-RPC 2.0 error.

Returns:
A JSON object representing this error object.

toString

public java.lang.String toString()
Serialises the error object to a JSON string.

Overrides:
toString in class java.lang.Throwable
Returns:
A JSON-encoded string representing this error object.

main

public static void main(java.lang.String[] args)


Copyright © 2009-2010 Vladimir Dzhuvinov. All Rights Reserved.