Exception when parsing a message - messagebroker

I am using a message set to parse a file and I am getting the following exception.I am not able to understand what it actually means.Please help me understand and resolve the problem.
<ParserException>
<File>/build/S000_P/src/MTI/MTIforBroker/MtiImbParser2/MtiImbFIHandler.cpp</File>
<Line>1017</Line>
<Function>MtiImbFIHandler::endMessageContent</Function>
<Type></Type>
<Name></Name>
<Label></Label>
<Catalog>BIPmsgs</Catalog>
<Severity>3</Severity>
<Number>5288</Number>
<Text>MTI. Not all the buffer was used when reading message</Text>
<Insert>
<Type>2</Type>
<Text>0</Text>
</Insert>
<Insert>
<Type>2</Type>
<Text>1659</Text>
</Insert>
</ParserException>

This kind of error happens when the message set "ends" before the data.
For example:
we have got a msg set like this:
NAME - 5 CHAR
SURNAME - 5 CHAR
Data is:
MARIOROSSIAAAAA
Parsed will raise that kind of exception because the msg set don't expect the string "AAAAA" but only:
NAME = "MARIO"
SURNAME = "ROSSI"
Without the precise example is not possibile go any further.

Related

Frame.msg not working with db_decode from cantools

I want to use the can_msgs/Frame.msg for decoding can messages using db.decode_message(Frame.id, Frame.data) but it is giving error
I want to try and write a new Frame.msg format but will it help?
def callback(Frame):
rospy.loginfo(rospy.get_caller_id() + "I heard %s", Frame.data)
Temp = db.decode_message(Frame.id, Frame.data)
temp.data = Temp
pub.publish(temp)
I want to print the message in the dbc format that the cantools package helps decoding.
Error:
File "safa.py", line 42, in callback
temp = db.decode_message(Frame.id, Frame.data)
File "build/bdist.linux-x86_64/egg/cantools/database/can/database.py", line 379, in decode_message
message = self._name_to_message[frame_id_or_name]
KeyError: 10
Looking at the cantools documentation for db.decode_message, the KeyError is a bad description/error msg for the following.
db is a database (class cantools.database.can.Database), which stores all the weird encodings we may choose to use with cantools. To decode a message, it must already have an encoding stored within it, using one of the db.add_* methods with the class.
Edit:
The definition of the can_msgs/Frame is
std_msgs/Header header
uint32 id
bool is_rtr
bool is_extended
bool is_error
uint8 dlc
uint8[8] data
The data term requires an array/list of 8 uint8 values, not a string. Any CANbus data encoding must finish in this form.
Additionally, ROS provides an interface to the CANbus already: socketcan_bridge can be called in a launch file with your node at the same time.
Before you can decode messages you should setup the database e.g by loading a dbc file:
try:
dbc_file_object = open(dbc_file, 'r')
except IOError as e:
rospy.loginfo('Unable to open file {}'.format(e))
sys.exit(-1)
self.db = cantools.db.load(dbc_file_object)

reserved keyword in dynamodb - Swift 3

