How to set XStream mode in kie-server to use id/reference

64 views
Skip to first unread message

Giovanni Martano

unread,
Oct 3, 2018, 8:58:26 AM10/3/18
to Drools Setup

I'm tryng optaplanner xml solution posting sample data to kie-server (ver. 7.11-FINAL)  on wildfly11, via REST API (using SOAP-UI). 

I deployed some sample project via kie-wb and I can successfully test  sample xml with XPath reference to previous fact, so I can submit the XML data and get the best-solution calling the related endpoint.

But when I try to use id/reference for previous fact i get the com.thoughtworks.xstream.converters.ConversionException: Invalid reference error pointing to the xml line where I change XPath reference with id/reference. I found that XStream has a setting to process the incoming xml in the right way (XStream.ID_REFERENCES), but I canno't found in the kie-wb/kie-server how to set this mode.




Any help is very appreciated, thanks




Giovanni

Giovanni Martano

unread,
Oct 3, 2018, 10:45:25 AM10/3/18
to Drools Setup
I open a RFE on jboss jira   https://issues.jboss.org/browse/DROOLS-3075

Maciej Swiderski

unread,
Oct 3, 2018, 1:14:38 PM10/3/18
to drools...@googlegroups.com
Could you provide bit more information how you interact between workbench and kie server and where do you want to have the xstream option enabled?

Maciej

--
You received this message because you are subscribed to the Google Groups "Drools Setup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-setup...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-setup/8029ccde-594a-4e8e-9061-627022f47c58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Giovanni Martano

unread,
Oct 3, 2018, 4:28:44 PM10/3/18
to Drools Setup
Hi Maciej, thanks for your reply....well, I'm using kie-wb trought the GUI (I deployed kie-drools-wb and kie-server on wildlfy 11) to create a sample (optaplanner) project and deploy it in kie-server instance (using the deploy feature of kie-wb GUI). Then I interact with kie-server via rest api endpoints using SOAP-UI as client.
I don't know where is the best place to put the necessary xstream setting, I only found that in the scenario I described above I can't use xstream id_references mode option (kie-server respond with the reported error).
If it can be in the http header of rest request or in xml solver config, or in another place... I really don't know ...I'm not the right person to suggest where :-)

Maciej Swiderski

unread,
Oct 4, 2018, 2:24:35 AM10/4/18
to drools...@googlegroups.com
Giovanni,

You can set following HTTP header for the request to instruct kie server that the content and the response should be in xstream format
Name: X-KIE-ContentType
Value: XSTREAM

Is that what you are after?

Maciej

Giovanni Martano

unread,
Oct 4, 2018, 4:16:51 AM10/4/18
to Drools Setup
Well, but I know this feature and I already setted the header when submit xml, the problem is that when in xml body of solution  I try to use id/reference (instead of XPath) for previous fact i get the com.thoughtworks.xstream.converters.ConversionException: Invalid reference error pointing to the xml line where I change XPath reference with id/reference. I found that XStream has a setting to process the incoming xml in the right way (XStream.ID_REFERENCES), but I canno't found in the kie-wb/kie-server how to set this mode.

To be more clear, the following XML work well (where I use Xpath for reference):

<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>
                .........

With this one, instead, I receive from kie-server (after submit xml via rest with SOAP-UI client) com.thoughtworks.xstream.converters.ConversionException: Invalid 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 difference is, as you can see, that I change reference to previous fact with id's instead of XPath.
On stackoverflow Geoffrey De Smet (Lead optaplanner sw dev) reply that XStream has a setting param to process well this type of xml, using in code it will be
xStream = new XStream();
xStream.setMode(XStream.ID_REFERENCES);

But I'm using kie-wb GUI do develop and kie-server for deploy my project, so I have no access directly to XStream library to set this param. So, i conclude, that must be (it will be appreciated) present in some place on kie-server the possibility to set this param, and describe as sample (suggested by Geoffrey) the http parameter to switch between xstream xml, jaxb xml . I hope it's clear the use-case scenario :-) 

Giovanni Martano

unread,
Oct 4, 2018, 4:26:03 AM10/4/18
to Drools Setup
Last but not least, XML with XPath reference is very hard to read for users and to produce dinamically for app that post/get xml data via rest api to kie-server.

Maciej Swiderski

unread,
Oct 4, 2018, 4:33:07 AM10/4/18
to drools...@googlegroups.com
Ok, now it’s more clear, thanks.

You could already do it by implementing org.kie.server.api.marshalling.xstream.XStreamMarshallerExtension and package this in a jar with services file (follow Java SE ServiceLoader approach). Once you have the jar file place it to the same class path as kie-server-api module is - make sure you have this jar on both client and server side.

Maciej

Giovanni Martano

unread,
Oct 4, 2018, 4:43:36 AM10/4/18
to Drools Setup
Thanks Maciej for your prompt reply, but I'm using Optaplanner 7.11FINAL (kie-wb + kie-server), not drools/optaplanner jars with custom java project, so how I can implement this extension? When i create asset via kie-wb GUI? What type of asset?

Thanks again

Maciej Swiderski

