19 package org.turro.http;
21 import com.google.gson.Gson;
22 import com.google.gson.GsonBuilder;
23 import com.google.gson.JsonSyntaxException;
24 import java.io.IOException;
25 import java.io.InputStreamReader;
26 import java.io.Reader;
27 import java.nio.charset.Charset;
28 import java.util.logging.Level;
29 import java.util.logging.Logger;
30 import javax.servlet.http.HttpServletResponse;
31 import org.apache.commons.io.Charsets;
32 import org.apache.hc.core5.http.ContentType;
33 import org.apache.hc.core5.http.HttpEntity;
34 import org.turro.elephant.context.ElephantContext;
53 }
catch(IllegalArgumentException |NullPointerException ex) {
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);
65 }
catch(JsonSyntaxException ex) {
72 Gson gson =
new GsonBuilder().create();
77 return gson.toJson(er);
81 response.setContentType(
"application/json");
static String logMsg(String msg)
static String getEncoding()
static String getResponse(ElephantResponseType type, String message, String code)
static ElephantResponse getResponse(HttpEntity entity)
static boolean isCorrect(ElephantResponse er)
static void writeToResponse(HttpServletResponse response, ElephantResponseType type, String message, String code)
static ElephantResponseType getType(ElephantResponse er)