在TextMessage中更改MessageHeader

时间:2019-05-17 12:35:05

标签: java spring-boot jms

在我的Springboot应用程序中,我想更改一个messageheader,它是Textmessage中的内容。问题是如何改变价值。

应用程序正在从JMS队列中提取SOAP消息。 在下面的消息中,我想将Mock更改为 请求

@JmsListener提供JMS标头,但不提供此MessageHeader。

我非常感谢您能提供的所有帮助。

2019-05-17 12:17:40.097  INFO 51240 --- [enerContainer-1] s.FindBusinessPartnerApplicationReceiver : txt TextMessage={ Header={ JMSMessageID={null} JMSDestination={Queue[ESB.CustomerAdministration.BS.Party.2.FindBusinessPartner.4.Request]} JMSReplyTo={Queue[$TMP$.EMS_TST_ESB_P2P_SMALL.2DC35CDC563C14BEED1A.7604]} JMSDeliveryMode={PERSISTENT} JMSRedelivered={false} JMSCorrelationID={null} JMSType={null} JMSTimestamp={0} JMSDeliveryTime={0} JMSExpiration={0} JMSPriority={4} } Properties={ } Text={<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><MessageHeader xmlns="http://nn.nl/XSD/Generic/MessageHeader/2">
   <From>
      <Id>IJA_TiBeT2</Id>
   </From>
   <To>
      <Location>ESB.CustomerAdministration.BS.Party.2.FindBusinessPartner.4.Mock</Location>
   </To>
   <HeaderFields>
      <CPAId>n/a</CPAId>
      <ConversationId>srtzzapp0301.insim.biz_0ace093b-2fc350ff_16abdb90d19_-2293</ConversationId>
      <MessageId>srtzzapp0301.insim.biz_0ace093b-2fc350ff_16abdb90d19_-2292</MessageId>
      <Timestamp>2019-05-17T12:17:39</Timestamp>
   </HeaderFields>
   <Service>
      <Name>Party</Name>
      <Context/>
      <Action>
         <Paradigm>Mock</Paradigm>
         <Name>FindBusinessPartner</Name>
         <Version>4</Version>
      </Action>
   </Service>
</MessageHeader>
</soapenv:Header><soapenv:Body><ns0:FindBusinessPartner_Request xmlns:ns0="http://nn.nl/XSD/CustomerAdministration/Party/Party/2/FindBusinessPartner/3">
        <ns0:Role>ZKLANT</ns0:Role>
        <ns0:AuthorizationGroup>Z007</ns0:AuthorizationGroup>
        <ns0:IdentificationNumber>
                                  <ns0:IdentificationType>ZVTAID</ns0:IdentificationType>
                                  <ns0:IdentificationNumber>Z007</ns0:IdentificationNumber>
                               </ns0:IdentificationNumber>                    
    </ns0:FindBusinessPartner_Request>
</soapenv:Body></soapenv:Envelope>} }



    @Component
    @Slf4j
    public class FindBusinessPartnerApplicationReceiver {

      private static final String RECEIVE_ENDPOINT =
          "ESB.CustomerAdministration.BS.Party.2.FindBusinessPartner.4.Mock";
      private static final String DELIVERY_ENDPOINT =
          "ESB.CustomerAdministration.BS.Party.2.FindBusinessPartner.4.Request";

      @Resource(name = "${config.JmsTemplate}")
      @Autowired
      private JmsTemplate jmsTemplate;

      @Autowired
      private FindBusinessPartnerMockStrategy mockStrategy;

      @Autowired
      private MessageHeaderType messageHeaderType;

      @SuppressWarnings("rawtypes")
      @JmsListener(destination = RECEIVE_ENDPOINT, containerFactory = "${config.ContainerFactory}")
      public void receiveMessage(@Headers Map headers, TextMessage message) throws JMSException {

        String correlationId = String.valueOf(headers.get("jms_correlationId"));

    private TextMessage callSap(TextMessage message) {
        MessageCreator msg = session -> {
          TextMessage txt = session.createTextMessage(message.getText());
          txt.setJMSReplyTo(message.getJMSReplyTo());
          txt.setJMSDestination(session.createQueue(DELIVERY_ENDPOINT));
          return txt;
        };


        Message responseObj = jmsTemplate.sendAndReceive(DELIVERY_ENDPOINT, msg);

        if (!(responseObj instanceof TextMessage)) {
          throw new IllegalStateException("not a text message");
        }
        return (TextMessage) responseObj;
      }

      private void replySource(TextMessage origin, TextMessage response) throws JMSException {
        MessageCreator msg2 = session -> {
          TextMessage txt = session.createTextMessage(response.getText());
          if (origin.getJMSCorrelationID() == null) {
            txt.setJMSCorrelationID(origin.getJMSMessageID());
          } else {
            txt.setJMSCorrelationID(origin.getJMSCorrelationID());
          }
          return txt;
        };

        jmsTemplate.send(origin.getJMSReplyTo(), msg2);
      }

      private void handlePassThrough(TextMessage message) throws JMSException {
        TextMessage response = callSap(message);
        replySource(message, response);
      }

0 个答案:

没有答案