Skip to content

Commit 8902fb8

Browse files
committed
fixes 108: Do not verbosely log non-existence of entity when performing HEAD request
A HEAD request can be performed to check if an entity exists. If the answer is 'no' (represented by a 404 status code), then this should not be logged on a level that automatically gets written to a log file. This prevents cluttering of the log file.
1 parent d5b8491 commit 8902fb8

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

changelog.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ <h1>
4646

4747
<p><b>1.8.1</b> ???</p>
4848
<ul>
49+
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/108'>#108</a>] - On existence (HEAD) check, do not log absence of entity verbosely.</li>
4950
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/105'>#105</a>] - New endpoints for bulk operations on MUC room affiliations.</li>
5051
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/102'>#102</a>] - Reduce log level of error responses.</li>
5152
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/99'>#99</a>] - Fix hard-coded link to localhost for OpenAPI yaml link in docs.</li>

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<description>Allows administration over a RESTful API.</description>
77
<author>Roman Soldatow</author>
88
<version>${project.version}</version>
9-
<date>2022-06-01</date>
9+
<date>2022-06-22</date>
1010
<minServerVersion>4.7.0</minServerVersion>
1111
<adminconsole>
1212
<tab id="tab-server">

src/java/org/jivesoftware/openfire/plugin/rest/exceptions/RESTExceptionMapper.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@
1616

1717
package org.jivesoftware.openfire.plugin.rest.exceptions;
1818

19-
import java.util.List;
19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
2021

21-
import javax.ws.rs.core.Context;
22-
import javax.ws.rs.core.HttpHeaders;
23-
import javax.ws.rs.core.MediaType;
24-
import javax.ws.rs.core.Response;
22+
import javax.servlet.http.HttpServletRequest;
23+
import javax.ws.rs.core.*;
2524
import javax.ws.rs.core.Response.ResponseBuilder;
2625
import javax.ws.rs.ext.ExceptionMapper;
2726
import javax.ws.rs.ext.Provider;
28-
29-
import org.slf4j.Logger;
30-
import org.slf4j.LoggerFactory;
27+
import java.util.List;
3128

3229
/**
3330
* The Class RESTExceptionMapper.
@@ -41,7 +38,9 @@ public class RESTExceptionMapper implements ExceptionMapper<ServiceException> {
4138
/** The headers. */
4239
@Context
4340
private HttpHeaders headers;
44-
41+
42+
@Context
43+
private HttpServletRequest request;
4544

4645
/**
4746
* Instantiates a new REST exception mapper.
@@ -64,6 +63,9 @@ public Response toResponse(ServiceException exception) {
6463
LOG.warn(
6564
exception.getException() + ": " + exception.getMessage() + " with resource "
6665
+ exception.getResource(), exception.getException());
66+
} else if (exception.getStatus().getStatusCode() == 404 && "HEAD".equalsIgnoreCase(request.getMethod())) {
67+
// This is an existence check that has a 'nope' answer that is perfectly valid. This should not be logged by default.
68+
LOG.debug(exception.getException() + ": " + exception.getMessage() + " with resource " + exception.getResource());
6769
} else {
6870
LOG.info(
6971
exception.getException() + ": " + exception.getMessage() + " with resource "

0 commit comments

Comments
 (0)