Here is code:
queryExpression.keyConditionExpression = "#userId= :userId"
queryExpression.expressionAttributeNames = ["#userId":"userId", "#status":"status"]
queryExpression.expressionAttributeValues = [":userId":userID, ":status":"accept"]
queryExpression.projectionExpression = "status"
but I got the following error and I didnt know that status word is a reserved word in DynamoDB:
Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=0 "(null)" UserInfo={message=Invalid ProjectionExpression: Attribute name is a reserved keyword; reserved keyword: status, __type=com.amazon.coral.validate#ValidationException}
I have looked at the below link but I do not understand it and I can't find a Swift example. How do I accomplish this?
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html#Expressions.ExpressionAttributeNames.ReservedWords
I am new to DynamoDB things.
Thanks!
Here is a list of all the reserved words in DynamoDB:
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html
so ExpressionAttributeNames and expressionAttributeValues are ways of aliasing to use #fooattribute and :foovalue even if foo were a reserved word within the above list.
So in your case, I believe your error is because the term status is reserved, you may try changing your last line to be :
queryExpression.projectionExpression = "#status"
That way you wouldn't be using the reserved word, it would read the alias instead. That alias would resolve to your actual attribute name which might as well be status.

How to remove non-ascii char from MQ messages with ESQL

CONCLUSION:
For some reason the flow wouldn't let me convert the incoming message to a BLOB by changing the Message Domain property of the Input Node so I added a Reset Content Descriptor node before the Compute Node with the code from the accepted answer. On the line that parses the XML and creates the XMLNSC Child for the message I was getting a 'CHARACTER:Invalid wire format received' error so I took that line out and added another Reset Content Descriptor node after the Compute Node instead. Now it parses and replaces the Unicode characters with spaces. So now it doesn't crash.
Here is the code for the added Compute Node:
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
DECLARE NonPrintable BLOB X'0001020304050607080B0C0E0F101112131415161718191A1B1C1D1E1F7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF1F2F3F4F5F6F7F8F9FAFBFCFDFEFF';
DECLARE Printable BLOB X'20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020';
DECLARE Fixed BLOB TRANSLATE(InputRoot.BLOB.BLOB, NonPrintable, Printable);
SET OutputRoot = InputRoot;
SET OutputRoot.BLOB.BLOB = Fixed;
RETURN TRUE;
END;
UPDATE:
The message is being parsed as XML using XMLNSC. Thought that would cause a problem, but it does not appear to be.
Now I'm using PHP. I've created a node to plug into the legacy flow. Here's the relevant code:
class fixIncompetence {
function evaluate ($output_assembly,$input_assembly) {
$output_assembly->MRM = $input_assembly->MRM;
$output_assembly->MQMD = $input_assembly->MQMD;
$tmp = htmlentities($input_assembly->MRM->VALUE_TO_FIX, ENT_HTML5|ENT_SUBSTITUTE,'UTF-8');
if (!empty($tmp)) {
$output_assembly->MRM->VALUE_TO_FIX = $tmp;
}
// Ensure there are no null MRM fields. MessageBroker is strict.
foreach ($output_assembly->MRM as $key => $val) {
if (empty($val)) {
$output_assembly->MRM->$key = '';
}
}
}
}
Right now I'm getting a vague error about read only messages, but before that it wasn't working either.
Original Question:
For some reason I am unable to impress upon the senders of our MQ
messages that smart quotes, endashes, emdashes, and such crash our XML
parser.
I managed to make a working solution with SQL queries, but it wasted
too many resources. Here's the last thing I tried, but it didn't work
either:
CREATE FUNCTION CLEAN(IN STR CHAR) RETURNS CHAR BEGIN
SET STR = REPLACE('–',STR,'–');
SET STR = REPLACE('—',STR,'—');
SET STR = REPLACE('·',STR,'·');
SET STR = REPLACE('“',STR,'“');
SET STR = REPLACE('”',STR,'”');
SET STR = REPLACE('‘',STR,'&lsqo;');
SET STR = REPLACE('’',STR,'’');
SET STR = REPLACE('•',STR,'•');
SET STR = REPLACE('°',STR,'°');
RETURN STR;
END;
As you can see I'm not very good at this. I have tried reading about
various ESQL string functions without much success.
So in ESQL you can use the TRANSLATE function.
The following is a snippet I use to clean up a BLOB containing non-ASCII low hex values so that it then be cast into a usable character string.
You should be able to modify it to change your undesired characters into something more benign. Basically each hex value in NonPrintable gets translated into its positional equivalent in Printable, in this case always a full-stop i.e. x'2E' in ASCII. You'll need to make your BLOB's long enough to cover the desired range of hex values.
DECLARE NonPrintable BLOB X'000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F';
DECLARE Printable BLOB X'2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E';
SET WorkBlob = TRANSLATE(WorkBlob, NonPrintable, Printable);
BTW if messages with invalid characters only come in every now and then I'd probably specify BLOB on the input node and then use something similar to the following to invoke the XMLNSC parser.
CREATE LASTCHILD OF OutputRoot DOMAIN 'XMLNSC'
PARSE(InputRoot.BLOB.BLOB CCSID InputRoot.Properties.CodedCharSetId ENCODING InputRoot.Properties.Encoding);
With the exception terminal wired up you can then correct the BLOB's of any messages containing parser breaking invalid characters before attempting to reparse.
Finally my best wishes as I've had a number of battles over the years with being forced to correct invalid message content in the "Integration Layer" after all that's what it's meant to do.

XSLT 2.0. Loop inside a Function

Hitting my wall here...
I've got the following data where a Primary Employee may have multiple dependents. I need to create a function that will match the Employee's SSN (ab:SSN) against the Dependent_SSN and determine if one of them is a 'Spouse'. If so, then we'll return the Dependent_SSN of the 'Spouse'.
If not, we'll move on and return the next non-'Spouse' Dependent_SSN.
I'm trying to create a function as I think I'll need this more than once. The code snippet resides inside of an existing template that is doing other looping functionality.
I've tried this but Oxygen returns an error:
<xsl:function name="ab:PQB">
<xsl:param name="EE_SSN">
</xsl:param>
<xsl:for-each select="/ab:Report_Data/ab:Report_Entry[ab:Employee_ID=$EE_SSN]/ab:Report_Data/ab:Report_Entry[ab:Employee_ID=$EE_SSN]ab:dependents/ab:Dependent_SSN">
</xsl:for-each>
The Error returned is :
"Engine name: Saxon-PE 9.3.0.5
Severity: fatal
Description: Unexpected token name "wd:dependents" beyond end of expression"
I know I need to test the higher level SSN against looping through the dependents, but like I said "I'm against my wall" :)
Data is here:
<ab:Report_Entry>
<ab:SSN>888881006</ab:SSN>
<ab:Last_Name>Smith</ab:Last_Name>
<ab:First_Name>Kimberly</ab:First_Name>
<ab:dependents>
<ab:Dependent_SSN>888881009</ab:Dependent_SSN>
<ab:Relation ab:Descriptor="Spouse">
</ab:Relation>
</ab:dependents>
<ab:dependents>
<ab:Dependent_SSN>888881004</ab:Dependent_SSN>
<ab:Relation ab:Descriptor="Child">
</ab:Relation>
</ab:dependents>
<ab:dependents>
<ab:Dependent_SSN>888881003</ab:Dependent_SSN>
<ab:Relation ab:Descriptor="Child">
<ab:ID ab:type="Related_Person_Relationship_ID">Child</ab:ID>
</ab:Relation>
</ab:dependents>
<ab:dependents>
<ab:Dependent_SSN>888881001</ab:Dependent_SSN>
<ab:Dependent_ID>1032D-4</ab:Dependent_ID>
<ab:Relation ab:Descriptor="Child">
<ab:ID ab:type="Related_Person_Relationship_ID">Child</ab:ID>
</ab:Relation>
</ab:dependents>
</ab:Report_Entry>
Thank you to any advice!
You might want to define the type of the input parameter and the type of the function result and then you should write a function body returning a value of that type. Currently your description sounds rather procedural, that is not going to work with XSLT/XPath.
As for the error, I think in the path /ab:Report_Data/ab:Report_Entry[ab:Employee_ID=$EE_SSN]/ab:Report_Data/ab:Report_Entry[ab:Employee_ID=$EE_SSN]ab:dependents/ab:Dependent_SSN you need one more slash /ab:Report_Data/ab:Report_Entry[ab:Employee_ID=$EE_SSN]/ab:Report_Data/ab:Report_Entry[ab:Employee_ID=$EE_SSN]/ab:dependents/ab:Dependent_SSN to have a syntactically correct path. That should avoid the syntax error you get but is not likely to return the result you want.

