简体   繁体   中英

apache camel crypto set 'CamelSignaturePublicKeyOrCert' in JMS TextMessage Header

I am trying to sign the payload of a JMS text message with a private key. The message is then sent to a queue and routed accordingly. The signature will be place in the message header along with the public key.

I am using the following code to set the header with the public key.

TextMessage textMessage = session.createTextMessage(message);
String publicKey = new String(pubk.getEncoded());
 textMessage.setStringProperty("CamelSignaturePublicKeyOrCert", publicKey);

However when the message is begin routed I get the following error

11:13:20,027 WARN [org.apache.camel.component.jms.EndpointMessageListener] Execution of JMS message listener failed. Caused by: [org.apache.camel.RuntimeCamelException - java.lang.IllegalStateException: Cannot verify signature as no Public Key or Certificate has been supplied. Either supply one in the route definition or via the message header 'CamelSignaturePublicKeyOrCert']: org.apache.camel.RuntimeCamelException: java.lang.IllegalStateException: Cannot verify signature as no Public Key or Certificate has been supplied. Either supply one in the route definition or via the message header 'CamelSignaturePublicKeyOrCert

the routes are defined as follows

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<!-- Dependencies: ojdbc.jar and aqjms.jar must be in the activemq lib directory -->
<route>
    <from uri="activemq:queue:queue.outbound"/>
    <log message="The expected queue is :: ${headers.queue}" />

     <to uri="crypto:verify://slpy" />
    <choice>
        <when>
            <simple>${headers.queue} == 'ora'</simple>
            <to uri="oracleQueue:queue:SLEEPY_LION_QUEUE"/>
        </when>
        <when>
            <simple>${headers.queue} == 'proc'</simple>
            <to uri="activemq:queue:queue.proc"/>
        </when>
        <otherwise>
            <log message="Invalid queue"/>
        </otherwise>
    </choice>
</route>

In order to fix this issue I updated the broker-config.xml as follows

<route>
    <!-- <package>com.rs2.sleepylion.routes</package> -->
    <from uri="activemq:queue:queue.outbound"/>

    <to uri="log:in?showHeaders=true" />
    <log message="The expected queue is :: ${headers.queue}" />
    <to uri="log:out?showHeaders=true" />

    <choice>
        <when>
            <simple>${headers.queue} == 'ora'</simple>
            <to uri="oracleQueue:queue:SLEEPY_LION_QUEUE"/>
        </when>
        <when>
            <simple>${headers.queue} == 'proc'</simple>
            <to uri="crypto:verify://headers?publicKey=#myPublicKey&amp;clearHeaders=false" />
            <to uri="activemq:queue:queue.proc"/>
        </when>
        <otherwise>
            <log message="Invalid queue"/>
        </otherwise>
    </choice>
</route>
<bean id="myPublicKey" class="com.rs2.sleepylion.routes.Keys" factory-method="publicKey"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM