Skip to content

Commit 35890a5

Browse files
refactor: normalize log and exception messages (#8)
1 parent 5ca3310 commit 35890a5

File tree

7 files changed

+48
-61
lines changed

7 files changed

+48
-61
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
### Changed
9-
- Logging improvement.
9+
- Normalized logging and error messages using Keyple coding standards.
1010
- Migrated the CI pipeline from Jenkins to GitHub Actions.
11+
### Upgraded
12+
- `keyple-util-java-lib` from `2.4.0` to `2.4.1`
13+
- `slf4j-api` from `1.7.32` to `1.7.36` (compileOnly)
1114

1215
## [2.1.0] - 2024-04-12
1316
### Changed

plugin/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ dependencies {
2121
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.7.20")
2222
implementation("org.eclipse.keyple:keyple-common-java-api:2.0.2")
2323
implementation("org.eclipse.keyple:keyple-plugin-java-api:2.3.2")
24-
implementation("org.eclipse.keyple:keyple-util-java-lib:2.4.0")
25-
implementation("org.slf4j:slf4j-api:1.7.32")
24+
implementation("org.eclipse.keyple:keyple-util-java-lib:2.4.1")
25+
compileOnly("org.slf4j:slf4j-api:1.7.36")
2626
}
2727

2828
///////////////////////////////////////////////////////////////////////////////

plugin/src/main/kotlin/org/eclipse/keyple/plugin/android/omapi/AbstractAndroidOmapiPluginAdapter.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ internal abstract class AbstractAndroidOmapiPluginAdapter<T, V> : AndroidOmapiPl
4444
return if (seService != null) {
4545
callback()
4646
} else {
47-
logger.info("Plugin [{}]: connect to SE", name)
47+
logger.info("Connecting to OMAPI SE Service")
4848
connectToSe(context.applicationContext, callback)
4949
}
5050
}
5151

