java.lang.StringIndexOutOfBoundsException: smooks

43 views
Skip to first unread message

Serena Angelucci

unread,
Nov 29, 2024, 10:21:11 AM11/29/24
to Smooks Users
Hello, 
I have a custom edifact parser that works with a List:
List<Group4> group4 
where group4 contains an element RTI.
I have defined the .XML file in this way:

<jb:bean beanId="Group4_List" class="java.util.ArrayList" createOnElement="${EDIFACTCarAvailRuleRequest1P}">

<jb:wiring beanIdRef="Group4" />

</jb:bean>


<jb:bean beanId="Group4" class="com.travelport.car.at.cdcp.model.edifact.availrule.onep.request.Group4" createOnElement="${EDIFACTCarAvailRuleRequest1P}/Group4">

<jb:wiring property="rti" beanIdRef="rti" />

</jb:bean>


<jb:bean beanId="rti" class="com.travelport.car.at.cdcp.model.edifact.availrule.onep.request.Rti" createOnElement="${Group4}/rti">

<jb:wiring property="rateIdentificationDetails" beanIdRef="rateIdentificationDetails" />

</jb:bean>


<jb:bean beanId="rateIdentificationDetails" class="com.travelport.car.at.cdcp.model.edifact.availrule.onep.request.field.RateIdentificationDetails" createOnElement="${rti}/rateIdentificationDetails">

<jb:value property="rateTariffClassIdentificationCode" data="#/rateTariffClassIdentificationCode" default="null"/>

</jb:bean>


and the .dfdl file:

<xsd:element name="Group4" maxOccurs="unbounded" dfdl:ref="ibmEdiFmt:EDISegmentFormat">

<xsd:complexType>

<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">

<xsd:element dfdl:initiator="RTI" name="rti" minOccurs="1" maxOccurs="1" dfdl:ref="ibmEdiFmt:EDISegmentFormat">

<xsd:complexType>

<xsd:sequence dfdl:ref="ibmEdiFmt:EDICompositeSequenceFormat">

<xsd:element name="rateIdentificationDetails">

<xsd:complexType>

<xsd:sequence dfdl:ref="ibmEdiFmt:EDICompositeSequenceFormat">

<xsd:element name="rateTariffClassIdentificationCode" type="xsd:string"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

</xsd:sequence>

</xsd:complexType>

</xsd:element>


But when I try to execute the code I receive this error:


Caused by: java.lang.StringIndexOutOfBoundsException: begin -1, end 31, length 31
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4604)
at java.base/java.lang.String.substring(String.java:2707)
at java.base/java.lang.String.substring(String.java:2680)
at org.smooks.cartridges.javabean.MapToSelectorFromContextAwareAttribute.resolveBeandIdSelector(MapToSelectorFromContextAwareAttribute.java:116)
at org.smooks.cartridges.javabean.MapToSelectorFromContextAwareAttribute.visitBefore(MapToSelectorFromContextAwareAttribute.java:107)



Could you please help me to understand where is the error?


Thanks in advance,

Serena

Claude Mamo

unread,
Dec 2, 2024, 5:18:14 AM12/2/24
to smook...@googlegroups.com
Are those Spring placeholders in the createOnElement selectors? Smooks does not support Spring though it would be nice to have.

Claude

--
You received this message because you are subscribed to the Google Groups "Smooks Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smooks-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/smooks-user/496a7145-5eef-4430-bf59-9a0538d31a63n%40googlegroups.com.

Serena Angelucci

unread,
Dec 3, 2024, 6:03:45 AM12/3/24
to Smooks Users
Hi Claude, 
Yes, as you can see in the previous code, but nothing changed....I solved the issue removing the arrayList definition:

<jb:bean beanId="Group4_List" class="java.util.ArrayList" createOnElement="${EDIFACTCarAvailRuleRequest1P}">

<jb:wiring beanIdRef="Group4" />

</jb:bean>


Now I have another error, but I'm not able to understand what I'm doing wrong:

Caused by: org.apache.daffodil.lib.exceptions.UsageException: Usage error: Attempted to use an invalid input source. This can happen due to our position in the input source not being properly reset after failed parse could not backtrack to its original position (state.dataInputStreamIsValid)

Thanks, 
Serena

Claude

unread,
Dec 4, 2024, 2:48:10 AM12/4/24
to Smooks Users
I'm a bit lost here. The selectors look invalid to me so I reckon that's why it wasn't working in the first place. Those dollar-sign placeholders are not supported unless you're doing some kind of pre-processing. Regarding the second error,  do you get the error if you remove all the JavaBean bindings?

