package com.pgf.mqspring.service.impl; import java.util.concurrent.atomic.AtomicReference; import javax.jms.BytesMessage; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.Session; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jms.JmsException; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.core.MessageCreator; import org.springframework.stereotype.Service; import com.pgf.mqspring.model.QlPoc01Test2Request; import com.pgf.mqspring.service.CommonService; import com.pgf.mqspring.service.MqQlPoc01Test2SendService; /** * QL.POC01.TEST2へ送信するサービスの実装クラス */ @Service public class MqQlPoc01Test2SendServiceImpl implements MqQlPoc01Test2SendService { private JmsTemplate jmsTemplate = null; private String que = ""; private QlPoc01Test2Request request = null; private static Logger logger = LogManager.getLogger(); @Autowired CommonService commonService; /** * コンストラクタ */ public MqQlPoc01Test2SendServiceImpl(JmsTemplate template) { this.jmsTemplate = template; } /** * {@inheritDoc} */ @Override public String[] send(QlPoc01Test2Request request) { String[] ret = new String[2]; try { AtomicReference atomicReferenceMessage = new AtomicReference<>(); jmsTemplate.send(que, new MessageCreator() { public Message createMessage(Session session) throws JMSException { BytesMessage byteMessage = session.createBytesMessage(); // byteMessage.setJMSReplyTo(session.createQueue("QL.POC01.REPLY")); byteMessage.writeBytes(commonService.encodeEbcdic(request.toString())); atomicReferenceMessage.set(byteMessage); return byteMessage; } }); ret[0] = "OK"; ret[1] = atomicReferenceMessage.get().getJMSMessageID(); return ret; } catch (JmsException | JMSException ex) { ex.printStackTrace(); ret[0] = "FAIL"; ret[1] = null; return ret; } } /** * {@inheritDoc} */ @Override public String getQue() { return que; } /** * {@inheritDoc} */ @Override public void setQue(String que) { this.que = que; } /** * {@inheritDoc} */ @Override public QlPoc01Test2Request getRequest() { return request; } /** * {@inheritDoc} */ @Override public void setRequest(QlPoc01Test2Request request) { this.request = request; } }