diff --git a/skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/RestfulAPIService.java b/skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/RestfulAPIService.java index 8dfa6092de7799bae19d69c66c461a95a00e0b04..95ce78e7cb5671d4605e47d6239c1d2846838830 100644 --- a/skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/RestfulAPIService.java +++ b/skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/RestfulAPIService.java @@ -2,7 +2,6 @@ package com.a.eye.skywalking.routing.http; import com.a.eye.skywalking.logging.api.ILog; import com.a.eye.skywalking.logging.api.LogManager; -import com.a.eye.skywalking.network.dependencies.com.google.gson.Gson; import com.a.eye.skywalking.routing.http.module.ResponseMessage; import java.io.IOException; @@ -11,20 +10,19 @@ import java.util.Map; import fi.iki.elonen.NanoHTTPD; -import static com.a.eye.skywalking.routing.http.module.ResponseMessage.REQUEST_METHOD_NOT_SUPPORT; +import static com.a.eye.skywalking.routing.http.module.ResponseMessage.GET_NOT_SUPPORT; import static com.a.eye.skywalking.routing.http.module.ResponseMessage.SERVER_ERROR; public class RestfulAPIService extends NanoHTTPD { + public static final String JSON_MIME_TYPE = "application/json"; + private static ILog logger = LogManager.getLogger(RestfulAPIService.class); private static final SpanStorageController spanController = new SpanStorageController(); - public static final String JSON_MIME_TYPE = "application/json"; - private ILog logger = LogManager.getLogger(RestfulAPIService.class); public RestfulAPIService(String host, int port) { super(host, port); } - public void doStart() throws IOException { try { start(NanoHTTPD.SOCKET_READ_TIMEOUT, false); @@ -39,10 +37,10 @@ public class RestfulAPIService extends NanoHTTPD { public Response serve(IHTTPSession session) { if (session.getMethod() != Method.POST) { return newFixedLengthResponse(Response.Status.OK, JSON_MIME_TYPE, - new Gson().toJson(REQUEST_METHOD_NOT_SUPPORT)); + String.valueOf(GET_NOT_SUPPORT)); } - ResponseMessage responseMessage = ResponseMessage.URL_NOT_FOUND; + ResponseMessage responseMessage = ResponseMessage.NOT_FOUND; try { String postData = getPostData(session); if (spanController.isAddAckSpanURI(session.getUri())) { @@ -58,8 +56,7 @@ public class RestfulAPIService extends NanoHTTPD { responseMessage = SERVER_ERROR; } - return newFixedLengthResponse(Response.Status.OK, JSON_MIME_TYPE, new Gson().toJson - (responseMessage)); + return newFixedLengthResponse(Response.Status.OK, JSON_MIME_TYPE, String.valueOf(responseMessage)); } /** diff --git a/skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/module/AckSpanModule.java b/skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/module/AckSpanModule.java index 471f5d12b5845087e7c1960a4dc8285f2a5436f0..1dfd75aa697b0c561bb672c4e07417fd43479473 100644 --- a/skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/module/AckSpanModule.java +++ b/skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/module/AckSpanModule.java @@ -9,13 +9,16 @@ import java.util.Map; /** * Ack span module + *
+ * All fields in this class will be initialized by {@link com.google.gson.Gson#fromJson(String, Class)},
+ * ignore the un-assign values warning.
*/
public class AckSpanModule {
private String traceId;
private String parentLevelId = "";
- private int levelId = 0;
+ private int levelId = 0;
private long cost;
- private int routeKey;
+ private int routeKey;
private Map
+ * All fields in this class will be initialized by {@link com.google.gson.Gson#fromJson(String, Class)},
+ * ignore the un-assign values warning.
*/
public class RequestSpanModule {
private String traceId;
private String parentLevelId = "";
- private int levelId;
- private long startTime;
- private int routeKey;
+ private int levelId;
+ private long startTime;
+ private int routeKey;
private Map
+ * Created by wusheng on 2017/1/13.
+ */
+public enum ResponseMessage {
+ /**
+ * Request span or Ack Span are received and parsed without any errors.
+ */
+ OK(200, "Store success"),
+ /**
+ * Request a no-supported service.
+ */
+ GET_NOT_SUPPORT(405, "Get method not support"),
+ /**
+ * An internal error occurs.
+ */
+ SERVER_ERROR(500, "Server error"),
+ /**
+ * No service found. Also mean not provide this service.
+ */
+ NOT_FOUND(404, "Not found");
/**
- * Response code:
- * 200 -- store success
- * 403 -- request method not support
- * 500 -- server error
- * 404 -- not found
+ * The {@link String} represents the return message of the http services.
+ * It is in the JSON format, and formatted by {@link com.google.gson.Gson}.
*/
- private int code;
private String message;
ResponseMessage(int code, String message) {
- this.code = code;
- this.message = message;
+ JsonObject messageFormatter = new JsonObject();
+ messageFormatter.addProperty("code", code);
+ messageFormatter.addProperty("message", message);
+ this.message = messageFormatter.toString();
}
- public int getCode() {
- return code;
+ /**
+ * @return the return message of the http services.
+ */
+ @Override
+ public String toString() {
+ return message;
}
}