unread,
Oct 4, 2018, 4:54:19 AM10/4/18
to drools...@googlegroups.com
So you need to do the following:

- create maven project
- add dependency to org.kie.server:kie-server-api 
- create class that implements org.kie.server.api.marshalling.xstream.XStreamMarshallerExtension
- implement required methods
- in the extend method add this
XStream xstream = marshaller.getXstream();
xstream.setMode(mode);

- create file src/main/resources/META-INF/services/org.kie.server.api.marshalling.xstream.XStreamMarshallerExtension
- paste into that file fully qualified class name of the class you just created
- mvn clean package
- copy that file into kie-server.war/WEB-INF/lib
- copy that file (or add it as maven dependency) to your custom java project that uses kie server client
- not sure you use any UI to call kie server api from workbench but if you do copy that file to workbench/WEB-INF/lib too

Hope this helps
Maciej

Giovanni Martano

unread,
Oct 4, 2018, 5:36:22 AM10/4/18
to Drools Setup
Thanks for details Maciej, but I'm not using any kie client, I'm using a generic rest client (SOAP-UI) because I only need to access via different client (python, android, php)  to kie-server rest endpoints. 
It will work anyway? The jar package I intend.

Maciej Swiderski

unread,
Oct 4, 2018, 5:39:18 AM10/4/18
to drools...@googlegroups.com

On 4 Oct 2018, at 11:36, Giovanni Martano <giovanni...@gmail.com> wrote:

Thanks for details Maciej, but I'm not using any kie client, I'm using a generic rest client (SOAP-UI) because I only need to access via different client (python, android, php)  to kie-server rest endpoints. 
It will work anyway? The jar package I intend.
Yes, then you simply need to put this on kie-server.war/WEB-INF/lib

Maciej

Giovanni Martano

unread,
Oct 4, 2018, 5:40:33 AM10/4/18
to Drools Setup
I created the maven jar, but under wildfly 11 directory I cannot access any subdir under kie-server.war.

My directory wildfly-11/standalone/deployments/ only contain kie-server.war and kie-server.war.deployed no one sub dir where I can copy the jar :-(

Maciej Swiderski

unread,
Oct 4, 2018, 5:42:21 AM10/4/18
to drools...@googlegroups.com
Unzip the kie-server.war file and name the unzipped directory exactly the same kie-server.war (you would have to move the file before that)

Maciej

Giovanni Martano

unread,
Oct 4, 2018, 6:12:10 AM10/4/18
to Drools Setup
Well one step is ok, I can submit xml with reference id's withou errors, but when I try to get the solution via rest (calling the endpoint .../bestsolution)
I have this error in the raw response "Unexpected error during processing: Can't marshall input object: SolverInstance{containerId='TRostering_2.0.0', solverId='solver-1', solverConfigFile='com/linkit/trostering/TRosteringSolverConfig.solver.xml', status=SOLVING, scoreWrapper=ScoreWrapper{scoreClass='class org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore', scoreString='-4hard/-25soft'}}"

Maciej Swiderski

unread,
Oct 4, 2018, 6:13:46 AM10/4/18
to drools...@googlegroups.com
That I will leave to OptaPlanner experts … outside of my expertise area…

Maciej

Giovanni Martano

unread,
Oct 4, 2018, 6:15:41 AM10/4/18
to Drools Setup
Ok it function If I put in the header X-KIE-ContentType:xstream when I get the xml, but hot to have json? 

Giovanni Martano

unread,
Oct 4, 2018, 6:24:36 AM10/4/18
to Drools Setup
The solution xml response is wrong, it contain nested xml solution with  facts and solution mixed (?)...nothing done..i must use reference XPath 

Michael Anstis

unread,
Oct 4, 2018, 6:24:47 AM10/4/18
to drools...@googlegroups.com
Forwarded to the Optaplanner lead.. there may be a better mailing list to use from now on... 

Giovanni Martano

unread,
Oct 4, 2018, 6:25:44 AM10/4/18
to Drools Setup
Thanks for your support Maciej, I rollback my work and avoid tu use id's for the moment
Maciej

Maciej

To view this discussion on the web visit https://groups.google.com/d/msgid/drools-setup/ae384da2-4916-4055-9d1e-1f66d9481b2f%40googlegroups.com<span style="font-family:Helvetica;font-size:1

Geoffrey De Smet

unread,
Oct 4, 2018, 7:11:35 AM10/4/18
to drools...@googlegroups.com

Thanks for forwarding, Michael.

This kie-server feature isn't optaplanner specific though,
although optaplanner use cases might run into it more easily.

In any case, currently kie-server only supports XPath references in XStream as there no way to make kie-server's marshaller call:
  xStream.setMode(XStream.ID_REFERENCES);
through a HTTP parameter.


FWIW, Looks like a duplicate of this optaplanner question:
  https://stackoverflow.com/questions/52623500/optaplanner-7-11-id-reference-error-posting-xml-for-solution-to-kie-server
And specifically this RFE jira:
  https://issues.jboss.org/browse/DROOLS-3075

With kind regards,
Geoffrey De Smet

Reply all
Reply to author
Forward
0 new messages