This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit d481581f9dcd3c7c012160c60066fb086754fc5f Author: Tran Tien Duc <[email protected]> AuthorDate: Tue Apr 7 15:31:10 2020 +0700 JAMES-2891 Remove JMAPRoutes.logger() --- .../org/apache/james/jmap/http/AuthenticationRoutes.java | 13 ++++--------- .../java/org/apache/james/jmap/http/DownloadRoutes.java | 9 ++------- .../main/java/org/apache/james/jmap/http/JMAPApiRoutes.java | 9 ++------- .../main/java/org/apache/james/jmap/http/UploadRoutes.java | 7 +------ .../scala/org/apache/james/jmap/http/SessionRoutes.scala | 5 ++--- .../main/scala/org/apache/james/jmap/model/Session.scala | 6 ++---- .../apache/james/jmap/json/SessionSerializationTest.scala | 10 ++-------- .../src/main/java/org/apache/james/jmap/JMAPRoutes.java | 10 ++++------ .../src/test/java/org/apache/james/jmap/JMAPServerTest.java | 5 ----- 9 files changed, 19 insertions(+), 55 deletions(-) diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/AuthenticationRoutes.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/AuthenticationRoutes.java index f824da2..a968480 100644 --- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/AuthenticationRoutes.java +++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/AuthenticationRoutes.java @@ -100,11 +100,6 @@ public class AuthenticationRoutes implements JMAPRoutes { } @Override - public Logger logger() { - return LOGGER; - } - - @Override public Stream<JMAPRoute> routes() { return Stream.of( JMAPRoute.builder() @@ -141,7 +136,7 @@ public class AuthenticationRoutes implements JMAPRoutes { throw new RuntimeException(objectRequest.getClass() + " " + objectRequest); } }))) - .onErrorResume(BadRequestException.class, e -> handleBadRequest(response, e)) + .onErrorResume(BadRequestException.class, e -> handleBadRequest(response, LOGGER, e)) .doOnEach(logOnError(e -> LOGGER.error("Unexpected error", e))) .onErrorResume(e -> handleInternalError(response, e)) .subscriberContext(jmapContext(request)) @@ -153,10 +148,10 @@ public class AuthenticationRoutes implements JMAPRoutes { return authenticator.authenticate(req) .flatMap(session -> returnEndPointsResponse(resp) .subscriberContext(jmapAuthContext(session))) - .onErrorResume(BadRequestException.class, e -> handleBadRequest(resp, e)) + .onErrorResume(BadRequestException.class, e -> handleBadRequest(resp, LOGGER, e)) .doOnEach(logOnError(e -> LOGGER.error("Unexpected error", e))) .onErrorResume(InternalErrorException.class, e -> handleInternalError(resp, e)) - .onErrorResume(UnauthorizedException.class, e -> handleAuthenticationFailure(resp, e)) + .onErrorResume(UnauthorizedException.class, e -> handleAuthenticationFailure(resp, LOGGER, e)) .subscriberContext(jmapContext(req)) .subscriberContext(jmapAction("returnEndPoints")) .subscribeOn(Schedulers.elastic()); @@ -186,7 +181,7 @@ public class AuthenticationRoutes implements JMAPRoutes { .flatMap(session -> Mono.from(accessTokenManager.revoke(AccessToken.fromString(authorizationHeader))) .then(resp.status(NO_CONTENT).send().then()) .subscriberContext(jmapAuthContext(session))) - .onErrorResume(UnauthorizedException.class, e -> handleAuthenticationFailure(resp, e)) + .onErrorResume(UnauthorizedException.class, e -> handleAuthenticationFailure(resp, LOGGER, e)) .subscriberContext(jmapContext(req)) .subscriberContext(jmapAction("auth-delete")) .subscribeOn(Schedulers.elastic()); diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/DownloadRoutes.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/DownloadRoutes.java index 21ac5a9..160bdde 100644 --- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/DownloadRoutes.java +++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/DownloadRoutes.java @@ -93,11 +93,6 @@ public class DownloadRoutes implements JMAPRoutes { } @Override - public Logger logger() { - return LOGGER; - } - - @Override public Stream<JMAPRoute> routes() { return Stream.of( JMAPRoute.builder() @@ -145,7 +140,7 @@ public class DownloadRoutes implements JMAPRoutes { .flatMap(session -> Mono.from(metricFactory.runPublishingTimerMetric("JMAP-download-post", respondAttachmentAccessToken(session, downloadPath, response))) .subscriberContext(jmapAuthContext(session))) - .onErrorResume(UnauthorizedException.class, e -> handleAuthenticationFailure(response, e)) + .onErrorResume(UnauthorizedException.class, e -> handleAuthenticationFailure(response, LOGGER, e)) .doOnEach(logOnError(e -> LOGGER.error("Unexpected error", e))) .onErrorResume(e -> handleInternalError(response, e)) .subscriberContext(jmapContext(request)) @@ -175,7 +170,7 @@ public class DownloadRoutes implements JMAPRoutes { .flatMap(session -> Mono.from(metricFactory.runPublishingTimerMetric("JMAP-download-get", download(session, downloadPath, response))) .subscriberContext(jmapAuthContext(session))) - .onErrorResume(UnauthorizedException.class, e -> handleAuthenticationFailure(response, e)) + .onErrorResume(UnauthorizedException.class, e -> handleAuthenticationFailure(response, LOGGER, e)) .doOnEach(logOnError(e -> LOGGER.error("Unexpected error", e))) .onErrorResume(e -> handleInternalError(response, e)) .subscriberContext(jmapContext(request)) diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/JMAPApiRoutes.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/JMAPApiRoutes.java index 68c51c4..deea975 100644 --- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/JMAPApiRoutes.java +++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/JMAPApiRoutes.java @@ -80,11 +80,6 @@ public class JMAPApiRoutes implements JMAPRoutes { } @Override - public Logger logger() { - return LOGGER; - } - - @Override public Stream<JMAPRoute> routes() { return Stream.of( JMAPRoute.builder() @@ -106,8 +101,8 @@ public class JMAPApiRoutes implements JMAPRoutes { .then(Mono.from(metricFactory.runPublishingTimerMetric("JMAP-request", post(request, response, session)))) .subscriberContext(jmapAuthContext(session))) - .onErrorResume(BadRequestException.class, e -> handleBadRequest(response, e)) - .onErrorResume(UnauthorizedException.class, e -> handleAuthenticationFailure(response, e)) + .onErrorResume(BadRequestException.class, e -> handleBadRequest(response, LOGGER, e)) + .onErrorResume(UnauthorizedException.class, e -> handleAuthenticationFailure(response, LOGGER, e)) .doOnEach(logOnError(e -> LOGGER.error("Unexpected error", e))) .onErrorResume(e -> handleInternalError(response, e)) .subscriberContext(jmapContext(request)) diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/UploadRoutes.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/UploadRoutes.java index 5629608..5605b13 100644 --- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/UploadRoutes.java +++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/UploadRoutes.java @@ -82,11 +82,6 @@ public class UploadRoutes implements JMAPRoutes { } @Override - public Logger logger() { - return LOGGER; - } - - @Override public Stream<JMAPRoute> routes() { return Stream.of( JMAPRoute.builder() @@ -110,7 +105,7 @@ public class UploadRoutes implements JMAPRoutes { .subscriberContext(jmapAuthContext(session))) .onErrorResume(CancelledUploadException.class, e -> handleCanceledUpload(response, e)) .onErrorResume(BadRequestException.class, e -> handleBadRequest(response, e)) - .onErrorResume(UnauthorizedException.class, e -> handleAuthenticationFailure(response, e)) + .onErrorResume(UnauthorizedException.class, e -> handleAuthenticationFailure(response, LOGGER, e)) .doOnEach(logOnError(e -> LOGGER.error("Unexpected error", e))) .onErrorResume(e -> handleInternalError(response, e)) .subscriberContext(jmapContext(request)) diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/http/SessionRoutes.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/http/SessionRoutes.scala index 75a280b..901ef64 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/http/SessionRoutes.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/http/SessionRoutes.scala @@ -27,7 +27,7 @@ import javax.inject.Inject import org.apache.james.jmap.HttpConstants.JSON_CONTENT_TYPE_UTF8 import org.apache.james.jmap.JMAPRoutes import org.apache.james.jmap.exceptions.UnauthorizedException -import org.apache.james.jmap.http.SessionRoutes.JMAP_SESSION +import org.apache.james.jmap.http.SessionRoutes.{JMAP_SESSION, LOGGER} import org.apache.james.jmap.json.Serializer import org.apache.james.jmap.model.Session import org.reactivestreams.Publisher @@ -48,7 +48,6 @@ class SessionRoutes(val authFilter: Authenticator, val sessionSupplier: SessionSupplier = new SessionSupplier(), val serializer: Serializer = new Serializer()) extends JMAPRoutes { - val logger: Logger = SessionRoutes.LOGGER private val generateSession: BiFunction[HttpServerRequest, HttpServerResponse, Publisher[Void]] = (request, response) => SMono.fromPublisher(authFilter.authenticate(request)) .map(_.getUser) @@ -69,7 +68,7 @@ class SessionRoutes(val authFilter: Authenticator, def errorHandling(throwable: Throwable, response: HttpServerResponse): Mono[Void] = throwable match { - case _: UnauthorizedException => handleAuthenticationFailure(response, throwable) + case _: UnauthorizedException => handleAuthenticationFailure(response, LOGGER, throwable) case _ => handleInternalError(response, throwable) } } diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Session.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Session.scala index 0bb733d..1b09946 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Session.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Session.scala @@ -61,10 +61,8 @@ object Account { isPersonal: IsPersonal, isReadOnly: IsReadOnly, accountCapabilities: Set[_ <: Capability]): Either[IllegalArgumentException, Account] = - AccountId.from(name) match { - case Left(ex: IllegalArgumentException) => Left(ex) - case Right(accountId) => Right(new Account(accountId, name, isPersonal, isReadOnly, accountCapabilities)) - } + AccountId.from(name) + .map(Account(_, name, isPersonal, isReadOnly, accountCapabilities)) def unapplyIgnoreAccountId(account: Account): Some[(Username, IsPersonal, IsReadOnly, Set[_ <: Capability])] = Some(account.name, account.isPersonal, account.isReadOnly, account.accountCapabilities) diff --git a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/SessionSerializationTest.scala b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/SessionSerializationTest.scala index 98e3f81..248c331 100644 --- a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/SessionSerializationTest.scala +++ b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/SessionSerializationTest.scala @@ -89,19 +89,13 @@ object SessionSerializationTest { name = USER_1, isPersonal = IS_PERSONAL, isReadOnly = IS_NOT_READ_ONLY, - accountCapabilities = Set(CORE_CAPABILITY)) match { - case Left(ex: IllegalArgumentException) => throw ex - case Right(account: Account) => account - } + accountCapabilities = Set(CORE_CAPABILITY)).toOption.get private val ACCOUNT_2: Account = Account.from( name = USER_2, isPersonal = IS_NOT_PERSONAL, isReadOnly = IS_NOT_READ_ONLY, - accountCapabilities = Set(CORE_CAPABILITY)) match { - case Left(ex: IllegalArgumentException) => throw ex - case Right(account: Account) => account - } + accountCapabilities = Set(CORE_CAPABILITY)).toOption.get private val PRIMARY_ACCOUNTS = Map( MAIL_IDENTIFIER -> ACCOUNT_1.accountId, diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPRoutes.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPRoutes.java index 3ef6302..f683ea1 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPRoutes.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPRoutes.java @@ -42,19 +42,17 @@ public interface JMAPRoutes { .header("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept")); } - Logger logger(); - default Mono<Void> handleInternalError(HttpServerResponse response, Throwable e) { return response.status(INTERNAL_SERVER_ERROR).send(); } - default Mono<Void> handleBadRequest(HttpServerResponse response, Throwable e) { - logger().warn("Invalid request received.", e); + default Mono<Void> handleBadRequest(HttpServerResponse response, Logger logger, Throwable e) { + logger.warn("Invalid request received.", e); return response.status(BAD_REQUEST).send(); } - default Mono<Void> handleAuthenticationFailure(HttpServerResponse response, Throwable e) { - logger().warn("Unauthorized", e); + default Mono<Void> handleAuthenticationFailure(HttpServerResponse response, Logger logger, Throwable e) { + logger.warn("Unauthorized", e); return response.status(UNAUTHORIZED).send(); } } diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServerTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServerTest.java index 992e622..6fd242b 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServerTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServerTest.java @@ -242,11 +242,6 @@ class JMAPServerTest { .noCorsHeaders()); } - @Override - public Logger logger() { - return LOGGER; - } - private Mono<Void> sendVersionResponse(HttpServerResponse response) { return response.status(HttpResponseStatus.OK) .header(CONTENT_TYPE, JSON_CONTENT_TYPE_UTF8) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
