Skip to content

Commit 628df25

Browse files
committed
Adjust logging configuration
1 parent 9eecd83 commit 628df25

File tree

11 files changed

+27
-20
lines changed

11 files changed

+27
-20
lines changed

trellis-webdav/src/test/java/org/trellisldp/webdav/DebugExceptionMapper.java renamed to trellis-http/src/main/java/org/trellisldp/http/WebApplicationExceptionMapper.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,25 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.trellisldp.webdav;
17-
18-
import static java.util.Optional.of;
16+
package org.trellisldp.http;
1917

2018
import jakarta.ws.rs.WebApplicationException;
2119
import jakarta.ws.rs.core.Response;
2220
import jakarta.ws.rs.ext.ExceptionMapper;
2321
import jakarta.ws.rs.ext.Provider;
2422

23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
2526
@Provider
26-
public class DebugExceptionMapper implements ExceptionMapper<Exception> {
27+
public class WebApplicationExceptionMapper implements ExceptionMapper<WebApplicationException> {
2728

28-
@Override
29-
public Response toResponse(final Exception err) {
30-
err.printStackTrace();
29+
private static final Logger LOGGER = LoggerFactory.getLogger(WebApplicationExceptionMapper.class);
3130

32-
if (err instanceof WebApplicationException) {
33-
return ((WebApplicationException) err).getResponse();
34-
}
35-
return of(err).map(Throwable::getCause).filter(WebApplicationException.class::isInstance)
36-
.map(WebApplicationException.class::cast).orElseGet(() -> new WebApplicationException(err)).getResponse();
31+
@Override
32+
public Response toResponse(final WebApplicationException err) {
33+
LOGGER.debug("Unhandled web application exception", err);
3734

35+
return err.getResponse();
3836
}
3937
}

trellis-http/src/main/java/org/trellisldp/http/impl/GetHandler.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import static org.trellisldp.http.impl.HttpUtils.unskolemizeTriples;
6464

6565
import jakarta.ws.rs.ClientErrorException;
66+
import jakarta.ws.rs.InternalServerErrorException;
6667
import jakarta.ws.rs.NotAcceptableException;
6768
import jakarta.ws.rs.NotFoundException;
6869
import jakarta.ws.rs.RedirectionException;
@@ -383,8 +384,12 @@ private CompletionStage<ResponseBuilder> getLdpNr(final ResponseBuilder builder)
383384
}
384385

385386
private static void copy(final InputStream from, final OutputStream to) throws IOException {
386-
from.transferTo(to);
387-
from.close();
387+
if (from != null) {
388+
from.transferTo(to);
389+
from.close();
390+
} else {
391+
throw new InternalServerErrorException("Invalid data stream");
392+
}
388393
}
389394

390395
private CompletionStage<InputStream> getBinaryStream(final IRI dsid, final TrellisRequest req) {

trellis-http/src/main/java/org/trellisldp/http/impl/PostHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ public ResponseBuilder initialize(final Resource parent, final Resource child) {
148148
throw new BadRequestException("Unsupported interaction model provided", status(BAD_REQUEST)
149149
.link(UnsupportedInteractionModel.getIRIString(), LDP.constrainedBy.getIRIString()).build());
150150
} else if (ldpType.equals(LDP.NonRDFSource) && rdfSyntax != null) {
151-
LOGGER.error("Cannot save {} as a NonRDFSource with RDF syntax", getIdentifier());
152151
throw new BadRequestException("Cannot save resource as a NonRDFSource with RDF syntax");
153152
}
154153

trellis-http/src/main/java/org/trellisldp/http/impl/PutHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ public CompletionStage<ResponseBuilder> setResource(final ResponseBuilder builde
160160

161161
// It is not possible to change the LDP type to a type that is not a subclass
162162
if (hasInteractionModelChangeRestriction(ldpType)) {
163-
LOGGER.error("Cannot change the LDP type to {} for {}", ldpType, getIdentifier());
164163
throw new ClientErrorException("Cannot change the LDP type to " + ldpType, status(CONFLICT).build());
165164
}
166165

trellis-http/src/test/java/org/trellisldp/http/TrellisHttpResourceBaseUrlTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ protected Application configure() {
4848
System.setProperty(CONFIG_HTTP_BASE_URL, URL);
4949

5050
final ResourceConfig config = new ResourceConfig();
51+
config.register(new WebApplicationExceptionMapper());
5152
config.register(new TrellisHttpResource());
5253
config.register(new TestAuthenticationFilter("testUser", "group"));
5354
config.register(new CacheControlFilter());

trellis-http/src/test/java/org/trellisldp/http/TrellisHttpResourceNoAgentTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected Application configure() {
4646
System.setProperty(CONFIG_HTTP_BASE_URL, baseUri);
4747

4848
final ResourceConfig config = new ResourceConfig();
49+
config.register(new WebApplicationExceptionMapper());
4950
config.register(new TrellisHttpResource());
5051
config.register(new CacheControlFilter());
5152
config.register(new WebSubHeaderFilter());

trellis-http/src/test/java/org/trellisldp/http/TrellisHttpResourceTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ protected Application configure() {
8282
System.setProperty(CONFIG_HTTP_BASE_URL, getBaseUrl());
8383

8484
final ResourceConfig config = new ResourceConfig();
85+
config.register(new WebApplicationExceptionMapper());
8586
config.register(new TrellisHttpResource());
8687
config.register(new CacheControlFilter());
8788
config.register(new TrellisHttpFilter());

trellis-http/src/test/java/org/trellisldp/http/TrellisHttpResourceUserTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected Application configure() {
3939
System.clearProperty(CONFIG_HTTP_BASE_URL);
4040

4141
final ResourceConfig config = new ResourceConfig();
42+
config.register(new WebApplicationExceptionMapper());
4243
config.register(new TrellisHttpResource());
4344
config.register(new TestAuthenticationFilter("testUser", "group"));
4445
config.register(new CacheControlFilter());

trellis-webdav/src/main/java/org/trellisldp/webdav/TrellisWebDAV.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ private Resource checkResource(final Resource res) {
337337
private Response handleException(final Throwable err) {
338338
final Throwable cause = err.getCause();
339339
if (cause instanceof WebApplicationException) return ((WebApplicationException) cause).getResponse();
340-
LOGGER.error("Trellis WebDAV Error: {}", err.getMessage());
341-
LOGGER.debug("WebDAV error", err);
340+
LOGGER.debug("WebDAV error: {}", err.getMessage());
341+
LOGGER.trace("WebDAV error", err);
342342
return new WebApplicationException(err).getResponse();
343343
}
344344

trellis-webdav/src/test/java/org/trellisldp/webdav/WebDAVNoBaseUrlTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.junit.jupiter.api.TestInstance;
3333
import org.trellisldp.common.ServiceBundler;
3434
import org.trellisldp.http.TrellisHttpResource;
35+
import org.trellisldp.http.WebApplicationExceptionMapper;
3536

3637
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
3738
class WebDAVNoBaseUrlTest extends AbstractWebDAVTest {
@@ -85,7 +86,7 @@ public Application configure() {
8586
dav.init();
8687

8788
config.register(dav);
88-
config.register(new DebugExceptionMapper());
89+
config.register(new WebApplicationExceptionMapper());
8990
config.register(new TestAuthnFilter("testUser", ""));
9091
config.register(new TrellisWebDAVRequestFilter());
9192
config.register(new TrellisWebDAVResponseFilter());

trellis-webdav/src/test/java/org/trellisldp/webdav/WebDAVTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.junit.jupiter.api.TestInstance;
2727
import org.trellisldp.common.ServiceBundler;
2828
import org.trellisldp.http.TrellisHttpResource;
29+
import org.trellisldp.http.WebApplicationExceptionMapper;
2930

3031
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
3132
class WebDAVTest extends AbstractWebDAVTest {
@@ -42,7 +43,7 @@ protected Application configure() {
4243
dav.init();
4344

4445
config.register(dav);
45-
config.register(new DebugExceptionMapper());
46+
config.register(new WebApplicationExceptionMapper());
4647
config.register(new TrellisWebDAVRequestFilter());
4748
config.register(new TrellisWebDAVResponseFilter());
4849
config.register(new TrellisHttpResource());

0 commit comments

Comments
 (0)