From 75e076376537d16333842834eeed2181f512ad28 Mon Sep 17 00:00:00 2001 From: iacsha <122627209+iacsha@users.noreply.github.com> Date: Fri, 6 Nov 2026 19:47:06 +0000 Subject: [PATCH 1/2] Return 400 instead of 404 for a malformed date query parameter (fixes #159) CalendarParamConverterProvider threw ProcessingException on an unparseable startDate/endDate, which Jersey surfaced as 404. Throw BadRequestException (400) with the value and expected format so the caller learns why the request failed. Signed-off-by: iacsha <122627209+iacsha@users.noreply.github.com> --- .../CalendarParamConverterProvider.java | 4 +- .../CalendarParamConverterProviderTest.java | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 server/src/test/java/com/mirth/connect/client/core/api/providers/CalendarParamConverterProviderTest.java diff --git a/server/src/main/java/com/mirth/connect/client/core/api/providers/CalendarParamConverterProvider.java b/server/src/main/java/com/mirth/connect/client/core/api/providers/CalendarParamConverterProvider.java index f194439702..486c89038f 100644 --- a/server/src/main/java/com/mirth/connect/client/core/api/providers/CalendarParamConverterProvider.java +++ b/server/src/main/java/com/mirth/connect/client/core/api/providers/CalendarParamConverterProvider.java @@ -10,7 +10,7 @@ package com.mirth.connect.client.core.api.providers; import javax.inject.Singleton; -import javax.ws.rs.ProcessingException; +import javax.ws.rs.BadRequestException; import javax.ws.rs.ext.ParamConverter; import javax.ws.rs.ext.ParamConverterProvider; import javax.ws.rs.ext.Provider; @@ -49,7 +49,7 @@ public T fromString(String value) { T result = (T) calendar; return result; } catch (DateTimeParseException e) { - throw new ProcessingException(e); + throw new BadRequestException("Invalid date '" + value + "'. Expected format yyyy-MM-dd'T'HH:mm:ss.SSSZ, for example 1985-10-26T09:00:00.000-0700.", e); } } diff --git a/server/src/test/java/com/mirth/connect/client/core/api/providers/CalendarParamConverterProviderTest.java b/server/src/test/java/com/mirth/connect/client/core/api/providers/CalendarParamConverterProviderTest.java new file mode 100644 index 0000000000..a547a81d59 --- /dev/null +++ b/server/src/test/java/com/mirth/connect/client/core/api/providers/CalendarParamConverterProviderTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) Mirth Corporation. All rights reserved. + * + * http://www.mirthcorp.com + * + * The software in this package is published under the terms of the MPL license a copy of which has + * been included with this distribution in the LICENSE.txt file. + */ + +package com.mirth.connect.client.core.api.providers; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import java.util.Calendar; + +import javax.ws.rs.BadRequestException; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ParamConverter; + +import org.junit.BeforeClass; +import org.junit.Test; + +public class CalendarParamConverterProviderTest { + + private static ParamConverter converter; + + @BeforeClass + public static void setup() { + converter = new CalendarParamConverterProvider().getConverter(Calendar.class, null, null); + } + + @Test + public void testNullReturnsNull() { + assertNull(converter.fromString(null)); + } + + @Test + public void testValidDateRoundTrips() { + String value = "1985-10-26T09:00:00.000-0700"; + Calendar calendar = converter.fromString(value); + assertNotNull(calendar); + assertEquals(value, converter.toString(calendar)); + } + + @Test + public void testInvalidDateThrowsBadRequest() { + try { + converter.fromString("1985"); + fail("Expected BadRequestException for a malformed date"); + } catch (BadRequestException e) { + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), e.getResponse().getStatus()); + } + } +} From 4a48ac6f1e47923832585927efc5c664c1e83dc9 Mon Sep 17 00:00:00 2001 From: iacsha <122627209+iacsha@users.noreply.github.com> Date: Fri, 6 Nov 2026 19:47:07 +0000 Subject: [PATCH 2/2] test: use SPDX license header on new test file Per review feedback on #562, replace the copied Mirth Corporation boilerplate header with the SPDX form used for new files. Signed-off-by: iacsha <122627209+iacsha@users.noreply.github.com> --- .../providers/CalendarParamConverterProviderTest.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/server/src/test/java/com/mirth/connect/client/core/api/providers/CalendarParamConverterProviderTest.java b/server/src/test/java/com/mirth/connect/client/core/api/providers/CalendarParamConverterProviderTest.java index a547a81d59..e02f120d27 100644 --- a/server/src/test/java/com/mirth/connect/client/core/api/providers/CalendarParamConverterProviderTest.java +++ b/server/src/test/java/com/mirth/connect/client/core/api/providers/CalendarParamConverterProviderTest.java @@ -1,11 +1,5 @@ -/* - * Copyright (c) Mirth Corporation. All rights reserved. - * - * http://www.mirthcorp.com - * - * The software in this package is published under the terms of the MPL license a copy of which has - * been included with this distribution in the LICENSE.txt file. - */ +// SPDX-License-Identifier: MPL-2.0 +// SPDX-FileCopyrightText: Open Integration Engine Contributors package com.mirth.connect.client.core.api.providers;