Bug 771203

Summary: Camel integration using jaxb, CCE occurs when trying to retrive FactHandle from unmarshalled ExecutionResult
Product: [JBoss] JBoss Enterprise BRMS Platform 5 Reporter: Radovan Synek <rsynek>
Component: BRE (Expert, Fusion)Assignee: Mario Fusco <mfusco>
Status: ASSIGNED --- QA Contact: Radovan Synek <rsynek>
Severity: medium Docs Contact:
Priority: unspecified    
Version: BRMS 5.3.0.GACC: atangrin, lpetrovi, mproctor, rzhang
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Attachments:
Description Flags
camel jaxb insert CCE reproducer none

Description Radovan Synek 2012-01-02 12:57:06 UTC
Created attachment 550253 [details]
camel jaxb insert CCE reproducer

I have this camel-drools configuration:

camelContext.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {          
                JaxbDataFormat jdf = new JaxbDataFormat();
                jdf.setContextPath("com.redhat.jaxbinsert.domain");
                jdf.setPrettyPrint(true);

                from("direct:test-session").policy(new DroolsPolicy()).unmarshal(jdf).to("drools://testnode/ksession").marshal(jdf);
                from("direct:unmarshall").policy(new DroolsPolicy()).unmarshal(jdf);
                from("direct:marshall").policy(new DroolsPolicy()).marshal(jdf);
            }
        });

I am trying to insert single fact into session this way:
//command creation, marshalling into XML and sending to drools
Person p = new Person("Alice", "spicy meals", 30);
        p.setId(1);
        List<Command> commands = new ArrayList<Command>();
        commands.add(CommandFactory.newInsert(p, "tempPerson"));
        BatchExecutionCommand command = CommandFactory.newBatchExecution(commands);
        String xmlCommand = template.requestBody("direct:marshall", command, String.class);

        String xml = template.requestBody("direct:test-session", xmlCommand, String.class);
        ExecutionResults res = (ExecutionResults) template.requestBody("direct:unmarshall", xml);
        FactHandle handle = (FactHandle)res.getFactHandle("tempPerson");

ClassCastException is thrown on the last line of code - when retrieving FactHandle from unmarshalled ExecutionResult:

Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to org.drools.runtime.rule.FactHandle
	at com.redhat.jaxbinsert.JaxbCamel.testInsert(JaxbCamel.java:105)
	at com.redhat.jaxbinsert.App.main(App.java:12)
-------------------------------------------------------------------------------
Instead of FactHandle instance, only it's String reprezentation is returned.

See an attachment for the details, build it and run it as maven project.

Comment 2 Mark Proctor 2012-01-19 01:04:27 UTC
Camel isn't being productised yet. So check with prakash/johng before
progressing further on this one. If the bug seems genuine, please re-open a
jira for .org and we'll make sure it's fixed there.

Comment 3 Lukáš Petrovický 2012-01-19 07:38:45 UTC
ERD states that the Camel integration is being productized. (https://docspace.corp.redhat.com/docs/DOC-76523)

Comment 5 Geoffrey De Smet 2012-02-08 13:56:07 UTC
The attached testcode makes use of drools-grid.
Drools Grid is not supported and likely broken (from what I 've heard).
It should not be in BRMS 5.3.0.BRMS.ER1 and I don't think it's in the latest productized builds any more.

Offending code:

        GridImpl grid = new GridImpl();
        grid.addService(WhitePages.class, new WhitePagesImpl());
        GridNode node = grid.createGridNode("testnode");
	Context context = new JndiContext();

Comment 6 Geoffrey De Smet 2012-02-08 15:19:03 UTC
I've rewritten the reproducing most of the code as a test in CamelEndpointTest and cherry-picked it to 5.3.x:
  https://github.com/droolsjbpm/droolsjbpm-integration/commit/449596510458de442cacea0542b0ec965658bb0b

It makes use of CommandFactory.newBatchExecution and response.getFactHandle, yet doesn't throw a CCE.

Please check if you can reproduce the CCE without using drools-grid.
Optional: Even better would be if you could send in a github pull request that adds a unit test to droolsjbpm-integration that fails with the CCE.
  https://github.com/droolsjbpm/droolsjbpm-integration

Comment 7 Radovan Synek 2012-02-09 13:38:33 UTC
Here is a pull request with reproducers for these 3 connected issues:
https://github.com/droolsjbpm/droolsjbpm-integration/pull/12

Comment 8 Geoffrey De Smet 2012-04-20 16:10:46 UTC
The other 2 issues are fixed (weeks ago), but this one is still open.
It's this currently @Ignored test:
  org.drools.camel.component.JaxbInsertTest#testInsert()
in
  /home/gdesmet/projects/jboss/droolsjbpm/droolsjbpm-integration/drools-camel/src/test/java/org/drools/camel/component/JaxbInsertTest.java

The main problem is that ExecutionResultImpl.facts is of type HashMap<String, Object> but should probably be of type Map<String, FactHandle>.

Comment 9 Geoffrey De Smet 2012-04-22 13:43:13 UTC
The bug is in JaxbMapAdapter, which changes a FactHandle into a String during marshalling, but doesn't do the same during unmarshalling.

The problem is that the reverse operation is not possible, because not every String in a JAXB map is a FactHandle...

Comment 10 Geoffrey De Smet 2012-04-22 13:57:37 UTC
Fixed. Applied on 5.3, 5.4 and master.

It turns out that the normal FactHandle implementations are JAXB ready, so JaxbMapAdapter should not do any dirty hacks like converting it to a String externalForm.

Comment 11 Ryan Zhang 2012-04-23 07:35:56 UTC
Update status to ON_QA. Please verify them against ER6.

Comment 12 Ryan Zhang 2012-04-23 07:56:25 UTC
Confirmed that not picked in ER6. Change status back.

Comment 14 Ryan Zhang 2012-05-11 11:45:18 UTC
This fix has actually been committed to project branch which BRMS 5.3 used.
The commit had been done before the blocker cut off date.
So this requires to request block+ flag.

Comment 16 Radovan Synek 2012-05-15 12:29:04 UTC
CCE is fixed, but another problem occurs. FactHandle is returned as expected:

ExecutionResults res = (ExecutionResults) template.requestBody("direct:unmarshall", xml);
FactHandle fh = (FactHandle) res.getFactHandle("tempPerson");

But the returned fact handle has external form [fact 0:0:0:0:0:null:null] - and of course null object is returned from knowledge session by calling session.getObject(fh);

Other command formats (json, xstream, pojo) return right fact handle which points to the inserted object in the knowledge session.

Please take a look at the org.drools.camel.component.JaxbInsertTest#testInsert() and inspect the returned fact handle.

Comment 17 Geoffrey De Smet 2012-05-16 11:12:44 UTC
For the record, here's the first change commit:
  https://github.com/droolsjbpm/drools/commit/8e6551a3decf62f96cbe24049a5633d5f22950be

This issue has no blocker+ tag, so I cannot fix it on 5.3.x (so not prioritizing it at the moment). I 'll fix it for master 5.5 and 5.4.x after my PTO.

Comment 18 Geoffrey De Smet 2013-03-05 13:39:19 UTC
Reassign to the guvnor team, now that I am working full time on planner. So these issues aren't forgotten.