Reputation: 7
Strange problem, it fails if we create a fat-jar to execute the project but not from Netbeans. Any clue why?
It's simple apache-camel app, it starts a route using Mina to receive an HL7 and then uses a bean that directly answer the ACK message, a simple sample.
<bean id="hl7codec" class="org.apache.camel.component.hl7.HL7MLLPCodec">
<property name="charset" value="utf-8"/>
</bean>
<bean id="answerACKHL7" class="com.mycompany.AnswerEMRBean" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route customId="true" id="routeID">
<from uri="mina:tcp://localhost:8255?sync=true&codec=#hl7codec" />
<bean ref="answerACKHL7" method="sendACK" />
</route>
</camelContext>
The app has another java defined REST route but this part works equals both in Netbeans and executing jar file.
If we run it from Netbeans and send an HL7 message to the port it works. Ok, we build a fat-jar with maven-shade-plugin 3.2.4 and run it with java -jar jarfile.jar everything seems to start ok then we send the same HL7 message that works if running from netbeans and got an Exception.
Copy of error message: GRAVE: Failed delivery for (MessageId: ID-DESKTOP-O7B5GIN-1603385955728-0-1 on ExchangeId: ID-DESKTOP-O7B5GIN-1603385955728-0-1). Exhausted after delivery attempt: 1 caught: org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[]
RouteId ProcessorId Processor Elapsed (ms)
[routeID ] [routeID ] [from[mina://tcp://localhost:8255?codec=%23hl7codec&sync=true] ] [ 45]
...
[routeID ] [bean1 ] [bean[ref:answerACKHL7 method:sendACK] ] [ 0]
org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[] at org.apache.camel.CamelExecutionException.wrapCamelExecutionException(CamelExecutionException.java:47) at org.apache.camel.support.builder.ExpressionBuilder$32.evaluate(ExpressionBuilder.java:943) at org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:36) at org.apache.camel.component.bean.MethodInfo$ParameterExpression.evaluateParameterBinding(MethodInfo.java:748) at org.apache.camel.component.bean.MethodInfo$ParameterExpression.evaluateParameterExpressions(MethodInfo.java:640) at org.apache.camel.component.bean.MethodInfo$ParameterExpression.evaluate(MethodInfo.java:608) at org.apache.camel.component.bean.MethodInfo.createMethodInvocation(MethodInfo.java:195) at org.apache.camel.component.bean.BeanInfo.createInvocation(BeanInfo.java:265) at org.apache.camel.component.bean.AbstractBeanProcessor.process(AbstractBeanProcessor.java:135) at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:56) at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:395) at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:148) at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:60) at org.apache.camel.processor.Pipeline.process(Pipeline.java:147) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:286) at org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.process(DefaultAsyncProcessorAwaitManager.java:83) at org.apache.camel.support.AsyncProcessorSupport.process(AsyncProcessorSupport.java:40) at org.apache.camel.component.mina.MinaConsumer$ReceiveHandler.messageReceived(MinaConsumer.java:409) at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.messageReceived(DefaultIoFilterChain.java:1015) at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:650) at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1300(DefaultIoFilterChain.java:49) at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:1128) at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:106) at org.apache.mina.core.session.IoEvent.run(IoEvent.java:89) at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:766) at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:758) at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:697) at java.lang.Thread.run(Unknown Source) Caused by: org.apache.camel.InvalidPayloadException: No body available of type: ca.uhn.hl7v2.model.Message but has value: ... copy of all the message here ... of type: java.lang.String on: Message. Caused by: No type converter available to convert from type: java.lang.String to the required type: ca.uhn.hl7v2.model.Message with value ... copy of all the HL7 message... . Exchange[]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: java.lang.String to the required type: ca.uhn.hl7v2.model.Message with value ... copy of all the HL7 message again... ] at org.apache.camel.support.MessageSupport.getMandatoryBody(MessageSupport.java:118) at org.apache.camel.support.builder.ExpressionBuilder$32.evaluate(ExpressionBuilder.java:941) ... 26 more Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: java.lang.String to the required type: ca.uhn.hl7v2.model.Message with value ... at org.apache.camel.impl.converter.CoreTypeConverterRegistry.mandatoryConvertTo(CoreTypeConverterRegistry.java:216) at org.apache.camel.support.MessageSupport.getMandatoryBody(MessageSupport.java:116) ... 27 more oct 22, 2020 6:59:15 PM org.apache.camel.component.mina.MinaConsumer$ReceiveHandler exceptionCaught ADVERTENCIA: Closing session as an exception was thrown from MINA oct 22, 2020 6:59:15 PM org.apache.mina.core.filterchain.DefaultIoFilterChain callNextExceptionCaught ADVERTENCIA: Unexpected exception from exceptionCaught handler. org.apache.camel.CamelException: org.apache.mina.filter.codec.ProtocolEncoderException: org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[] at org.apache.camel.component.mina.MinaConsumer$ReceiveHandler.exceptionCaught(MinaConsumer.java:387) at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.exceptionCaught(DefaultIoFilterChain.java:987) at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:706) at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1100(DefaultIoFilterChain.java:49) at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.exceptionCaught(DefaultIoFilterChain.java:1110) at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:97) at org.apache.mina.core.session.IoEvent.run(IoEvent.java:89) at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:766) at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:758) at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:697) at java.lang.Thread.run(Unknown Source)
...
Camel version 3.2.0 Java version 1.8.0.221 (should be the same in both Netbeans and command-line)
Any idea why it fails from built jar???
Regards.
Upvotes: 0
Views: 224
Reputation: 4929
With shading of depedencies to fat jar you need to instruct maven plugin, how to handle duplicate resources. In your case is maven-shade-plugin
overriding TypeConverterLoader
which is responsible for type conversion and thus you get
No type converter available to convert from type: java.lang.String to the required type
exception.
You need to configure maven-shade-plugin
to merge this resource. See How to create executable JAR for camel-main project:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>executable-jar</shadedClassifierName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>my.package.MainClass</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/services/org/apache/camel/TypeConverterLoader</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
Upvotes: 0