Serena Angelucci

unread,
Dec 4, 2024, 4:00:05 AM12/4/24
to smook...@googlegroups.com
I'm trying to explain what I should do....
I have a bean named EDIFACTCarAvailRuleRequest1P that contains a List< Group4  > element that contains  rti  object (that maps the edifact  RTI  element)

I mapped it in this way:

<jb:bean beanId="Group4_List" class="java.util.ArrayList" createOnElement="${EDIFACTCarAvailRuleRequest1P}">

<jb:wiring beanIdRef="Group4" />

</jb:bean>


<jb:bean beanId="Group4" class="com.travelport.car.at.cdcp.model.edifact.availrule.onep.request.Group4" createOnElement="${EDIFACTCarAvailRuleRequest1P}/Group4">

<jb:wiring property="rti" beanIdRef="rti" />

</jb:bean>


<jb:bean beanId="rti" class="com.travelport.car.at.cdcp.model.edifact.availrule.onep.request.Rti" createOnElement="${Group4}/rti">

<jb:wiring property="rateIdentificationDetails" beanIdRef="rateIdentificationDetails" />

</jb:bean>


and the edifact that I should map is ...RTI+9'


In your opinion, what is wrong?


Serena Angelucci

unread,
Dec 4, 2024, 4:28:02 AM12/4/24
to Smooks Users
The error that I received is:

org.smooks.api.SmooksException: Failed to apply processing unit [org.smooks.cartridges.javabean.MapToSelectorFromContextAwareAttribute] to [org:smooks:unknowndoc:/smooks-resource-list/jb:bean[43]].
at org.smooks.engine.delivery.dom.SmooksDOMFilter.processVisitorException(SmooksDOMFilter.java:889)
at org.smooks.engine.delivery.dom.SmooksDOMFilter.access$700(SmooksDOMFilter.java:186)
at org.smooks.engine.delivery.dom.SmooksDOMFilter$ElementProcessor.processMapping(SmooksDOMFilter.java:831)
at org.smooks.engine.delivery.dom.SmooksDOMFilter$ElementProcessor.process(SmooksDOMFilter.java:778)
at org.smooks.engine.delivery.dom.SmooksDOMFilter$ElementProcessor.access$000(SmooksDOMFilter.java:736)
at org.smooks.engine.delivery.dom.SmooksDOMFilter.filter(SmooksDOMFilter.java:466)
at org.smooks.engine.delivery.dom.SmooksDOMFilter.doFilter(SmooksDOMFilter.java:296)
at org.smooks.engine.delivery.dom.SmooksDOMFilter.doFilter(SmooksDOMFilter.java:274)
at org.smooks.Smooks._filter(Smooks.java:551)
at org.smooks.Smooks.filterSource(Smooks.java:510)
at org.smooks.engine.resource.config.loader.xml.XmlResourceConfigLoader.loadExtendedResourceConfig(XmlResourceConfigLoader.java:417)
at org.smooks.engine.resource.config.loader.xml.XmlResourceConfigLoader.loadV20XSDValidatedConfig(XmlResourceConfigLoader.java:212)
at org.smooks.engine.resource.config.loader.xml.XmlResourceConfigLoader.loadConfigRecursively(XmlResourceConfigLoader.java:169)
at org.smooks.engine.resource.config.loader.xml.XmlResourceConfigLoader.load(XmlResourceConfigLoader.java:140)
at org.smooks.engine.DefaultRegistry.registerResources(DefaultRegistry.java:179)
at org.smooks.Smooks.addResourceConfigs(Smooks.java:379)
at org.smooks.Smooks.addResourceConfigs(Smooks.java:351)
at org.smooks.Smooks.<init>(Smooks.java:205)
at com.travelport.car.at.cdcp.model.edifact.availrule.ConvertFromEdiToJavaOnePTestCase.convertFromEdiToJava(ConvertFromEdiToJavaOnePTestCase.java:75)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Caused by: java.lang.StringIndexOutOfBoundsException: begin -1, end 31, length 31
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4604)
at java.base/java.lang.String.substring(String.java:2707)
at java.base/java.lang.String.substring(String.java:2680)
at org.smooks.cartridges.javabean.MapToSelectorFromContextAwareAttribute.resolveBeandIdSelector(MapToSelectorFromContextAwareAttribute.java:116)
at org.smooks.cartridges.javabean.MapToSelectorFromContextAwareAttribute.visitBefore(MapToSelectorFromContextAwareAttribute.java:107)
at org.smooks.engine.delivery.dom.SmooksDOMFilter$ElementProcessor.processMapping(SmooksDOMFilter.java:825)
... 19 more



