/** * Process this internal message. * @param internalMessage The message to process. * @return (optional) The return message if applicable. */ public BaseMessage processMessage(BaseMessage internalMessage) { TrxMessageHeader messageHeader = (TrxMessageHeader)internalMessage.getMessageHeader(); //if (messageHeader.get(TrxMessageHeader.MESSAGE_CODE) == null) // messageHeader.put(TrxMessageHeader.MESSAGE_CODE, HotelRateRequestMessageOutProcessor.MESSAGE_CODE); // External operation name //if (messageHeader.get(TrxMessageHeader.MESSAGE_RESPONSE_CODE) == null) // For email transport, need to know who processes the returned message // messageHeader.put(TrxMessageHeader.MESSAGE_RESPONSE_CODE, com.tourgeek.tour.product.hotel.message.in.HotelRateResponseSOAPMsgReplyOut.MESSAGE_CODE); // External operation name return null; // No return from a message out }
/** * Get the message queue registry ID from this message. * @param internalMessage The message to get the registry ID from. * @return Integer The registry ID. */ public Integer getRegistryID(BaseMessage internalMessageReply) { Integer intRegistryID = null; Object objRegistryID = null; if (internalMessageReply.getMessageHeader() instanceof TrxMessageHeader) // Always objRegistryID = ((TrxMessageHeader)internalMessageReply.getMessageHeader()).getMessageHeaderMap().get(TrxMessageHeader.REGISTRY_ID); if (objRegistryID == null) objRegistryID = internalMessageReply.get(TrxMessageHeader.REGISTRY_ID); if (objRegistryID instanceof Integer) intRegistryID = (Integer)objRegistryID; else if (objRegistryID instanceof String) { try { intRegistryID = new Integer(Integer.parseInt((String)objRegistryID)); } catch (NumberFormatException ex) { intRegistryID = null; } } return intRegistryID; } /**
if (internalMessage.getMessageDataDesc(null) == null) internalMessage.addMessageDataDesc(new BaseProductMessageDesc(null, null)); BaseMessageHeader inMessageHeader = internalMessage.getMessageHeader(); String strMessage = (String)internalMessage.get(MESSAGE_PARAM); BaseMessageHeader messageReplyHeader = null; messageReplyHeader = new TrxMessageHeader(inMessageHeader.getQueueName(), inMessageHeader.getQueueType(), null); messageReply.addMessageDataDesc(productResponse); if (strMessage != null) messageReply.put(MESSAGE_PARAM, strMessage); else if (internalMessage.getMessageHeader() instanceof TrxMessageHeader) // Always if (((TrxMessageHeader)internalMessage.getMessageHeader()).get(TrxMessageHeader.MESSAGE_ERROR) != null) strErrorMessage = ((TrxMessageHeader)internalMessage.getMessageHeader()).get(TrxMessageHeader.MESSAGE_ERROR).toString(); // Rare if (strErrorMessage == null) strErrorMessage = "Error - No data to PING";
/** * Process this internal message. * @param internalMessage The message to process. * @return (optional) The return message if applicable. */ public BaseMessage processMessage(BaseMessage internalMessage) { String strRoomType = (String)internalMessage.get("rateType"); String strRoomClass = (String)internalMessage.get("roomClass"); // Add code to lookup hotel rate here try { java.lang.Thread.currentThread().sleep(5000); // Simulate time for message turnaround } catch (InterruptedException ex) { } BaseMessage replyMessage = new MapMessage(); replyMessage.put(DBParams.FIELD, "multipleFields"); replyMessage.put("CityOrTown", "Los Angeles"); replyMessage.put("Contact", "Fred"); //? this.sendMessage(new BaseMessage(null, replyMessage)); return null; // No reply expected }
/** * Utility to add the standard payload properties to the message * @param msg * @param message */ public void addPayloadProperties(Object msg, BaseMessage message) { MessageDataDesc messageDataDesc = message.getMessageDataDesc(null); // Top level only if (messageDataDesc != null) { Map<String,Class<?>> mapPropertyNames = messageDataDesc.getPayloadPropertyNames(null); if (mapPropertyNames != null) { Map<String,Object> properties = this.getPayloadProperties(msg, mapPropertyNames); for (String key : properties.keySet()) { message.put(key, properties.get(key)); } } } } /**
if (trxMessageHeader == null) return null; BaseMessage messageOut = BaseMessage.createMessage(trxMessageHeader); ProductRequest message = (ProductRequest)messageOut.getMessageDataDesc(null); if (message == null) return null; trxMessageHeader = (TrxMessageHeader)messageOut.getMessageHeader(); BaseProductResponse messageReply = (BaseProductResponse)((BaseMessage)recHotel.processCostRequestInMessage(messageOut, null)).getMessageDataDesc(null); double dProductCost = recHotel.getField(Product.PRODUCT_COST).getValue(); this.getScreenRecord().getField(TestHotelRateScreenRecord.TOTAL_COST).setValue(dProductCost);
if (m_properties.get("standalone") == null) if ((message.getMessageHeader().get(REMOVE_LISTENER) != null) || (message.get(REMOVE_LISTENER) != null)) message.consume(); m_properties.put(MessageConstants.QUEUE_NAME, message.getMessageHeader().getQueueName()); if (m_properties.get(MessageConstants.QUEUE_TYPE) == null) m_properties.put(MessageConstants.QUEUE_TYPE, message.getMessageHeader().getQueueType()); m_properties.remove(ServletTask.APPLICATION); m_properties.remove(MessageInfoApplication.AUTOSTART); if (message instanceof MapMessage) // Always Map<String,Object> propMessage = (Map)message.getData(); if (propMessage != null) properties.putAll(propMessage); properties.remove(MessageInfoApplication.AUTOSTART); properties.put(DBParams.PROCESS, strProcessClass); BaseMessage messageInitial = new MapMessage(new BaseMessageHeader(message.getMessageHeader().getQueueName(), message.getMessageHeader().getQueueType(), this, null), properties); env.getMessageManager(m_application, true).sendMessage(messageInitial); // Resend it! (Don't consume it!)
if (message.getMessageHeader().getRegistryIDMatch() != null) // My private message if (message.get(PingRequestMessageInProcessor.MESSAGE_PARAM) == null) if (dblRate != null) // Display the rate this.getScreenRecord().getField(TestHotelRateScreenRecord.TOTAL_COST).setValue(dblRate.doubleValue()); int iStatus = ((BaseProductResponse)message.getMessageDataDesc(null)).getMessageDataStatus(); this.getScreenRecord().getField(TestHotelRateScreenRecord.DISPLAY_COST_STATUS_ID).setValue(iStatus); String strMessage = (String)message.get(PingRequestMessageInProcessor.MESSAGE_PARAM); System.out.println("Message: " + strMessage); if ("Hello".equalsIgnoreCase(strMessage))
messageIn.put(key, propMessage.get(key)); if (msgReplyInternal.getExternalMessage() != null) String strReply = msgReplyInternal.getExternalMessage().toString(); res.getWriter().print(strReply); String strTrxID = (String)msgReplyInternal.getMessageHeader().get(TrxMessageHeader.LOG_TRX_ID); if ((msgReplyInternal != null) && (xmlMessageTransport != null)) String strTrxID = (String)msgReplyInternal.getMessageHeader().get(TrxMessageHeader.LOG_TRX_ID); xmlMessageTransport.logMessage(strTrxID, msgReplyInternal, MessageInfoTypeModel.REPLY, MessageTypeModel.MESSAGE_OUT, MessageStatusModel.ERROR, strError, null);
if (trxMessageHeader == null) return false; BaseMessage messageOut = BaseMessage.createMessage(trxMessageHeader); ProductRequest message = (ProductRequest)messageOut.getMessageDataDesc(null); if (message == null) return false; trxMessageHeader = (TrxMessageHeader)messageOut.getMessageHeader(); messageReply = (BaseProductResponse)baseMessageReply.getMessageDataDesc(null); messageInProcessor.free(); message.put(PingRequestMessageInProcessor.MESSAGE_PARAM, "Hello"); if (!MessageTransport.DIRECT.equalsIgnoreCase((String)trxMessageHeader.get(MessageTransport.SEND_MESSAGE_BY_PARAM))) message.put(PingRequestMessageInProcessor.MESSAGE_PARAM, "CHF"); if (!MessageTransport.DIRECT.equalsIgnoreCase((String)trxMessageHeader.get(MessageTransport.SEND_MESSAGE_BY_PARAM)))
/** * Move this standard payload properties from the message to the xml. * @param message * @param msg * @param strKey */ public void setPayloadProperty(BaseMessage message, Object msg, String strKey, Class<?> classKey) { Object data = message.get(strKey); if (data == null) return; this.setPayloadProperty(data, msg, strKey, classKey); } /**
/** A record with this datasource handle changed, notify any behaviors that are checking. * NOTE: Be very careful as this code is running in an independent thread * (synchronize to the task before calling record calls). * NOTE: For now, you are only notified of the main record changes. */ public int handleMessage(BaseMessage message) { Record record = this.getMainRecord(); // Record changed if ((record.getTable() instanceof GridTable) // Always except HTML && (message.getMessageHeader() != null) && (message.getMessageHeader() instanceof RecordMessageHeader)) { int iIndex = -1; synchronized (this.getTask()) { iIndex = ((GridTable)record.getTable()).updateGridToMessage(message, true, true); } if (iIndex != -1) { // This screen has changed, add this clue so a remote thin table will know where the change was. message.put(ModelMessageHandler.START_INDEX_PARAM, Integer.toString(iIndex)); } } return super.handleMessage(message); } /**
else message = BaseMessage.createMessage(trxMessageHeader); message.put(ManualMessage.MESSAGE_PARAM, strMessage); // The physical message if (trxMessageHeader.get(TrxMessageHeader.MESSAGE_PROCESSOR_CLASS) == null) trxMessageHeader.put(TrxMessageHeader.MESSAGE_PROCESSOR_CLASS, BaseMessageOutProcessor.class.getName()); // Default processor if ((trxMessageHeader.get(TrxMessageHeader.DESTINATION_PARAM) == null) && (message.get(TrxMessageHeader.DESTINATION_PARAM) == null)) return this.getTask().setLastError(this.getTask().getString("No destination address in message"));
/** * Process this internal message. * @param internalMessage The message to process. * @return (optional) The return message if applicable. */ public BaseMessage processMessage(BaseMessage internalMessage) { ProductRequest msgProductAvailRequestIn = (ProductRequest)internalMessage.getMessageDataDesc(null); Product recProduct = (Product)this.getMainRecord(); if (recProduct == null) recProduct = this.getProductRecord(); if (!((ProductMessageData)msgProductAvailRequestIn.getMessageDataDesc(ProductRequest.PRODUCT_MESSAGE)).getProduct(recProduct)) { // Error, hotel not found // pend(don) } BaseProductResponse productAvailResponseOut = (BaseProductResponse)((BaseMessage)recProduct.processAvailabilityRequestInMessage((BaseMessage)msgProductAvailRequestIn.getMessage(), null, null)).getMessageDataDesc(null); // ProductAvailabilityResponse BaseProductResponse productRateResponseOut = (BaseProductResponse)((BaseMessage)recProduct.processCostRequestInMessage((BaseMessage)msgProductAvailRequestIn.getMessage(), null)).getMessageDataDesc(null); TrxMessageHeader messageHeader = (TrxMessageHeader)productAvailResponseOut.getMessage().getMessageHeader(); //?Map<String,Object> mapMessage = productAvailResponseOut.getMap(); //?Map<String,Object> mapMessage2 = productRateResponseOut.getMap(); //?mapMessage.putAll(mapMessage2); BaseMessage response = null;//?new BaseMessage(messageHeader, new HotelRateAvailResponse(null, mapMessage)); return response; }
/** * Convert the external form to the internal message form. * You must override this method. * @param externalMessage The received message to be converted to internal form. * @return The internal message. */ public int convertExternalToInternal(Object recordOwner) { String strMessage = (String)this.getRawData(); strMessage = this.stripHtmlTags((String)strMessage); Map<String,Object> map = this.getEMailParams(strMessage); this.moveHeaderParams(map, ((TrxMessageHeader)this.getMessage().getMessageHeader()).getMessageHeaderMap()); String rootTag = BaseMessage.ROOT_TAG; if (this.getMessage() != null) if (this.getMessage().getMessageDataDesc(null) != null) if (this.getMessage().getMessageDataDesc(null).getKey() != null) rootTag = this.getMessage().getMessageDataDesc(null).getKey(); StringBuffer sb = new StringBuffer(); Util.addStartTag(sb, rootTag); Util.addXMLMap(sb, map); Util.addEndTag(sb, rootTag); String strXML = sb.toString(); if (this.getXSLTDocument() != null) strXML = this.transformMessage(strXML, null); // Now use the XSLT document to convert this XSL document. boolean bSuccess = this.getMessage().setXML(strXML); return bSuccess ? DBConstants.NORMAL_RETURN : DBConstants.ERROR_RETURN; } /**
/** * A record with this datasource handle changed, notify any behaviors that are checking. * NOTE: Be very careful as this code is running in an independent thread * (synchronize to the task before calling record calls). * NOTE: For now, you are only notified of the main record changes. * @param message The message to handle. * @return The error code. */ public int handleMessage(BaseMessage message) { if (message != null) if (message.getMessageHeader().getRegistryIDMatch() != null) // My private message if (message.getMessageHeader().getRegistryIDMatch().equals(m_intRegistryID)) // My private message { Application app = (Application)this.getTask().getApplication(); String strMessage = app.getResources(ResourceConstants.DEFAULT_RESOURCE, true).getString("Remote action completed"); this.getTask().setStatusText(strMessage, Constants.INFORMATION); message.consume(); } return super.handleMessage(message); }
/** * Get the cost or inventory information from the product now. * @return The message status. */ public int getDirectProductInfo(Product recProduct, BaseMessage message) { BaseProductResponse response = (BaseProductResponse)((BaseMessage)recProduct.processAvailabilityRequestInMessage(message, null, null)).getMessageDataDesc(null); if (response != null) return response.getMessageDataStatus(); return BaseStatus.NOT_VALID; } /**
/** * Convert the external form to the internal message form. * You must override this method. * @param root The root object of the marshallable object. * @param recordOwner The recordowner * @return The error code. */ public int convertMarshallableObjectToInternal(Object root, RecordOwner recordOwner) { if (root instanceof ConversionRateResponse) { // Always ConversionRateResponse msg = (ConversionRateResponse)root; double rate = msg.getConversionRateResult(); BaseMessage message = this.getMessage(); message.put(ManualMessage.MESSAGE_PARAM, rate); } return DBConstants.NORMAL_RETURN; }
/** * Move the standard payload properties from the message to the xml. * @param message * @param msg */ public void setPayloadProperties(BaseMessage message, Object msg) { MessageDataDesc messageDataDesc = message.getMessageDataDesc(null); // Top level only if (messageDataDesc != null) { Map<String,Class<?>> mapPropertyNames = messageDataDesc.getPayloadPropertyNames(null); if (mapPropertyNames != null) { for (String strKey : mapPropertyNames.keySet()) { Class<?> classKey = mapPropertyNames.get(strKey); this.setPayloadProperty(message, msg, strKey, classKey); } } } if (message.get("Version") == null) this.setPayloadProperty(DEFAULT_VERSION, msg, "Version", Float.class); this.setPayloadProperty(this.getTimeStamp(), msg, "TimeStamp", org.joda.time.DateTime.class); // Current timestamp } /**
message.setProcessedByClientSession(messageTask); // Don't echo back up to my server. message.setProcessedByServer(true); // Don't send this message down to the server. message.setProcessedByServer(true); // Don't send this message down to the server. BaseDatabase database = this.getTable().getCurrentTable().getDatabase(); if (DBConstants.FALSE.equals(database.getProperty(DBParams.MESSAGES_TO_REMOTE))) message.setProcessedByServer(true); // Don't send this message down to the server. if (this.getTask() != null) if (this.getTask().getApplication() instanceof Application) // Always