/** * This gets a String to be split in the message object.It splits the string into substrings and * then stores them in the message object to be apssed to the next processors individually. This * class expects at least a single next processor hence it return a null if there are no next * processors. * * @param msgObj The MesageObject containg the string. * @return NVPair[] Name-Value pair array of next processor name and the MessageObject * @exception ProcessingException Thrown if processing fails */ public NVPair[] process(MessageProcessorContext context, MessageObject msgObj) throws MessageException, ProcessingException { if (Debug.isLevelEnabled(Debug.BENCHMARK)) Debug.log(Debug.BENCHMARK, "Reached Splitter process method.."); // Debug.log(null, Debug.UNIT_TEST,"MESSAGE OBJECT RECEIVED:--->"+msgObj.describe()); if (msgObj == null) { return null; } else if (toProcessorNames == null) { Debug.log(Debug.ALL_WARNINGS, "Splitter: No next processors available. Hence exiting."); } else if (!(msgObj.get() instanceof String)) { if (Debug.isLevelEnabled(Debug.UNIT_TEST)) Debug.log(Debug.UNIT_TEST, "SPLITTER : UNIT_TEST: " + ((msgObj.get()).getClass())); throw new ProcessingException("ERROR: Splitter: " + "The msg Object must be a String."); } if (Debug.isLevelEnabled(Debug.UNIT_TEST)) Debug.log(Debug.UNIT_TEST, "MESSAGE OBJECT RECEIVED:--->" + msgObj.describe()); String batchedRecords = msgObj.getString(); List singleRecord; String subStr = ""; // to take care empty batch files that are valid files in some cases if (!StringUtils.hasValue(batchedRecords)) { Debug.log(Debug.ALL_WARNINGS, "MESSAGE CONTENT IS NULL"); return null; } if (!StringUtils.hasValue(fileSeparator)) // if fileseparator is false... { if (batchedRecords.length() < splitLength) { throw new MessageException( "ERROR: Splitter: " + "Batched String length is less than " + splitLength + "bytes."); } float tempSize = (float) (batchedRecords.length()) / splitLength; int size = (batchedRecords.length()) / splitLength; // check for length of string if (size != tempSize) { throw new MessageException( "ERROR: Splitter: " + "Record received is not of correct length"); } singleRecord = new Vector(size); int i = 0; for (i = 0; i < size; i++) { subStr = batchedRecords.substring(i * splitLength, (i + 1) * splitLength); singleRecord.add(i, subStr); } } else // if fileseparator is true... { singleRecord = new Vector(); StringTokenizer st = new StringTokenizer(batchedRecords, fileSeparator); while (st.hasMoreTokens()) { subStr = st.nextToken(); if (subStr.length() != splitLength) { throw new MessageException( "ERROR: Splitter: Record " + "received after removing the fileseparator is not of correct length ."); } singleRecord.add(subStr); if (Debug.isLevelEnabled(Debug.UNIT_TEST)) Debug.log( Debug.UNIT_TEST, "\nDATA\n" + "********************************************" + subStr); } } if (getBoolean(truncHeaderFooter)) // if truncHeaderFooter is true... { singleRecord.remove((singleRecord.size() - 1)); singleRecord.remove(0); } // else continue... int batchedSize = singleRecord.size(); if (Debug.isLevelEnabled(Debug.UNIT_TEST)) Debug.log(Debug.UNIT_TEST, "BATCHED SIZE--->" + batchedSize); int processorsNo = toProcessorNames.length; NVPair[] contents = new NVPair[batchedSize * processorsNo]; int i = 0; for (i = 0; i < batchedSize; i++) { MessageObject mObj = new MessageObject(); mObj.set(singleRecord.get(i)); // Sending the message objects to the next processors. for (int j = 0; j < processorsNo; j++) { contents[(i * (processorsNo)) + j] = new NVPair(toProcessorNames[j], mObj); if (Debug.isLevelEnabled(Debug.UNIT_TEST)) Debug.log( Debug.UNIT_TEST, "NEXT PROCESSOR-->" + toProcessorNames[j] + "\n" + "MESSAGE OBJECT CONTENT------------>" + mObj.describe()); } } if (Debug.isLevelEnabled(Debug.UNIT_TEST)) Debug.log(Debug.UNIT_TEST, "SPLITTER : CONTEXT---->" + context.describe()); return contents; }
/** * If NF_HEADER_LOCATION_PROP exists in context use as the header to forward to Gateway. If * IS_ASYNCHRONOUS_PROP exists in context then use that value to call either processAsync or * processSync * * @param input MessageObject containing the value to be processed * * @param mpcontext The context * @return Optional NVPair containing a Destination name and a MessageObject, or null if none. * @exception ProcessingException Thrown if processing fails. * @exception MessageException Thrown if bad message. */ public NVPair[] process(MessageProcessorContext ctx, MessageObject input) throws MessageException, ProcessingException { if (input == null) return null; try { serverName = getRequiredProperty(ctx, input, SERVER_NAME_PROP); } catch (MessageException me) { throw new ProcessingException(me.getMessage()); } if (StringUtils.hasValue(headerLocation)) { try { header = getString(headerLocation, ctx, input); } catch (MessageException me) { throw new ProcessingException(me.getMessage()); } } if (StringUtils.hasValue(isAsyncLocation)) { try { isAsync = StringUtils.getBoolean(getString(isAsyncLocation, ctx, input)); } catch (FrameworkException fe) { throw new ProcessingException( "Value of " + IS_ASYNCHRONOUS_LOCATION_PROP + " is not TRUE/FALSE. " + fe.getMessage()); } } // Fetch the alternate Orb Address, if one exists at the specified context location if (StringUtils.hasValue(orbAgentAddrLocation)) { try { if (exists(orbAgentAddrLocation, ctx, input, true)) { orbAgentAddr = getString(orbAgentAddrLocation, ctx, input); if (Debug.isLevelEnabled(Debug.MSG_STATUS)) Debug.log( Debug.MSG_STATUS, "RequestHandlerClient:: alternate orb exists with orb agent address [" + orbAgentAddr + "]"); } } catch (MessageException me) { throw new ProcessingException(me.getMessage()); } } // Fetch the alternate Orb Port, if one exists at the specified context location if (StringUtils.hasValue(orbAgentPortLocation)) { try { if (exists(orbAgentPortLocation, ctx, input, true)) { orbAgentPort = getString(orbAgentPortLocation, ctx, input); if (Debug.isLevelEnabled(Debug.MSG_STATUS)) Debug.log( Debug.MSG_STATUS, "RequestHandlerClient:: alternate orb exists with orb agent port [" + orbAgentPort + "]"); } } catch (MessageException me) { throw new ProcessingException(me.getMessage()); } } String msg = input.getString(); try { try { return (formatNVPair(makeClientCall(serverName, false, header, msg))); } catch (Exception e) { // Any of the following exceptions indicate that the failure might be due to // a CORBA communications issue (stale object reference) that should be retried. if ((e instanceof org.omg.CORBA.OBJECT_NOT_EXIST) || (e instanceof org.omg.CORBA.TRANSIENT) || (e instanceof org.omg.CORBA.COMM_FAILURE) || (e instanceof org.omg.CORBA.INV_OBJREF) || (e instanceof org.omg.CORBA.UNKNOWN)) { Debug.warning( "Caught the following CORBA communication error, so retrying:\n" + e.toString() + "\n" + Debug.getStackTrace(e)); return (formatNVPair(makeClientCall(serverName, true, header, msg))); } else { // It's not a communication exception indicating that retry is recommended, // so just re-throw it. throw e; } } } catch (Exception e) { if (e instanceof InvalidDataException) { Debug.error(e.toString() + "\n" + Debug.getStackTrace(e)); throw new MessageException(((InvalidDataException) e).errorMessage); } else { Debug.error(e.toString() + "\n" + Debug.getStackTrace(e)); throw new ProcessingException(e.toString()); } } }