Message has been deleted

Serena Angelucci

unread,
Dec 4, 2024, 5:05:26 AM12/4/24
to Smooks Users
I removed the placeholder ${...}, but I got the same error :(

Claude

unread,
Dec 5, 2024, 3:31:00 AM12/5/24
to Smooks Users
Could you upload the project somewhere like in a GitHub repo so I can take a glance at it?

Serena Angelucci

unread,
Dec 5, 2024, 6:38:46 AM12/5/24
to Smooks Users
Sure Claude. Here it is my personal repo URL:

Claude Mamo

unread,
Dec 5, 2024, 7:06:03 AM12/5/24
to smook...@googlegroups.com
Nothing happens when I run "mvn clean test"

Serena Angelucci

unread,
Dec 5, 2024, 8:42:05 AM12/5/24
to Smooks Users
Could you please pull from the repo?

Claude Mamo

unread,
Dec 5, 2024, 11:40:43 AM12/5/24
to smook...@googlegroups.com
The EDIFACT segment group group4 doesn't seem to modelled correctly in your DFDL schema. In fact, edi:parser is choking on the "RTI" segment. EDIFACT segment groups can be tricky to model but you can find plenty of examples of segment groups in one the EDIFACT schema packs.

I don't have the full context of your project though I'm wondering why Java binding is performed from within Smooks instead of using XStream or JAXB like in https://github.com/smooks/smooks-examples/tree/v4/edifact-to-java . The latter just seems to be easier to me unless you have one big EDIFACT file to process and you want to leverage Smooks's streaming capabilities.

Claude

Serena Angelucci

unread,
Dec 6, 2024, 4:01:44 AM12/6/24
to Smooks Users
Hello Claude, 
I used Smooks some years ago to parse the edifact message using jdk8, so now I need to move it to java17....this is not a new implementation. For this reason, I can't change the binding implementation.

Regarding the junit failure, I got this error:

org.smooks.api.SmooksException: Failed to filter source
at org.smooks.engine.delivery.sax.ng.SaxNgFilter.doFilter(SaxNgFilter.java:122)
at org.smooks.engine.delivery.sax.ng.SaxNgFilter.doFilter(SaxNgFilter.java:94)

at org.smooks.Smooks._filter(Smooks.java:551)
at org.smooks.Smooks.filterSource(Smooks.java:510)
at com.smookspoc.car.at.cdcp.model.edifact.availrule.ConvertFromEdiToJavaOnePTestCase.runSmooksTransform(ConvertFromEdiToJavaOnePTestCase.java:90)
at com.smookspoc.car.at.cdcp.model.edifact.availrule.ConvertFromEdiToJavaOnePTestCase.convertFromEdiToJava(ConvertFromEdiToJavaOnePTestCase.java:80)

at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by: org.smooks.cartridges.dfdl.parser.ParserDfdlSmooksException: Parse Error: Initiator 'UIB' not found
Schema context: uib Location line 18 column 22 in .../model/edifact/availrule/edi-mapping-1p-request.dfdl.xsd
Data location was preceding byte 141
at org.smooks.cartridges.dfdl.parser.DfdlParser.parse(DfdlParser.java:228)
at org.smooks.engine.delivery.sax.ng.SaxNgParser.parse(SaxNgParser.java:87)
at org.smooks.engine.delivery.sax.ng.SaxNgFilter.doFilter(SaxNgFilter.java:110)
... 8 more
Caused by: Parse Error: Initiator 'UIB' not found
Schema context: uib Location line 18 column 22 in .../model/edifact/availrule/edi-mapping-1p-request.dfdl.xsd
Data location was preceding byte 141

that is not clear to understand what is the error cause. Is there a way to have the real exception message?

Claude Mamo

unread,
Dec 6, 2024, 5:50:43 AM12/6/24
to smook...@googlegroups.com
that is not clear to understand what is the error cause. Is there a way to have the real exception message?

Yeah, DFDL error messages can be counterintuitive. In your case, edi:parser is not expecting the RTI segment (because it's not modelled correctly in your schema) so edi:parser mistakenly concludes that it has reached the end of the current UIB message being parsed. However, edi:parser has not reached the EOF in the input stream, therefore it assumes that there's another UIB message to parse. Since edi:parser finds an RTI segment instead of a UIB segment identifying the beginning of the message, you get this error: "Initiator 'UIB' not found"

Claude

Reply all
Reply to author
Forward
0 new messages