add trust all package

This commit is contained in:
Raffaele Mignone 2020-04-24 18:58:13 +02:00
parent 1381d706ed
commit 2cd3dd6549
Signed by: norangebit
GPG Key ID: F5255658CB220573
10 changed files with 36 additions and 26 deletions

View File

@ -1,7 +1,7 @@
package drills.drill07.exercise3.hello package drills.drill07.exercise3.hello
import drills.drill07.exercise3.replier.ActiveMQReplier import util.jms.replier.ActiveMQReplier
import drills.drill07.exercise3.replier.Replier import util.jms.replier.Replier
import javax.jms.TextMessage import javax.jms.TextMessage
fun main() { fun main() {

View File

@ -1,11 +1,12 @@
package drills.drill07.exercise3.hello package drills.drill07.exercise3.hello
import drills.drill07.exercise3.requestor.ActiveMQRequestor import util.jms.requestor.ActiveMQRequestor
import drills.drill07.exercise3.requestor.Requestor import util.jms.requestor.Requestor
import javax.jms.TextMessage import javax.jms.TextMessage
fun main() { fun main() {
val requestor: Requestor = ActiveMQRequestor("hello", shared = true) val requestor: Requestor =
ActiveMQRequestor("hello", shared = true)
val msg = requestor.request(requestor.createTextMessage("Hello Home!")) as TextMessage val msg = requestor.request(requestor.createTextMessage("Hello Home!")) as TextMessage

View File

@ -1,7 +1,7 @@
package drills.drill07.exercise4 package drills.drill07.exercise4
import drills.drill07.exercise3.replier.ActiveMQReplier import util.jms.replier.ActiveMQReplier
import drills.drill07.exercise3.replier.Replier import util.jms.replier.Replier
fun main() { fun main() {
val replier: Replier = ActiveMQReplier("factorial", shared = true) val replier: Replier = ActiveMQReplier("factorial", shared = true)

View File

@ -1,10 +1,11 @@
package drills.drill07.exercise4 package drills.drill07.exercise4
import drills.drill07.exercise3.requestor.ActiveMQRequestor import util.jms.requestor.ActiveMQRequestor
import drills.drill07.exercise3.requestor.Requestor import util.jms.requestor.Requestor
fun main() { fun main() {
val requestor: Requestor = ActiveMQRequestor("factorial", shared = true) val requestor: Requestor =
ActiveMQRequestor("factorial", shared = true)
println("Enter the number of which you want to calculate the factorial:") println("Enter the number of which you want to calculate the factorial:")
val n = readLine()?.toInt() val n = readLine()?.toInt()

View File

@ -1,5 +1,6 @@
package drills.drill07.exercise3.replier package util.jms.replier
import java.io.Serializable
import javax.jms.Message import javax.jms.Message
import javax.jms.Queue import javax.jms.Queue
import javax.jms.QueueConnectionFactory import javax.jms.QueueConnectionFactory
@ -13,12 +14,12 @@ abstract class AbstarctReplier(
) : Replier { ) : Replier {
private val factory: QueueConnectionFactory = this.getFactory() private val factory: QueueConnectionFactory = this.getFactory()
private val connection = factory.createQueueConnection() private val connection = factory.createQueueConnection()
private val session = connection.createQueueSession( private val mainSession = connection.createQueueSession(
false, false,
Session.AUTO_ACKNOWLEDGE Session.AUTO_ACKNOWLEDGE
) )
private val mainQueue = session.createQueue(queueName) private val mainQueue = mainSession.createQueue(queueName)
private val receiver = session.createReceiver(mainQueue) private val receiver = mainSession.createReceiver(mainQueue)
private val secondarySession = connection.createQueueSession( private val secondarySession = connection.createQueueSession(
false, false,
Session.AUTO_ACKNOWLEDGE Session.AUTO_ACKNOWLEDGE
@ -37,18 +38,19 @@ abstract class AbstarctReplier(
} }
} }
override fun createTextMessage(text: String): TextMessage = session.createTextMessage(text) override fun createTextMessage(text: String): TextMessage = mainSession.createTextMessage(text)
override fun createObjectMessage(): ObjectMessage = session.createObjectMessage() override fun createObjectMessage(obj: Serializable?): ObjectMessage =
mainSession.createObjectMessage(obj)
override fun createMessage(): Message = session.createMessage() override fun createMessage(): Message = mainSession.createMessage()
override fun start() { override fun start() {
connection.start() connection.start()
} }
override fun close() { override fun close() {
session.close() mainSession.close()
connection.close() connection.close()
} }

View File

@ -1,4 +1,4 @@
package drills.drill07.exercise3.replier package util.jms.replier
import org.apache.activemq.ActiveMQConnectionFactory import org.apache.activemq.ActiveMQConnectionFactory
import javax.jms.QueueConnectionFactory import javax.jms.QueueConnectionFactory
@ -8,4 +8,5 @@ class ActiveMQReplier(
shared: Boolean = false shared: Boolean = false
) : AbstarctReplier(queueName, shared) { ) : AbstarctReplier(queueName, shared) {
override fun getFactory(uri: String): QueueConnectionFactory = ActiveMQConnectionFactory(uri) override fun getFactory(uri: String): QueueConnectionFactory = ActiveMQConnectionFactory(uri)
.also { it.isTrustAllPackages = true }
} }

View File

@ -1,5 +1,6 @@
package drills.drill07.exercise3.replier package util.jms.replier
import java.io.Serializable
import javax.jms.Message import javax.jms.Message
import javax.jms.ObjectMessage import javax.jms.ObjectMessage
import javax.jms.TextMessage import javax.jms.TextMessage
@ -7,7 +8,7 @@ import javax.jms.TextMessage
interface Replier { interface Replier {
fun onRequest(buildResponse: (Message) -> Message) fun onRequest(buildResponse: (Message) -> Message)
fun createTextMessage(text: String = ""): TextMessage fun createTextMessage(text: String = ""): TextMessage
fun createObjectMessage(): ObjectMessage fun createObjectMessage(obj: Serializable? = null): ObjectMessage
fun createMessage(): Message fun createMessage(): Message
fun start() fun start()
fun close() fun close()

View File

@ -1,5 +1,6 @@
package drills.drill07.exercise3.requestor package util.jms.requestor
import java.io.Serializable
import javax.jms.Message import javax.jms.Message
import javax.jms.QueueConnectionFactory import javax.jms.QueueConnectionFactory
import javax.jms.Session import javax.jms.Session
@ -42,7 +43,8 @@ abstract class AbstractRequestor(
override fun createTextMessage(text: String): TextMessage = mainSession.createTextMessage(text) override fun createTextMessage(text: String): TextMessage = mainSession.createTextMessage(text)
override fun createObjectMessage(): ObjectMessage = mainSession.createObjectMessage() override fun createObjectMessage(obj: Serializable?): ObjectMessage =
mainSession.createObjectMessage(obj)
override fun createMessage(): Message = mainSession.createMessage() override fun createMessage(): Message = mainSession.createMessage()

View File

@ -1,4 +1,4 @@
package drills.drill07.exercise3.requestor package util.jms.requestor
import org.apache.activemq.ActiveMQConnectionFactory import org.apache.activemq.ActiveMQConnectionFactory
import javax.jms.QueueConnectionFactory import javax.jms.QueueConnectionFactory
@ -8,4 +8,5 @@ class ActiveMQRequestor(
shared: Boolean = false shared: Boolean = false
) : AbstractRequestor(queueName, shared) { ) : AbstractRequestor(queueName, shared) {
override fun getFactory(uri: String): QueueConnectionFactory = ActiveMQConnectionFactory(uri) override fun getFactory(uri: String): QueueConnectionFactory = ActiveMQConnectionFactory(uri)
.also { it.isTrustAllPackages = true }
} }

View File

@ -1,5 +1,6 @@
package drills.drill07.exercise3.requestor package util.jms.requestor
import java.io.Serializable
import javax.jms.Message import javax.jms.Message
import javax.jms.ObjectMessage import javax.jms.ObjectMessage
import javax.jms.TextMessage import javax.jms.TextMessage
@ -7,7 +8,7 @@ import javax.jms.TextMessage
interface Requestor { interface Requestor {
fun request(message: Message): Message fun request(message: Message): Message
fun createTextMessage(text: String = ""): TextMessage fun createTextMessage(text: String = ""): TextMessage
fun createObjectMessage(): ObjectMessage fun createObjectMessage(obj: Serializable? = null): ObjectMessage
fun createMessage(): Message fun createMessage(): Message
fun close() fun close()
} }