|
| 1 | +/* |
| 2 | + * Copyright 2024 NAVER Corp. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.navercorp.pinpoint.web.controller; |
| 17 | + |
| 18 | +import jakarta.servlet.http.HttpServletResponse; |
| 19 | +import org.springframework.validation.annotation.Validated; |
| 20 | +import org.springframework.web.bind.annotation.GetMapping; |
| 21 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 22 | +import org.springframework.web.bind.annotation.RestController; |
| 23 | + |
| 24 | +import java.io.IOException; |
| 25 | +import java.io.PrintWriter; |
| 26 | + |
| 27 | +/** |
| 28 | + * @author intr3p1d |
| 29 | + */ |
| 30 | +@RestController |
| 31 | +@RequestMapping("/api/errorTest") |
| 32 | +@Validated |
| 33 | +public class ErrorMockController { |
| 34 | + |
| 35 | + @GetMapping(value = "/basicJsonError") |
| 36 | + public void basicJsonError(HttpServletResponse response) throws IOException { |
| 37 | + response.setContentType("text/html"); |
| 38 | + response.setCharacterEncoding("UTF-8"); |
| 39 | + response.setStatus(400); |
| 40 | + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "basicJsonError"); |
| 41 | + |
| 42 | + throw new IOException("basic Json Error"); |
| 43 | + } |
| 44 | + |
| 45 | + @GetMapping(value = "/400requestHeader") |
| 46 | + public void htmlErrorPage(HttpServletResponse response) throws IOException { |
| 47 | + response.setContentType("text/html"); |
| 48 | + response.setCharacterEncoding("UTF-8"); |
| 49 | + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); |
| 50 | + |
| 51 | + PrintWriter writer = response.getWriter(); |
| 52 | + writer.write("<html lang=\"en\"><head><title>HTTP Status 400 – Bad Request</title><style type=\"text/css\">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style><style data-emotion=\"css\" data-s=\"\"></style></head><body><h1>HTTP Status 400 – Bad Request</h1><hr class=\"line\"><p><b>Type</b> Exception Report</p><p><b>Message</b> Request header is too large</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p><p><b>Exception</b></p><pre>java.lang.IllegalArgumentException: Request header is too large\n" + |
| 53 | + "\torg.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:770)\n" + |
| 54 | + "\torg.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:442)\n" + |
| 55 | + "\torg.apache.coyote.http11.Http11Processor.service(Http11Processor.java:264)\n" + |
| 56 | + "\torg.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)\n" + |
| 57 | + "\torg.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896)\n" + |
| 58 | + "\torg.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1744)\n" + |
| 59 | + "\torg.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)\n" + |
| 60 | + "\torg.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)\n" + |
| 61 | + "\torg.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)\n" + |
| 62 | + "\torg.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)\n" + |
| 63 | + "\tjava.base/java.lang.Thread.run(Thread.java:833)\n" + |
| 64 | + "</pre><p><b>Note</b> The full stack trace of the root cause is available in the server logs.</p><hr class=\"line\"><h3>Apache Tomcat/10.1.19</h3><div id=\"__endic_crx__\"><div class=\"css-diqpy0\"></div></div></body></html>"); |
| 65 | + writer.flush(); |
| 66 | + } |
| 67 | + |
| 68 | + @GetMapping(value = "/unterminatedJson") |
| 69 | + public void unterminatedJson(HttpServletResponse response) throws IOException { |
| 70 | + response.setContentType("text/json"); |
| 71 | + response.setCharacterEncoding("UTF-8"); |
| 72 | + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); |
| 73 | + |
| 74 | + PrintWriter writer = response.getWriter(); |
| 75 | + writer.write("[\n" + |
| 76 | + " {\n" + |
| 77 | + " \"_id\": \"66826f1f4b11d4c2bd7e9ab0\",\n" + |
| 78 | + " \"index\": 0,\n" + |
| 79 | + " \"guid\": \"cfedcfa2-2706-43ed-83b7-9c9dfd4a8e46\",\n" + |
| 80 | + " \"isActive\": true,\n" + |
| 81 | + " \"balance\": \"$2,472.51\",\n" + |
| 82 | + " \"picture\": \"http://placehold.it/32x32\",\n" + |
| 83 | + " \"address\": \"826 Clifford Place, Nelson, Arkansas, 3533\",\n" + |
| 84 | + " \"about\": \"Culpa consequat duis elit"); |
| 85 | + |
| 86 | + writer.flush(); |
| 87 | + } |
| 88 | + |
| 89 | + |
| 90 | +} |
0 commit comments