Skip to content

Commit 245e678

Browse files
authored
Merge pull request #84 from tomwetjens/83-ioexception-message
Fix #83 Improve message on I/O exception
2 parents 48fd5b3 + 09ade44 commit 245e678

File tree

7 files changed

+34
-14
lines changed

7 files changed

+34
-14
lines changed

api/src/main/resources/uftp.xjb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
3-
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="4.0">
2+
<jaxb:bindings xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
3+
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0">
44

55
<jaxb:globalBindings>
66
<jaxb:serializable uid="1"/>

core/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
<jna.version>5.13.0</jna.version>
2323
<lazysodium-java.version>5.1.4</lazysodium-java.version>
2424
<resource-loader.version>2.0.2</resource-loader.version>
25-
<swagger-annotations.version>2.2.20</swagger-annotations.version>
26-
<wiremock.version>3.2.0</wiremock.version>
25+
<swagger-annotations.version>2.2.21</swagger-annotations.version>
26+
<wiremock.version>3.5.3</wiremock.version>
2727
<xmlunit.verion>2.9.1</xmlunit.verion>
28-
<lombok.version>1.18.30</lombok.version>
29-
<commons-logging.version>1.2</commons-logging.version>
28+
<lombok.version>1.18.32</lombok.version>
29+
<commons-logging.version>1.3.1</commons-logging.version>
3030
<jakarta-annotation.version>2.1.1</jakarta-annotation.version>
31-
<awaitility.version>4.2.0</awaitility.version>
31+
<awaitility.version>4.2.1</awaitility.version>
3232
</properties>
3333

3434
<dependencies>

core/src/main/java/org/lfenergy/shapeshifter/core/service/sending/UftpSendMessageService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class UftpSendMessageService {
5252
private static final String MSG_CLIENT_ERROR = "Client error {0} received while sending UFTP message to {1}: {2}";
5353
private static final String MSG_SERVER_ERROR = "Server error {0} received while sending UFTP message to {1}: {2}";
5454
private static final String MSG_UNEXPECTED_RESPONSE_STATUS = "Unexpected response status {0} received while sending UFTP message to {1}: {2}";
55-
private static final String MSG_UNEXPECTED_IO_ERROR = "Unexpected I/O exception while sending UFTP message to {0}: {1}";
55+
private static final String MSG_UNEXPECTED_IO_ERROR = "Unexpected I/O exception while sending UFTP message to {0}: {1}: {2}";
5656
private static final String MSG_INTERRUPTED = "Interrupted while sending UFTP message to {0}: {1}";
5757
private static final String MSG_TOO_MANY_REDIRECTS = "Too many redirects while sending UFTP message to {0}";
5858
private static final String MSG_MISSING_REDIRECT_LOCATION = "Redirect received without " + REDIRECT_LOCATION_HEADER_NAME + " header while sending UFTP message to {0}";
@@ -166,7 +166,7 @@ private void send(String signedXml, String url, int maxFollowRedirects) {
166166
} catch (URISyntaxException | IllegalArgumentException e) {
167167
throw new UftpSendException(MessageFormat.format(MSG_INVALID_ENDPOINT, e.getMessage()), e);
168168
} catch (IOException e) {
169-
throw new UftpSendException(MessageFormat.format(MSG_UNEXPECTED_IO_ERROR, url, e.getMessage()), e);
169+
throw new UftpSendException(MessageFormat.format(MSG_UNEXPECTED_IO_ERROR, url, e.getClass().getSimpleName(), e.getMessage()), e);
170170
} catch (InterruptedException e) {
171171
Thread.currentThread().interrupt();
172172
throw new UftpSendException(MessageFormat.format(MSG_INTERRUPTED, url, e.getMessage()), e);

core/src/test/java/org/lfenergy/shapeshifter/core/service/sending/UftpSendMessageServiceTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,26 @@ void attemptToSendMessage_MalformedUrl() {
350350
verifyNoInteractions(uftpValidationService);
351351
}
352352

353+
@Test
354+
void attemptToSendMessage_connectFailed() {
355+
mockSerialisation();
356+
mockSending();
357+
var endpoint = "http://localhost:1"; // something that will trigger a java.net.ConnectException
358+
given(participantService.getEndPointUrl(any())).willReturn(endpoint);
359+
var httpStatusCode = HttpStatusCode.INTERNAL_SERVER_ERROR;
360+
361+
var actual = assertThrows(UftpSendException.class, () ->
362+
testSubject.attemptToSendMessage(flexRequest, details));
363+
364+
verifySending();
365+
366+
assertThat(actual)
367+
.isInstanceOf(UftpSendException.class)
368+
.hasMessage("Unexpected I/O exception while sending UFTP message to " + endpoint + ": ConnectException: null");
369+
assertThat(actual.getHttpStatusCode()).isEqualTo(httpStatusCode);
370+
verifyNoInteractions(uftpValidationService);
371+
}
372+
353373
@Test
354374
void attemptToValidateAndSendMessage_ValidationException() {
355375
given(details.sender()).willReturn(sender);

core/src/test/java/org/lfenergy/shapeshifter/core/service/serialization/TestFile.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.io.IOException;
1111
import java.nio.charset.StandardCharsets;
1212
import java.nio.file.Files;
13-
import org.apache.commons.io.FileUtils;
1413

1514
public class TestFile {
1615

@@ -26,7 +25,7 @@ private static String toFolder(Class<?> testClass) {
2625

2726
public static String readResourceFileAsString(Class<?> testClass, String testName, String postFix) throws IOException {
2827
File file = resourceAsFile(testClass, testName, postFix);
29-
return FileUtils.readFileToString(file, StandardCharsets.UTF_8);
28+
return Files.readString(file.toPath(), StandardCharsets.UTF_8);
3029
}
3130

3231
public static void compareAsXml(Class<?> testClass, String testName, String actualXml) throws IOException {

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<!-- Test dependency versions -->
4949
<junit.version>5.10.2</junit.version>
5050
<assertj.version>3.25.3</assertj.version>
51-
<mockito.version>5.6.0</mockito.version>
51+
<mockito.version>5.11.0</mockito.version>
5252

5353
<!-- Plugin versions -->
5454
<maven-surefire-plugin.version>3.2.1</maven-surefire-plugin.version>
@@ -138,6 +138,7 @@
138138
<version>${dependency-check-maven.version}</version>
139139
<configuration>
140140
<failBuildOnCVSS>8</failBuildOnCVSS>
141+
<assemblyAnalyzerEnabled>false</assemblyAnalyzerEnabled> <!-- We don't have .NET assemblies -->
141142
</configuration>
142143
<executions>
143144
<execution>

spring/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<url>https://www.lfenergy.org/projects/shapeshifter/</url>
1717

1818
<properties>
19-
<spring-boot.version>3.2.3</spring-boot.version>
20-
<swagger-annotations.version>2.2.20</swagger-annotations.version>
19+
<spring-boot.version>3.2.5</spring-boot.version>
20+
<swagger-annotations.version>2.2.21</swagger-annotations.version>
2121
</properties>
2222

2323
<dependencyManagement>

0 commit comments

Comments
 (0)