|
1 | 1 | package com.quadient.migration.service.ipsclient |
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties |
3 | 4 | import com.fasterxml.jackson.dataformat.xml.XmlMapper |
4 | 5 | import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper |
5 | 6 | import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty |
6 | 7 | import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement |
7 | 8 | import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText |
| 9 | +import com.fasterxml.jackson.module.kotlin.readValue |
8 | 10 | import com.fasterxml.jackson.module.kotlin.registerKotlinModule |
9 | 11 | import kotlinx.serialization.Serializable |
10 | 12 | import org.slf4j.LoggerFactory |
@@ -249,6 +251,41 @@ class IpsClient(private val host: String, private val port: Int, private val tim |
249 | 251 | this._version = version() |
250 | 252 | } |
251 | 253 |
|
| 254 | + init { |
| 255 | + val result = serverProperties() |
| 256 | + if (result != null) { |
| 257 | + if (result.runForWeb) { |
| 258 | + throw RuntimeException("IPS server has -runforweb enabled, this is currently not supported.") |
| 259 | + } |
| 260 | + if (result.encryptionRequired) { |
| 261 | + throw RuntimeException("IPS server has -forceencryption enabled, this is currently not supported.") |
| 262 | + } |
| 263 | + } |
| 264 | + |
| 265 | + } |
| 266 | + |
| 267 | + private fun serverProperties(): ServerProperties? { |
| 268 | + val command = "diag" |
| 269 | + |
| 270 | + this.writeLine(command).getOrElse { |
| 271 | + logger.error("Failed to write diag command to ips", it) |
| 272 | + return null |
| 273 | + } |
| 274 | + |
| 275 | + val response = this.readLine().split(";") |
| 276 | + if (response.getOrNull(0) != "ok" || response.getOrNull(1)?.toLongOrNull() == null) { |
| 277 | + logger.error("Failed to get diagnostics from ips. Expected byte size, got $response") |
| 278 | + return null |
| 279 | + } |
| 280 | + val bytesToRead = response[1].toInt() |
| 281 | + val bytes = ByteArray(bytesToRead) |
| 282 | + this.reader.readNBytes(bytes, 0, bytesToRead) |
| 283 | + |
| 284 | + val stat: ServerProperties = xmlMapper.readValue(bytes) |
| 285 | + |
| 286 | + return stat |
| 287 | + } |
| 288 | + |
252 | 289 | private fun version(): Version? { |
253 | 290 | val command = "version" |
254 | 291 |
|
@@ -381,14 +418,22 @@ class Output { |
381 | 418 | } |
382 | 419 | } |
383 | 420 |
|
| 421 | +@JsonIgnoreProperties(ignoreUnknown = true) |
| 422 | +@Serializable |
| 423 | +data class ServerProperties( |
| 424 | + @param:JacksonXmlProperty(localName = "RunForWeb") val runForWeb: Boolean, |
| 425 | + @param:JacksonXmlProperty(localName = "Encrypted") val encrypted: Boolean, |
| 426 | + @param:JacksonXmlProperty(localName = "EncryptionRequired") val encryptionRequired: Boolean, |
| 427 | + ) |
| 428 | + |
384 | 429 | @Serializable |
385 | 430 | data class Coms( |
386 | | - @JacksonXmlProperty(localName = "ImportLayoutXml") val values: ImportLayoutXml |
| 431 | + @param:JacksonXmlProperty(localName = "ImportLayoutXml") val values: ImportLayoutXml |
387 | 432 | ) { |
388 | 433 | @Serializable |
389 | 434 | data class ImportLayoutXml( |
390 | | - @JacksonXmlProperty(localName = "ModuleName") val moduleName: String, |
| 435 | + @param:JacksonXmlProperty(localName = "ModuleName") val moduleName: String, |
391 | 436 |
|
392 | | - @JacksonXmlProperty(localName = "FileName") val fileName: String |
| 437 | + @param:JacksonXmlProperty(localName = "FileName") val fileName: String |
393 | 438 | ) |
394 | 439 | } |
0 commit comments