BrightSide Workbench Full Report + Source Code
org.turro.http.ElephantResponse Class Reference

Static Public Member Functions

static boolean isCorrect (ElephantResponse er)
 
static ElephantResponseType getType (ElephantResponse er)
 
static ElephantResponse getResponse (HttpEntity entity) throws IOException
 
static String getResponse (ElephantResponseType type, String message, String code) throws IOException
 
static void writeToResponse (HttpServletResponse response, ElephantResponseType type, String message, String code) throws IOException
 

Public Attributes

String type
 
String message
 
String code
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 40 of file ElephantResponse.java.

Member Function Documentation

◆ getResponse() [1/2]

static String org.turro.http.ElephantResponse.getResponse ( ElephantResponseType  type,
String  message,
String  code 
) throws IOException
static

Definition at line 71 of file ElephantResponse.java.

71  {
72  Gson gson = new GsonBuilder().create();
73  ElephantResponse er = new ElephantResponse();
74  er.type = type.toString();
75  er.message = message;
76  er.code = code;
77  return gson.toJson(er);
78  }

◆ getResponse() [2/2]

static ElephantResponse org.turro.http.ElephantResponse.getResponse ( HttpEntity  entity) throws IOException
static

Definition at line 58 of file ElephantResponse.java.

58  {
59  Gson gson = new GsonBuilder().create();
60  ContentType contentType = ContentType.create(entity.getContentType(), Charsets.toCharset(entity.getContentEncoding()));
61  Charset charset = contentType.getCharset();
62  Reader reader = new InputStreamReader(entity.getContent(), charset);
63  try {
64  return gson.fromJson(reader, ElephantResponse.class);
65  } catch(JsonSyntaxException ex) {
66  Logger.getLogger(ElephantResponse.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
67  }
68  return null;
69  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getType()

static ElephantResponseType org.turro.http.ElephantResponse.getType ( ElephantResponse  er)
static

Definition at line 50 of file ElephantResponse.java.

50  {
51  try {
52  return er != null ? ElephantResponseType.valueOf(er.type) : null;
53  } catch(IllegalArgumentException |NullPointerException ex) {
54  return null;
55  }
56  }
Here is the caller graph for this function:

◆ isCorrect()

static boolean org.turro.http.ElephantResponse.isCorrect ( ElephantResponse  er)
static

Definition at line 46 of file ElephantResponse.java.

46  {
47  return ElephantResponseType.RESPONSE_CORRECT.equals(ElephantResponse.getType(er));
48  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeToResponse()

static void org.turro.http.ElephantResponse.writeToResponse ( HttpServletResponse  response,
ElephantResponseType  type,
String  message,
String  code 
) throws IOException
static

Definition at line 80 of file ElephantResponse.java.

80  {
81  response.setContentType("application/json");
82  response.setCharacterEncoding(ElephantContext.getEncoding());
83  response.getWriter().write(getResponse(type, message, code));
84  }
static ElephantResponse getResponse(HttpEntity entity)
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ code

String org.turro.http.ElephantResponse.code

Definition at line 44 of file ElephantResponse.java.

◆ message

String org.turro.http.ElephantResponse.message

Definition at line 43 of file ElephantResponse.java.

◆ type

String org.turro.http.ElephantResponse.type

Definition at line 42 of file ElephantResponse.java.


The documentation for this class was generated from the following file: