Skip to content

Commit

Permalink
Checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
kifj committed Nov 29, 2024
1 parent cdcd5db commit d14ed66
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.1</version>
<version>3.5.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -606,7 +606,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.5.1</version>
<version>3.5.2</version>
<reportSets>
<reportSet>
<reports>
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/x1/stomp/boundary/ExceptionMapperBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@
import org.slf4j.MDC;
import static x1.stomp.boundary.MDCFilter.HTTP_STATUS_CODE;

import java.net.URI;

/**
* Base class for ExceptionMapper with MDC logging
*/
public abstract class ExceptionMapperBase {
private final Logger log = LoggerFactory.getLogger(ExceptionMapperBase.class);

@Context
protected UriInfo uriInfo;

private UriInfo uriInfo;

protected URI getRequestUri() {
return uriInfo.getRequestUri();
}

protected void debug(Status status, String message, Object... args) {
try {
MDC.put(HTTP_STATUS_CODE, Integer.toString(status.getStatusCode()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class FaultToleranceExceptionMapper extends ExceptionMapperBase implement
public Response toResponse(FaultToleranceException e) {
var response = new ErrorResponse(e.getClass().getSimpleName());
var status = SERVICE_UNAVAILABLE;
response.setRequestUri(uriInfo.getRequestUri().toString());
response.setRequestUri(getRequestUri().toString());
response.add(ErrorMessage.from(e));
warn(status, "Service not available due to:\n{}", response.toString());
return Response.status(status).entity(response).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class RuntimeExceptionMapper extends ExceptionMapperBase implements Excep
public Response toResponse(RuntimeException e) {
// will be logged by LoggingInterceptor
var response = new ErrorResponse(e.getClass().getSimpleName());
response.setRequestUri(uriInfo.getRequestUri().toString());
response.setRequestUri(getRequestUri().toString());
response.add(ErrorMessage.from(e));
return Response.status(INTERNAL_SERVER_ERROR).entity(response).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ValidationExceptionMapper extends ExceptionMapperBase implements Ex
public Response toResponse(ConstraintViolationException e) {
var response = new ErrorResponse("Invalid data");
var status = BAD_REQUEST;
response.setRequestUri(uriInfo.getRequestUri().toString());
response.setRequestUri(getRequestUri().toString());
e.getConstraintViolations().forEach(violation -> response.add(ErrorMessage.of(violation)));
info(status, "Request failed because of invalid parameters:\n{}", response.toString());
return Response.status(status).entity(response).build();
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/x1/stomp/model/JaxbSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
import jakarta.xml.bind.annotation.adapters.XmlAdapter;

/**
* copied from jakarta.ws.rs.core where this is deprecated
* copied from jakarta.ws.rs.core where this is deprecated
*/
public final class JaxbSupport {
private JaxbSupport() {}

private JaxbSupport() {
}

public static class JaxbLink {

private URI uri;
Expand Down Expand Up @@ -90,25 +91,25 @@ public int hashCode() {
}

}

public static class JaxbAdapter extends XmlAdapter<JaxbLink, Link> {

@Override
public Link unmarshal(final JaxbLink v) {
var lb = Link.fromUri(v.getUri());
for (var e : v.getParams().entrySet()) {
lb.param(e.getKey().getLocalPart(), e.getValue().toString());
}
return lb.build();
var lb = Link.fromUri(v.getUri());
for (var e : v.getParams().entrySet()) {
lb.param(e.getKey().getLocalPart(), e.getValue().toString());
}
return lb.build();
}

@Override
public JaxbLink marshal(final Link v) {
var jl = new JaxbLink(v.getUri());
for (var e : v.getParams().entrySet()) {
jl.getParams().put(new QName("", e.getKey()), e.getValue());
}
return jl;
var jl = new JaxbLink(v.getUri());
for (var e : v.getParams().entrySet()) {
jl.getParams().put(new QName("", e.getKey()), e.getValue());
}
return jl;
}
}
}
}

0 comments on commit d14ed66

Please sign in to comment.