Problems with smooks

I am currently evaluating smooks (www.smooks.org). It looks just like what we need but I am having problems getting a simple example to work.
I've got an ant script which downloads me all the dependencies including the mapping and binding jars for EDIFACT messages.
I am trying to convert a simple EDIFACT APERAK message to Java using their EJC (I am using JavaSE for this little test).
The conversion fails with an exception that some block wasn't expected (see below). So I am wondering whether I am missing some configuration (notice the first few lines in the log output).
Has anyone worked with Smooks' EJC? How can I get more info about what line it is complaining?
So this is the code:
D00BInterchangeFactory factory = D00BInterchangeFactory.getInstance();
File file = new File("aperak.edi");
BufferedInputStream ediSource = new BufferedInputStream(new FileInputStream(file));
StreamResult xmlStream = new StreamResult();
StringWriter xmlWriter = new StringWriter();
xmlStream.setWriter(xmlWriter);
UNEdifactInterchange interchange = factory.fromUNEdifact(ediSource);
//System.err.println("MEssage "+xmlWriter.toString());
if(interchange instanceof UNEdifactInterchange41){
UNEdifactInterchange41 interchange41 = (UNEdifactInterchange41)interchange;
for(UNEdifactMessage41 message: interchange41.getMessages()){
Object messageObj = message.getMessage();
System.err.println("Ref Num "+message.getMessageHeader().getMessageRefNum());
if(messageObj instanceof Aperak){
Aperak aperak = (Aperak)message.getMessage();
System.err.println("Aperak "+aperak);
}
}
}
When I run it I get this exception
02-Nov-2011 15:58:09 org.milyn.delivery.ContentDeliveryConfigBuilder$ContentHandlerExtractionStrategy addCDU
WARNING: ContentHandlerFactory [org.milyn.delivery.JavaContentHandlerFactory] unable to create resource processing instance for resource [Target Profile: [[*]], Selector: [cdu-creator], Selector Namespace URI: [null], Resource: [org.milyn.smooks.scripting.groovy.GroovyContentHandlerFactory], Num Params: [1]]. org/codehaus/groovy/control/CompilationFailedException
02-Nov-2011 15:58:10 org.milyn.delivery.ContentDeliveryConfigBuilder$ContentHandlerExtractionStrategy addCDU
WARNING: ContentHandlerFactory [org.milyn.delivery.JavaContentHandlerFactory] unable to create resource processing instance for resource [Target Profile: [[*]], Selector: [cdu-creator], Selector Namespace URI: [null], Resource: [org.milyn.smooks.scripting.groovy.GroovyContentHandlerFactory], Num Params: [1]]. org/codehaus/groovy/control/CompilationFailedException
Exception in thread "main" org.milyn.SmooksException: Failed to filter source.
at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:86)
at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:61)
at org.milyn.Smooks._filter(Smooks.java:516)
at org.milyn.Smooks.filterSource(Smooks.java:475)
at org.milyn.Smooks.filterSource(Smooks.java:449)
at org.milyn.edi.unedifact.d00b.D00BInterchangeFactory.fromUNEdifact(D00BInterchangeFactory.java:58)
at org.milyn.edi.unedifact.d00b.D00BInterchangeFactory.fromUNEdifact(D00BInterchangeFactory.java:40)
at EDITestReader.readFile(EDITestReader.java:37)
at EDITestReader.main(EDITestReader.java:59)
Caused by: org.xml.sax.SAXException: Unknown/Unexpected UN/EDIFACT control block segment code '
UN'.
at org.milyn.edisax.unedifact.handlers.r41.UNEdifact41ControlBlockHandlerFactory.getControlBlockHandler(UNEdifact41ControlBlockHandlerFactory.java:53)
at org.milyn.edisax.unedifact.UNEdifactInterchangeParser.parse(UNEdifactInterchangeParser.java:95)
at org.milyn.smooks.edi.unedifact.UNEdifactReader.parse(UNEdifactReader.java:77)
at org.milyn.delivery.sax.SAXParser.parse(SAXParser.java:70)
at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:75)
... 8 more
enter code here
The actual EDIFACT message is fairly simple:
UNA:+.? '
UNB+UNOC:3+IMP+XXX+20110902:1024+44090560'
UNH+440905601+APERAK:D:00B:UN:IMP10'
BGM+313++9+RE'
RFF+ACW:XXXXXXXXX1109020'
DTM+182:201109021018:203'
RFF+BM:XXXXXXXXX'
RFF+AGO:XXXXXXX1109020'
RFF+EQ:XXXXXXXX'
NAD+MS+IMP'
CTA+MS+:EDI'
COM+XXXXXXXXXXX:TE'
COM+support#XXXXX.XX:EM'
ERC+200:IMP02:DAK'
FTX+AAO+++ERR4045?: Gest.datum ist mehr als 90 Tage kleiner als das Tagesdatum+DE'
UNT+14+440905601'
UNZ+1+44090560'
When I remove the leading UNA and UNB segment it comes up with this exception: ([APERAK][D:00B:UN]. Must be a minimum of 1 instances of segment [BGM]). There is a BGM segment so I am not sure why it is complaining.
Caused by: org.milyn.edisax.EDIParseException: EDI message processing failed [APERAK][D:00B:UN]. Must be a minimum of 1 instances of segment [BGM]. Currently at segment number 2.
at org.milyn.edisax.EDIParser.mapSegments(EDIParser.java:460)
at org.milyn.edisax.EDIParser.mapSegments(EDIParser.java:411)
at org.milyn.edisax.EDIParser.parse(EDIParser.java:387)
at org.milyn.edisax.EDIParser.parse(EDIParser.java:371)
at org.milyn.edisax.unedifact.handlers.r41.UNHHandler.process(UNHHandler.java:80)
at org.milyn.edisax.unedifact.UNEdifactInterchangeParser.parse(UNEdifactInterchangeParser.java:98)
at org.milyn.smooks.edi.unedifact.UNEdifactReader.parse(UNEdifactReader.java:77)
at org.milyn.delivery.sax.SAXParser.parse(SAXParser.java:70)
UPDATE:
When I remove the carriage returns from the message
UNH+440905601+APERAK:D:00B:UN:IMP10'BGM+313++9+RE'RFF+ACW:XXXXXXXXX1109020'DTM+182:201109021018:203'
it works fine. But how do I get smooks to accept carriage returns and whitespaces and the two leading UNA/UNB segments? I probably skipped some part of message processing smooks normally does.
UPDATE 2:
Figured out UNA/UNB segments are supported (my mistake) but I am still having problems with the carriage returns.
Renat suggested to use a 'ignoreNewLines' option on the EDIParser. I've tried that but it doesn't seem to make a difference. I've also tried to configure smooks with this:
<?xml version="1.0" encoding="UTF-8"?>
<smooks-resource-list
xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:edi="http://www.milyn.org/xsd/smooks/edi-1.4.xsd">
<edi:reader mappingModel="/org/milyn/smooks/edi/xsd14/edi-to-xml-mapping.xml" ignoreNewLines="true" />
</smooks-resource-list>
Again with no success.
I have the feeling that the D00AInterchangeFactory (or what every version you use) configures its EDIParser differently and ignoreNewLines is ignored.
Is there a way to get the EDIParser the InterchangeFactory is using?
You need to add enable 'ignore new line' switch on the EDIParser.
You have multiple ways to do that, for example you can use a XMLReader#setFeature()
http://download.oracle.com/javase/1.5.0/docs/api/org/xml/sax/XMLReader.html#setFeature(java.lang.String,%20boolean)
or directly via EDIParser method call. See samples here
https://gist.github.com/825845
and here
https://gist.github.com/825843
Renat

Resources