You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2020/03/09 04:24:02 UTC

[GitHub] [skywalking-agent-test-tool] kezhenxu94 commented on a change in pull request #8: Introduce Http Receiver

kezhenxu94 commented on a change in pull request #8: Introduce Http Receiver
URL: https://github.com/apache/skywalking-agent-test-tool/pull/8#discussion_r389457999
 
 

 ##########
 File path: mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/rest/service/JettyJsonHandler.java
 ##########
 @@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.plugin.test.mockcollector.rest.service;
+
+import com.google.gson.JsonElement;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Enumeration;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import static java.util.Objects.nonNull;
+
+public abstract class JettyJsonHandler extends HttpServlet {
+    private static final Logger logger = LogManager.getLogger(JettyJsonHandler.class);
+
+    @Override
+    protected final void doGet(HttpServletRequest req, HttpServletResponse resp) {
+        try {
+            reply(resp, doGet(req));
+        } catch (IOException e) {
+            try {
+                replyError(resp, e.getMessage(), HttpServletResponse.SC_BAD_REQUEST);
+            } catch (IOException replyException) {
+                logger.error(replyException.getMessage(), e);
+            }
+        }
+    }
+
+    protected abstract JsonElement doGet(HttpServletRequest req);
+
+    @Override
+    protected final void doPost(HttpServletRequest req, HttpServletResponse resp) {
+        try {
+            reply(resp, doPost(req));
+        } catch (IOException e) {
+            try {
+                replyError(resp, e.getMessage(), HttpServletResponse.SC_BAD_REQUEST);
+            } catch (IOException replyException) {
+                logger.error(replyException.getMessage(), e);
+            }
+        }
+    }
+
+    protected abstract JsonElement doPost(HttpServletRequest req) throws IOException;
+
+    @Override
+    protected final void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+        super.doHead(req, resp);
+    }
 
 Review comment:
   make no sense to override and simply call `super`, same as below, so many useless methods

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services