List of usage examples for javax.jms TextMessage getText
String getText() throws JMSException;
From source file:com.inkubator.hrm.service.impl.JadwalKerjaMassMessagesListener.java
@Override @Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, timeout = 50, rollbackFor = Exception.class) public void onMessage(Message message) { try {//from w ww.ja va 2 s.c o m TextMessage textMessage = (TextMessage) message; JSONObject jSONObject = new JSONObject(textMessage.getText()); long workingGroupId = Long.parseLong(jSONObject.getString("groupWorkingId")); String listEmp = jSONObject.getString("listEmpId"); Date createOn = new SimpleDateFormat("dd-MM-yyyy hh:mm").parse(jSONObject.getString("createDate")); String createBy = jSONObject.getString("createBy"); Gson gson = new GsonBuilder().create(); // List<TempJadwalKaryawan> dataToDelete = new ArrayList<>(); TypeToken<List<Long>> token = new TypeToken<List<Long>>() { }; List<Long> dataEmpId = gson.fromJson(listEmp, token.getType()); //Date now = new Date(); WtGroupWorking groupWorking = wtGroupWorkingDao.getEntiyByPK(workingGroupId); Date startDate = groupWorking.getBeginTime();//tidak ditempatkan di dalam loop karena untuk groupworking yang sama Date endDate = groupWorking.getEndTime(); int numberOfDay = DateTimeUtil.getTotalDayDifference(startDate, endDate); int totalDateDif = DateTimeUtil.getTotalDayDifference(startDate, createOn) + 1; int num = numberOfDay + 1; int hasilBagi = (totalDateDif) / (num); Date tanggalAkhirJadwal = DateTimeUtil.getDateFrom(startDate, (hasilBagi * num) - 1, CommonUtilConstant.DATE_FORMAT_DAY); // String dayBegin = new SimpleDateFormat("EEEE").format(endDate); // String dayNow = new SimpleDateFormat("EEEE").format(now); Date beginScheduleDate; if (new SimpleDateFormat("ddMMyyyy").format(tanggalAkhirJadwal) .equals(new SimpleDateFormat("ddMMyyyy").format(new Date()))) { beginScheduleDate = DateTimeUtil.getDateFrom(startDate, (hasilBagi * num) - num, CommonUtilConstant.DATE_FORMAT_DAY); } else { beginScheduleDate = DateTimeUtil.getDateFrom(startDate, (hasilBagi * num), CommonUtilConstant.DATE_FORMAT_DAY); } List<TempJadwalKaryawan> dataToSave = new ArrayList<>(); TempJadwalKaryawan jadwalKaryawan; for (Long id : dataEmpId) { // dataToDelete.addAll(tempJadwalKaryawanDao.getAllByEmpId(id)); for bussiner process Sake so must be close List<WtScheduleShift> dataScheduleShift = new ArrayList<>(groupWorking.getWtScheduleShifts()); // Collections.sort(dataScheduleShift, shortByDate1); List<WtScheduleShift> sortedDataScheduleShift = Lambda.sort(dataScheduleShift, Lambda.on(WtScheduleShift.class).getScheduleDate()); int i = 0; for (WtScheduleShift wtScheduleShift : sortedDataScheduleShift) { String onlyDate = new SimpleDateFormat("yyyy-MM-dd").format( DateTimeUtil.getDateFrom(beginScheduleDate, i, CommonUtilConstant.DATE_FORMAT_DAY)); Date olnyDate = new SimpleDateFormat("yyyy-MM-dd").parse(onlyDate); jadwalKaryawan = tempJadwalKaryawanDao.getByEmpId(id, olnyDate); if (jadwalKaryawan != null) { jadwalKaryawan.setUpdatedBy(createBy); jadwalKaryawan.setUpdatedOn(new Date()); // jadwalKaryawan = tempJadwalKaryawanDao.getByEmpId(empData.getId(), olnyDate); } else { jadwalKaryawan = new TempJadwalKaryawan(); jadwalKaryawan.setId(Long.parseLong(RandomNumberUtil.getRandomNumber(12))); jadwalKaryawan.setEmpData(empDataDao.getEntiyByPK(id)); jadwalKaryawan.setTanggalWaktuKerja( DateTimeUtil.getDateFrom(beginScheduleDate, i, CommonUtilConstant.DATE_FORMAT_DAY)); jadwalKaryawan.setCreatedBy(createBy); jadwalKaryawan.setCreatedOn(createOn); } // TempJadwalKaryawan jadwalKaryawan = new TempJadwalKaryawan(); // jadwalKaryawan.setEmpData(empDataDao.getEntiyByPK(id)); // jadwalKaryawan.setTanggalWaktuKerja(DateTimeUtil.getDateFrom(beginScheduleDate, i, CommonUtilConstant.DATE_FORMAT_DAY)); // jadwalKaryawan.setWtWorkingHour(wtScheduleShift.getWtWorkingHour()); WtHoliday holiday = wtHolidayDao.getWtHolidayByDate(jadwalKaryawan.getTanggalWaktuKerja()); if (holiday != null && groupWorking.getTypeSequeace().equals(HRMConstant.NORMAL_SCHEDULE)) { jadwalKaryawan.setWtWorkingHour(wtWorkingHourDao.getByCode("OFF")); } else { jadwalKaryawan.setWtWorkingHour(wtScheduleShift.getWtWorkingHour()); } // WtHoliday holiday = wtHolidayDao.getWtHolidayByDate(jadwalKaryawan.getTanggalWaktuKerja()); // if (holiday != null || wtScheduleShift.getWtWorkingHour().getCode().equalsIgnoreCase("OFF")) { // jadwalKaryawan.setAttendanceStatus(attendanceStatusDao.getByCode("OFF")); // } else { // jadwalKaryawan.setAttendanceStatus(attendanceStatusDao.getByCode("HD1")); // } jadwalKaryawan.setIsCollectiveLeave(Boolean.FALSE); dataToSave.add(jadwalKaryawan); i++; } } // tempJadwalKaryawanDao.deleteBacth(dataToDelete); tempJadwalKaryawanDao.saveBatch(dataToSave); //sending email process this.sendingEmailJadwalKaryawan(dataToSave, jSONObject.getString("locale")); } catch (Exception ex) { LOGGER.error("Error", ex); } }
From source file:eu.europa.ec.fisheries.uvms.spatial.service.bean.impl.SpatialUserServiceBean.java
private String mapToDeleteDataSetResponse(TextMessage response, String correlationId) throws SpatialModelMapperException { try {/* w w w. j a v a 2s. c om*/ validateResponse(response, correlationId); DeleteDatasetResponse deleteDatasetResponse = JAXBUtils.unMarshallMessage(response.getText(), DeleteDatasetResponse.class); return deleteDatasetResponse.getResponse(); } catch (JMSException | JAXBException e) { log.error(ERROR_WHEN_MARSHALLING_DATA, e); throw new SpatialModelMarshallException(ERROR_WHEN_MARSHALLING_OBJECT_TO_STRING, e); } }
From source file:eu.europa.ec.fisheries.uvms.spatial.service.bean.impl.SpatialUserServiceBean.java
private DatasetList mapToFindDataSetResponse(TextMessage response, String correlationId) throws SpatialModelMapperException { try {/*from w ww .jav a2 s . c o m*/ validateResponse(response, correlationId); FilterDatasetResponse createDataSetResponse = JAXBUtils.unMarshallMessage(response.getText(), FilterDatasetResponse.class); return createDataSetResponse.getDatasetList(); } catch (JMSException | JAXBException e) { log.error(ERROR_WHEN_MARSHALLING_DATA, e); throw new SpatialModelMarshallException(ERROR_WHEN_MARSHALLING_OBJECT_TO_STRING, e); } }
From source file:eu.europa.ec.fisheries.uvms.spatial.service.bean.impl.SpatialUserServiceBean.java
private String mapToCreateDatasetResponse(TextMessage response, String correlationId) throws SpatialModelMapperException { try {//w ww . j a va2s . com validateResponse(response, correlationId); CreateDatasetResponse createDatasetResponse = JAXBUtils.unMarshallMessage(response.getText(), CreateDatasetResponse.class); return createDatasetResponse.getResponse(); } catch (JMSException | JAXBException e) { log.error(ERROR_WHEN_MARSHALLING_DATA, e); throw new SpatialModelMarshallException(ERROR_WHEN_MARSHALLING_OBJECT_TO_STRING, e); } }
From source file:com.oneops.controller.jms.CmsListenerTest.java
@Test public void msgOpsProcedure() throws Exception { TextMessage message = mock(TextMessage.class); when(message.getStringProperty("source")).thenReturn("opsprocedure"); when(message.getJMSCorrelationID()).thenReturn(null); String msgJson = gson.toJson(createCmsOpsProcedure(OpsProcedureState.active)); when(message.getText()).thenReturn(msgJson); listener.onMessage(message);//from w w w . ja va2 s .co m //once more to get a SKIP when(message.getText()).thenReturn(gson.toJson(createCmsOpsProcedure(OpsProcedureState.discarded))); listener.onMessage(message); }
From source file:org.bremersee.common.jms.DefaultJmsConverter.java
private Object tryToGetPayload(TextMessage msg, Class<?> payloadClass) throws JMSException { String text = msg.getText(); if (StringUtils.isBlank(text)) { return null; }/*from w w w .j a va 2s .com*/ String trimmedText = text.trim(); Object payload = null; if (payloadClass != null && trimmedText.startsWith("{") && trimmedText.endsWith("}")) { try { payload = objectMapper.readValue(trimmedText, payloadClass); } catch (Throwable t0) { // NOSONAR log.info("Reading JSON from message with JMSType [" + msg.getJMSType() + "] failed."); // NOSONAR } } if (payload == null) { try { payload = marshaller.unmarshal(new StreamSource(new StringReader(text))); } catch (Throwable t0) { // NOSONAR log.info("Reading XML from message with JMSType [" + msg.getJMSType() + "] failed."); } } if (payload == null) { MessageConversionException e = new MessageConversionException("Converting TextMessage failed."); log.error("Could not convert text:\n" + text + "\n", e); throw e; } return payload; }
From source file:com.kinglcc.spring.jms.core.converter.Jackson2JmsMessageConverter.java
/** * Convert a TextMessage to a Java Object with the specified type. * @param message the input message/*www. j a va2s.c o m*/ * @return the message text * @throws JMSException if thrown by JMS * @throws IOException in case of I/O errors */ protected String getPayloadFromTextMessage(TextMessage message) throws JMSException, IOException { return message.getText(); }
From source file:com.inkubator.hrm.service.impl.ApprovalActivityNotSendListenerServiceImpl.java
@Override @Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class) public void onMessage(Message msg) { SchedulerLog log = null;//w w w. j av a 2s . c o m try { TextMessage textMessage = (TextMessage) msg; log = schedulerLogDao.getEntiyByPK(Long.parseLong(textMessage.getText())); sendNotificationApprovalNotSend(); log.setStatusMessages("FINISH"); super.doUpdateSchedulerLogSchedulerLog(log); } catch (Exception ex) { if (log != null) { log.setStatusMessages(ex.getMessage()); super.doUpdateSchedulerLogSchedulerLog(log); } LOGGER.error(ex, ex); } }
From source file:org.wso2.carbon.event.input.adapter.jms.internal.util.JMSMessageListener.java
public void onMessage(Message message) { try {//from ww w. ja v a 2 s .c o m PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); if (message != null) { if (log.isDebugEnabled()) { log.debug("Event received in JMS Event Adaptor - " + message); } if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; // Send the text of the message. Conversion to any type (XML,JSON) should // not happen here since this message will be built later. try { String msgText = textMessage.getText(); eventAdaptorListener.onEvent(msgText); } catch (JMSException e) { if (log.isErrorEnabled()) { log.error("Failed to get text from " + textMessage, e); } } catch (InputEventAdapterRuntimeException e) { if (log.isErrorEnabled()) { log.error(e); } } } else if (message instanceof MapMessage) { MapMessage mapMessage = (MapMessage) message; Map event = new HashMap(); try { Enumeration names = mapMessage.getMapNames(); Object name; while (names.hasMoreElements()) { name = names.nextElement(); event.put(name, mapMessage.getObject((String) name)); } eventAdaptorListener.onEvent(event); } catch (JMSException e) { log.error("Can not read the map message ", e); } catch (InputEventAdapterRuntimeException e) { log.error("Can not send the message to broker ", e); } } else if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; byte[] bytes; bytes = new byte[(int) bytesMessage.getBodyLength()]; bytesMessage.readBytes(bytes); eventAdaptorListener.onEvent(new String(bytes, "UTF-8")); } else { log.warn("Event dropped due to unsupported message type"); } } else { log.warn("Dropping the empty/null event received through jms adaptor"); } } catch (JMSException e) { log.error(e); } catch (UnsupportedEncodingException e) { log.error(e); } catch (Throwable t) { log.error(t); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
From source file:org.wso2.carbon.event.input.adaptor.jms.internal.util.JMSMessageListener.java
public void onMessage(Message message) { try {//ww w.ja va 2 s .c om PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); if (message != null) { if (log.isDebugEnabled()) { log.debug(message); } if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; // Send the text of the message. Conversion to any type (XML,JSON) should // not happen here since this message will be built later. try { String msgText = textMessage.getText(); eventAdaptorListener.onEventCall(msgText); } catch (JMSException e) { if (log.isErrorEnabled()) { log.error("Failed to get text from " + textMessage, e); } } catch (InputEventAdaptorEventProcessingException e) { if (log.isErrorEnabled()) { log.error(e); } } } else if (message instanceof MapMessage) { MapMessage mapMessage = (MapMessage) message; Map event = new HashMap(); try { Enumeration names = mapMessage.getMapNames(); Object name; while (names.hasMoreElements()) { name = names.nextElement(); event.put(name, mapMessage.getObject((String) name)); } eventAdaptorListener.onEventCall(event); } catch (JMSException e) { log.error("Can not read the map message ", e); } catch (InputEventAdaptorEventProcessingException e) { log.error("Can not send the message to broker ", e); } } else if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; byte[] bytes; bytes = new byte[(int) bytesMessage.getBodyLength()]; bytesMessage.readBytes(bytes); eventAdaptorListener.onEventCall(new String(bytes, "UTF-8")); } else { log.warn("Event dropped due to unsupported message type"); } } else { log.warn("Dropping the empty/null event received through jms adaptor"); } } catch (JMSException e) { log.error(e); } catch (UnsupportedEncodingException e) { log.error(e); } finally { PrivilegedCarbonContext.endTenantFlow(); } }