0

I'm tryng samples projects to understand how to use the Optaplanner features (using ver. 7.11-Final on wildfly11). I installed some built-in samples and now I encountered a very strange error after using an employee rostering sample modified by me, when I try to post different xml via REST API (using SOAP-UI).

Using the following xml (excerpt) it work well, I can submit the xml without problem and retrieve the best solution calling the related endpoint:

    <TeamRoster>
        <employeeList>
            <Employee>
                <name>Luigi</name>
            </Employee>
            <Employee>
                <name>Mauro</name>
            </Employee>
            <Employee>
                <name>Pietro</name>
            </Employee>
            <Employee>
                <name>Gino</name>
            </Employee>
        </employeeList>
        <teamList>
            <Team>
                <name>Squadra 1</name>
                <employeeList>
                    <Employee reference="../../../../employeeList/Employee"/>
                    <Employee reference="../../../../employeeList/Employee[2]"/>
                </employeeList>
                .........

Instead, using the following modified xml (with id/reference):

        <TeamRoster id="1">
            <employeeList id="2">
                <Employee id="3">
                    <id>0</id>
                    <name>Luigi</name>
                </Employee>
                <Employee id="4">
                    <id>1</id>
                    <name>Mauro</name>
                </Employee>
                <Employee id="5">
                    <id>2</id>
                    <name>Pietro</name>
                </Employee>
                <Employee id="6">
                    <id>3</id>
                    <name>Gino</name>
                </Employee>
            </employeeList>
            <teamList id="7">
                <Team id="8">
                    <id>0</id>
                    <name>Squadra 1</name>
                    <employeeList id="9">
                        <Employee reference="3"/>
                        <Employee reference="4"/>
                    </employeeList>

The response of kie server is a message error:

com.thoughtworks.xstream.converters.ConversionException: Invalid reference

with details:

    message             : Invalid reference
    reference           : 3
    referenced-type     : com.linkit.trostering.Employee
    referenceable       : true
    class               : java.util.ArrayList
    required-type       : java.util.ArrayList
    converter-type      : com.thoughtworks.xstream.converters.collections.CollectionConverter
    path                : /TeamRoster/teamList/Team/employeeList/Employee
    line number         : 25
    class[1]            : com.linkit.trostering.Team
    converter-type[1]   : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
    class[2]            : com.linkit.trostering.TeamRoster
    version             : 7.11.0.Final

I've seen that other samples included in optaplanner samples project use this option (if I understand it's a xtream feature) to reference fact already defined using id instead the xml path.

Now my doubt is if Optaplanner wb with kie server is shipped with xstream different settings? Is there any option that must be send via REST to use this feature of xtream? Any other thing?

Thanks in advance for any help that is very appreciated

giovanni
  • 105
  • 12
  • Note that this a pure XStream problem - for OptaPlanner, the input are Java objects (such as Employee, Team and TeamRoster), XStream transforms the XML to java objects before giving it to OptaPlanner. – Geoffrey De Smet Oct 03 '18 at 12:06
  • It clear that is a XStream problem :-) , but It'snt clear where to put the setting in the Optaplanner WB (or in the REST API call?) to tset XStream correct mode. – giovanni Oct 03 '18 at 12:15
  • Ah, my mistake. When running with OptaPlanner Execution Server (= kie-server), this makes sense of course. – Geoffrey De Smet Oct 03 '18 at 12:28

1 Answers1

0

Your first xml uses XPath references. Your second xml uses id references. The second one requires a different XStream setup:

xStream = new XStream();
xStream.setMode(XStream.ID_REFERENCES);
Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
  • thanks @geoffrey-de-smet, but I'm using Optaplanner 7.11FINAL (kie-wb + kie-server), not optaplanner jars with custom java project. so where I can set this option? There is some config file in the assets of the project? In the entity class POJO source code? – giovanni Oct 03 '18 at 12:10
  • I don't know by heart if there's a way to configure the Xstream mode to ID_REFERENCES. If it exists, I'd expect it to be mentioned in the kie-server user guide (general chapter, not optaplanner specific) - similar to how there's a http parameter to switch between xstream xml, jaxb xml and jackson json. – Geoffrey De Smet Oct 03 '18 at 12:32
  • It is the place where I search for some suggestion about XStream settings, but I didn't found any related to id/reference mode :-( – giovanni Oct 03 '18 at 12:35
  • Good point. Open a ticket for an RFE (access.redhat.com or issues.jboss.org). Workaround is to use XPath references. – Geoffrey De Smet Oct 03 '18 at 13:26
  • 1
    Thanks @Geoffrey, I submit a [RFE](https://issues.jboss.org/browse/DROOLS-3075) on drools project, It will be very usefull to have this type of setting via http header (or in other way) because xml with xpath reference is very hard to read by users and produce by apps comsuming kie-server via rest api. – giovanni Oct 03 '18 at 14:16