[rules-users] Reading a Guvnor PKG from drools API
Hey, I was trying to read a package(ResourceType.PKG), which i downloaded from Guvnor, using KnowledgeBuilder, but I consistently get the following error while trying to access the file. Here's my code and the error, **Code** KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ResourceFactory.newClassPathResource( "Goal Creation Charges.pkg", getClass() ), ResourceType.PKG ); if ( kbuilder.hasErrors() ) { System.err.println( kbuilder.getErrors().toString() ); } kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() ); **Error** java.lang.RuntimeException: java.io.StreamCorruptedException: invalid stream header: 7061636B at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:724) at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51) at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40) at com.infosys.fps.drools.adapter.DroolsAdapter.readKnowledgeBase(DroolsAdapter.java:80) at com.infosys.fps.drools.adapter.DroolsAdapter.main(DroolsAdapter.java:20) Caused by: java.io.StreamCorruptedException: invalid stream header: 7061636B at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783) at java.io.ObjectInputStream.(ObjectInputStream.java:280) at org.drools.common.DroolsObjectInputStream.(DroolsObjectInputStream.java:68) at org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:205) at org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:189) at org.drools.compiler.PackageBuilder.addPackageFromInputStream(PackageBuilder.java:819) at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:711) ... 4 more I have tried using both binary and source from guvnor, but neither of them works. I get the same error. Is there something m doing wrong ? Thanks, Abhinay -- View this message in context: http://drools.46999.n3.nabble.com/Reading-a-Guvnor-PKG-from-drools-API-tp4023921.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Reading a Guvnor PKG from drools API
It looks legit to me code-wise (I have some almost identical code, which works just fine). Are you using the same version of Drools in your project as the Guvnor you downloaded the package from? Steve On 22 May 2013, at 10:19, abhinay_agarwal wrote: > Hey, > > I was trying to read a package(ResourceType.PKG), which i downloaded from > Guvnor, using KnowledgeBuilder, but I consistently get the following error > while trying to access the file. > > Here's my code and the error, > > **Code** > > KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); > kbuilder.add( ResourceFactory.newClassPathResource( > "Goal Creation > Charges.pkg", getClass() ), ResourceType.PKG ); > if ( kbuilder.hasErrors() ) { > System.err.println( kbuilder.getErrors().toString() ); > } > kbase = KnowledgeBaseFactory.newKnowledgeBase(); > kbase.addKnowledgePackages( > kbuilder.getKnowledgePackages() ); > > > > **Error** > > java.lang.RuntimeException: java.io.StreamCorruptedException: invalid stream > header: 7061636B > at > org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:724) > at > org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51) > at > org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40) > at > com.infosys.fps.drools.adapter.DroolsAdapter.readKnowledgeBase(DroolsAdapter.java:80) > at > com.infosys.fps.drools.adapter.DroolsAdapter.main(DroolsAdapter.java:20) > Caused by: java.io.StreamCorruptedException: invalid stream header: 7061636B > at > java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783) > at java.io.ObjectInputStream.(ObjectInputStream.java:280) > at > org.drools.common.DroolsObjectInputStream.(DroolsObjectInputStream.java:68) > at > org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:205) > at > org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:189) > at > org.drools.compiler.PackageBuilder.addPackageFromInputStream(PackageBuilder.java:819) > at > org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:711) > ... 4 more > > > I have tried using both binary and source from guvnor, but neither of them > works. I get the same error. Is there something m doing wrong ? > > Thanks, > Abhinay > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/Reading-a-Guvnor-PKG-from-drools-API-tp4023921.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Reading a Guvnor PKG from drools API
Yes, all the jars are just fine, the above code works perfectly if I just replace the ResourceType.PKG to ResoureType.DRL, but dunno why PKG doesnt works. Abhi -- View this message in context: http://drools.46999.n3.nabble.com/Reading-a-Guvnor-PKG-from-drools-API-tp4023921p4023924.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Reading a Guvnor PKG from drools API
I saw the same error when there was a mismatch in ResourceType. You mention you downloaded the package from Guvnor and that it work when you change the ResourceType to drl. Can you check if the .pkg file is actually drl? Could it be that you downloaded the drl as a .pkg file? -- View this message in context: http://drools.46999.n3.nabble.com/Reading-a-Guvnor-PKG-from-drools-API-tp4023921p4023932.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Reading a Guvnor PKG from drools API
I got the problem, if I Download the source of a package then it returns the DRL file of the package and hence the resource type is PKG. While if i download the binary form then the file contains the actual package and hence the .PKG works here. Abhi -- View this message in context: http://drools.46999.n3.nabble.com/Reading-a-Guvnor-PKG-from-drools-API-tp4023921p4023934.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users