5252
override fun searchAvailableReaders(): MutableSet<ReaderSpi> {
53-
logger.info("Plugin [{}]: search available readers", name)
53+
if (logger.isTraceEnabled) {
54+
logger.trace("Searching available readers")
55+
}
5456
val readerSpis = HashSet<ReaderSpi>()
5557
getNativeReaders()?.forEach { nativeReader ->
5658
val reader = mapToReader(nativeReader)

plugin/src/main/kotlin/org/eclipse/keyple/plugin/android/omapi/se/AndroidOmapiPluginAdapter.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ internal object AndroidOmapiPluginAdapter :
3535
seService =
3636
seServiceFactory.connectToSe(
3737
SEService.OnConnectedListener {
38-
logger.info(
39-
"Plugin [{}]: connected, ready to register plugin, OMAPI SEService version: {}",
40-
name,
41-
seService?.version)
38+
logger.info("OMAPI SE Service connected [version={}]", seService?.version)
4239
callback()
4340
})
4441
}
@@ -49,8 +46,7 @@ internal object AndroidOmapiPluginAdapter :
4946

5047
override fun mapToReader(nativeReader: android.se.omapi.Reader): ReaderSpi {
5148
logger.info(
52-
"Plugin [{}]: reader available: [{}], is card present: {}",
53-
name,
49+
"Reader connected [nativeReader={}, isCardPresent={}]",
5450
nativeReader.name,
5551
nativeReader.isSecureElementPresent)
5652
return AndroidOmapiReaderAdapter(

plugin/src/main/kotlin/org/eclipse/keyple/plugin/android/omapi/se/AndroidOmapiReaderAdapter.kt

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,33 @@ internal class AndroidOmapiReaderAdapter(private val nativeReader: Reader, reade
4040
try {
4141
openChannel = session?.openBasicChannel(null)
4242
} catch (e: IOException) {
43-
throw ReaderIOException("IOException while opening basic channel.")
43+
throw ReaderIOException("Failed to open the basic channel", e)
4444
} catch (e: SecurityException) {
4545
throw ReaderIOException(
46-
"Error while opening basic channel, DFNAME = " + HexUtil.toHex(aid), e.cause)
46+
"Failed to open the basic channel. AID: " + HexUtil.toHex(aid), e.cause)
4747
}
4848

4949
if (openChannel == null) {
50-
throw ReaderIOException("Failed to open a basic channel.")
50+
throw ReaderIOException("Failed to open the basic channel")
5151
}
5252
} else {
53-
logger.info(
54-
"Reader [{}]: open logical channel, select application with AID [{}]",
55-
name,
56-
HexUtil.toHex(aid))
53+
if (logger.isDebugEnabled) {
54+
logger.debug(
55+
"[readerExt={}] Opening card physical channel [aid={}]", name, HexUtil.toHex(aid))
56+
}
5757
try {
5858
openChannel = session?.openLogicalChannel(aid, isoControlMask)
5959
} catch (e: IOException) {
60-
throw ReaderIOException("IOException while opening logical channel.")
60+
throw ReaderIOException("Failed to open the logical channel", e)
6161
} catch (e: NoSuchElementException) {
62-
throw java.lang.IllegalArgumentException("NoSuchElementException: " + HexUtil.toHex(aid), e)
62+
throw java.lang.IllegalArgumentException("AID not found: " + HexUtil.toHex(aid), e)
6363
} catch (e: SecurityException) {
6464
throw ReaderIOException(
65-
"SecurityException while opening logical channel, aid:" + HexUtil.toHex(aid), e.cause)
65+
"Failed to open the logical channel. AID: " + HexUtil.toHex(aid), e.cause)
6666
}
6767

6868
if (openChannel == null) {
69-
throw ReaderIOException("Failed to open a logical channel.")
69+
throw ReaderIOException("Failed to open the logical channel")
7070
}
7171
}
7272
/* get the FCI and build an ApduResponse */
@@ -92,7 +92,7 @@ internal class AndroidOmapiReaderAdapter(private val nativeReader: Reader, reade
9292
try {
9393
session = nativeReader.openSession()
9494
} catch (e: ReaderIOException) {
95-
throw ReaderIOException("IOException while opening physical channel.", e)
95+
throw ReaderIOException("Failed to open the physical channel", e)
9696
}
9797
}
9898

@@ -135,7 +135,9 @@ internal class AndroidOmapiReaderAdapter(private val nativeReader: Reader, reade
135135
val atr = session?.atr
136136
return if (atr != null) {
137137
val sAtr = HexUtil.toHex(atr)
138-
logger.info("Reader [{}]: retrieving ATR from session: {}", name, sAtr)
138+
if (logger.isDebugEnabled) {
139+
logger.debug("[readerExt={}] Retrieving ATR [atr={}]", name, sAtr)
140+
}
139141
sAtr
140142
} else ""
141143
}
@@ -147,19 +149,11 @@ internal class AndroidOmapiReaderAdapter(private val nativeReader: Reader, reade
147149
*/
148150
@Throws(ReaderIOException::class)
149151
override fun transmitApdu(apduIn: ByteArray): ByteArray {
150-
// Initialization
151-
if (logger.isTraceEnabled) {
152-
logger.trace("Reader [{}]: transmit APDU: {} bytes", name, apduIn.size)
153-
logger.trace("Reader [{}]: data in: {}", name, HexUtil.toHex(apduIn))
154-
}
155152
var dataOut = byteArrayOf(0)
156153
try {
157154
openChannel.let { dataOut = it?.transmit(apduIn) ?: throw IOException("Channel is not open") }
158155
} catch (e: IOException) {
159-
throw ReaderIOException("Error while transmitting APDU", e)
160-
}
161-
if (logger.isTraceEnabled) {
162-
logger.trace("Reader [{}]: data out: {}", name, HexUtil.toHex(dataOut))
156+
throw ReaderIOException("Failed to transmit APDU", e)
163157
}
164158
return dataOut
165159
}

plugin/src/main/kotlin/org/eclipse/keyple/plugin/android/omapi/simalliance/AndroidOmapiPluginAdapter.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ internal object AndroidOmapiPluginAdapter :
3333
seService =
3434
seServiceFactory.connectToSe(
3535
SEService.CallBack {
36-
logger.info(
37-
"Plugin [{}]: connected, ready to register plugin, OMAPI SEService version: {}",
38-
name,
39-
seService?.version)
36+
logger.info("OMAPI SE Service connected [version={}]", seService?.version)
4037
callback()
4138
})
4239
}
@@ -47,8 +44,7 @@ internal object AndroidOmapiPluginAdapter :
4744

4845
override fun mapToReader(nativeReader: org.simalliance.openmobileapi.Reader): ReaderSpi {
4946
logger.info(
50-
"Plugin [{}]: reader available: [{}], is card present: {}",
51-
name,
47+
"Reader connected [nativeReader={}, isCardPresent={}]",
5248
nativeReader.name,
5349
nativeReader.isSecureElementPresent)
5450
return AndroidOmapiReaderAdapter(

plugin/src/main/kotlin/org/eclipse/keyple/plugin/android/omapi/simalliance/AndroidOmapiReaderAdapter.kt

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,22 @@ internal class AndroidOmapiReaderAdapter(private val nativeReader: Reader, reade
4343
try {
4444
openChannel = session?.openBasicChannel(null)
4545
} catch (e: IOException) {
46-
throw ReaderIOException("IOException while opening basic channel.")
46+
throw ReaderIOException("Failed to open the basic channel", e)
4747
} catch (e: ReaderIOException) {
4848
throw ReaderIOException(
49-
"Error while opening basic channel, DFNAME = " + HexUtil.toHex(aid), e.cause)
49+
"Failed to communicate with card while opening the basic channel. DF Name: " +
50+
HexUtil.toHex(aid),
51+
e.cause)
5052
}
5153

5254
if (openChannel == null) {
53-
throw ReaderIOException("Failed to open a basic channel.")
55+
throw ReaderIOException("Failed to open the basic channel")
5456
}
5557
} else {
56-
logger.info(
57-
"Reader [{}]: open logical channel, select application with AID [{}]",
58-
name,
59-
HexUtil.toHex(aid))
58+
if (logger.isDebugEnabled) {
59+
logger.debug(
60+
"[readerExt={}] Opening card physical channel [aid={}]", name, HexUtil.toHex(aid))
61+
}
6062
try {
6163
// openLogicalChannel of SimAlliance OMAPI is only available for version 3.0+ of the
6264
// library.
@@ -76,16 +78,16 @@ internal class AndroidOmapiReaderAdapter(private val nativeReader: Reader, reade
7678
}
7779
}
7880
} catch (e: IOException) {
79-
throw ReaderIOException("IOException while opening logical channel.", e)
81+
throw ReaderIOException("Failed to open the logical channel", e)
8082
} catch (e: NoSuchElementException) {
81-
throw java.lang.IllegalArgumentException("NoSuchElementException: " + HexUtil.toHex(aid), e)
83+
throw java.lang.IllegalArgumentException("AID not found: " + HexUtil.toHex(aid), e)
8284
} catch (e: SecurityException) {
8385
throw ReaderIOException(
84-
"SecurityException while opening logical channel, aid:" + HexUtil.toHex(aid), e.cause)
86+
"Failed to open the logical channel. AID:" + HexUtil.toHex(aid), e.cause)
8587
}
8688

8789
if (openChannel == null) {
88-
throw ReaderIOException("Failed to open a logical channel.")
90+
throw ReaderIOException("Failed to open the logical channel")
8991
}
9092
}
9193
/* get the FCI and build an ApduResponse */
@@ -110,7 +112,9 @@ internal class AndroidOmapiReaderAdapter(private val nativeReader: Reader, reade
110112
val atr = session?.atr
111113
return if (atr != null) {
112114
val sAtr = HexUtil.toHex(atr)
113-
logger.info("Reader [{}]: retrieving ATR from session: {}", name, sAtr)
115+
if (logger.isDebugEnabled) {
116+
logger.debug("[readerExt={}] Retrieving ATR [atr={}]", name, sAtr)
117+
}
114118
sAtr
115119
} else ""
116120
}
@@ -125,7 +129,7 @@ internal class AndroidOmapiReaderAdapter(private val nativeReader: Reader, reade
125129
try {
126130
session = nativeReader.openSession()
127131
} catch (e: ReaderIOException) {
128-
throw ReaderIOException("IOException while opening physical channel.", e)
132+
throw ReaderIOException("Failed to open the physical channel", e)
129133
}
130134
}
131135

@@ -166,19 +170,11 @@ internal class AndroidOmapiReaderAdapter(private val nativeReader: Reader, reade
166170
*/
167171
@Throws(ReaderIOException::class)
168172
override fun transmitApdu(apduIn: ByteArray): ByteArray {
169-
// Initialization
170-
if (logger.isTraceEnabled) {
171-
logger.trace("Reader [{}]: transmit APDU: {} bytes", name, apduIn.size)
172-
logger.trace("Reader [{}]: data in: {}", name, HexUtil.toHex(apduIn))
173-
}
174173
var dataOut = byteArrayOf(0)
175174
try {
176175
openChannel.let { dataOut = it?.transmit(apduIn) ?: throw IOException("Channel is not open") }
177176
} catch (e: IOException) {
178-
throw ReaderIOException("Error while transmitting APDU", e)
179-
}
180-
if (logger.isTraceEnabled) {
181-
logger.trace("Reader [{}]: data out: {}", name, HexUtil.toHex(dataOut))
177+
throw ReaderIOException("Failed to transmit APDU", e)
182178
}
183179
return dataOut
184180
}

0 commit comments

Comments
 (0)