com.sonyericsson.hudson.plugins.metadata.cli
Class CliResponse

java.lang.Object
  extended by com.sonyericsson.hudson.plugins.metadata.cli.CliResponse

public final class CliResponse
extends Object

Common util functions for sending HTTP responses in JSON format.

Author:
Robert Sandell <robert.sandell@sonyericsson.com>

Nested Class Summary
static class CliResponse.Type
          A Type of Response that is sent to the client.
 
Field Summary
protected static String CONTENT_TYPE
          The JSON content type to use when writing responses.
 
Method Summary
static net.sf.json.JSONObject createResponse(CliResponse.Type type, int errorCode, String errorName, String message)
          Creates a Response JSON Object.
static void sendError(CliUtils.Status status, String message, org.kohsuke.stapler.StaplerResponse response)
          Sends an error message in json format on the response object.
static void sendIgnored(org.kohsuke.stapler.StaplerResponse response)
          Sends an OK status message with Ignored as the text in JSON format.
static void sendOk(org.kohsuke.stapler.StaplerResponse response)
          Sends an OK status message in JSON format.
static void sendResponse(CliResponse.Type type, int errorCode, String errorName, String message, org.kohsuke.stapler.StaplerResponse response)
          Sends a status message in JSON format.
static void sendResponse(CliResponse.Type type, int errorCode, String errorName, String message, org.kohsuke.stapler.StaplerResponse response, int httpStatus)
          Sends a status message in JSON format.
static void sendResponse(org.kohsuke.stapler.StaplerResponse response, net.sf.json.JSONObject json, int httpStatus)
          Sends the pre-formatted response object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_TYPE

protected static final String CONTENT_TYPE
The JSON content type to use when writing responses.

See Also:
Constant Field Values
Method Detail

sendError

public static void sendError(CliUtils.Status status,
                             String message,
                             org.kohsuke.stapler.StaplerResponse response)
                      throws IOException
Sends an error message in json format on the response object.

Parameters:
status - the status code.
message - the human readable message.
response - the response object to send to.
Throws:
IOException - if so.

sendOk

public static void sendOk(org.kohsuke.stapler.StaplerResponse response)
                   throws IOException
Sends an OK status message in JSON format.

Parameters:
response - the response handle.
Throws:
IOException - if so.

sendIgnored

public static void sendIgnored(org.kohsuke.stapler.StaplerResponse response)
                        throws IOException
Sends an OK status message with Ignored as the text in JSON format.

Parameters:
response - the response handle.
Throws:
IOException - if so.

sendResponse

public static void sendResponse(CliResponse.Type type,
                                int errorCode,
                                String errorName,
                                String message,
                                org.kohsuke.stapler.StaplerResponse response,
                                int httpStatus)
                         throws IOException
Sends a status message in JSON format.

Parameters:
type - the response type (ok, error, warning)
errorCode - the errorCode
errorName - the name of the error if any.
message - the message
response - the response handle.
httpStatus - the HTTP Status code
Throws:
IOException - if so.

sendResponse

public static void sendResponse(CliResponse.Type type,
                                int errorCode,
                                String errorName,
                                String message,
                                org.kohsuke.stapler.StaplerResponse response)
                         throws IOException
Sends a status message in JSON format.

Parameters:
type - the response type (ok, error, warning)
errorCode - the errorCode
errorName - the name of the error if any.
message - the message
response - the response handle.
Throws:
IOException - if so.

sendResponse

public static void sendResponse(org.kohsuke.stapler.StaplerResponse response,
                                net.sf.json.JSONObject json,
                                int httpStatus)
                         throws IOException
Sends the pre-formatted response object.

Parameters:
response - the http response handle to write to.
json - the response object to send.
httpStatus - the HTTP Status code
Throws:
IOException - if so.

createResponse

public static net.sf.json.JSONObject createResponse(CliResponse.Type type,
                                                    int errorCode,
                                                    String errorName,
                                                    String message)
Creates a Response JSON Object.

Parameters:
type - the response type (ok, error, warning)
errorCode - the errorCode
errorName - the name of the error if any.
message - the human readable message
Returns:
the response object, ready to be fed to sendResponse(org.kohsuke.stapler.StaplerResponse, net.sf.json.JSONObject, int)


Copyright © 2004-2013. All Rights Reserved.