forked from pinpoint-apm/pinpoint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pinpoint-apm#12021] Replace ErrorAttributes with Problem
- Loading branch information
Showing
13 changed files
with
236 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
web/src/main/java/com/navercorp/pinpoint/web/ExceptionHandling.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2025 NAVER Corp. | ||
* | ||
* Licensed 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 com.navercorp.pinpoint.web; | ||
|
||
import com.navercorp.pinpoint.web.problem.ProblemWrapper; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.context.request.NativeWebRequest; | ||
import org.zalando.problem.Problem; | ||
import org.zalando.problem.spring.web.advice.ProblemHandling; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
|
||
/** | ||
* @author intr3p1d | ||
*/ | ||
@ControllerAdvice | ||
final class ExceptionHandling implements ProblemHandling { | ||
|
||
private final String hostname; | ||
|
||
ExceptionHandling() { | ||
this.hostname = getHostName(); | ||
} | ||
|
||
static private String getHostName() { | ||
try { | ||
return InetAddress.getLocalHost().getHostName(); | ||
} catch (UnknownHostException e) { | ||
return "unknown"; | ||
} | ||
} | ||
|
||
@Override | ||
public ResponseEntity<Problem> process(ResponseEntity<Problem> entity, NativeWebRequest request) { | ||
Problem originalProblem = entity.getBody(); | ||
if (originalProblem == null) { | ||
return entity; | ||
} | ||
|
||
HttpServletRequest httpRequest = request.getNativeRequest(HttpServletRequest.class); | ||
HttpServletResponse httpResponse = request.getNativeResponse(HttpServletResponse.class); | ||
|
||
String path = (httpRequest != null) ? httpRequest.getRequestURI() : "unknown"; | ||
String method = (httpRequest != null) ? httpRequest.getMethod() : "unknown"; | ||
int statusCode = (httpResponse != null) ? httpResponse.getStatus() : entity.getStatusCode().value(); | ||
|
||
Problem modifiedProblem = new ProblemWrapper(originalProblem, hostname, path, method); | ||
return ResponseEntity.status(statusCode).body(modifiedProblem); | ||
} | ||
|
||
@Override | ||
public boolean isCausalChainsEnabled() { | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
web/src/main/java/com/navercorp/pinpoint/web/ProblemSpringWebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2025 NAVER Corp. | ||
* | ||
* Licensed 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 com.navercorp.pinpoint.web; | ||
|
||
import com.navercorp.pinpoint.web.problem.ProblemWrapper; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; | ||
import org.zalando.problem.Problem; | ||
import org.zalando.problem.jackson.ProblemModule; | ||
import org.zalando.problem.spring.web.advice.AdviceTrait; | ||
import org.zalando.problem.violations.ConstraintViolationProblemModule; | ||
|
||
/** | ||
* @author intr3p1d | ||
*/ | ||
@Configuration | ||
public class ProblemSpringWebConfig { | ||
@Bean | ||
public Jackson2ObjectMapperBuilderCustomizer addCustomBigDecimalDeserialization( | ||
@Qualifier("pinpointWebProblemModule") ProblemModule problemModule, | ||
@Qualifier("pinpointConstraintViolationProblemModule") ConstraintViolationProblemModule constraintViolationProblemModule | ||
) { | ||
return (Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) -> | ||
jacksonObjectMapperBuilder.modules( | ||
problemModule, constraintViolationProblemModule | ||
).mixIn(Problem.class, ProblemWrapper.class); | ||
} | ||
|
||
@Bean | ||
public ProblemModule pinpointWebProblemModule() { | ||
return new ProblemModule().withStackTraces(true); | ||
} | ||
|
||
@Bean | ||
public ConstraintViolationProblemModule pinpointConstraintViolationProblemModule() { | ||
return new ConstraintViolationProblemModule(); | ||
} | ||
|
||
@Bean | ||
@Primary | ||
public AdviceTrait pinpointExceptionHandling() { | ||
return new ExceptionHandling(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 0 additions & 114 deletions
114
web/src/main/java/com/navercorp/pinpoint/web/controller/NonWhiteLabelErrorController.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.