Bug 827624
Summary: | ClassCastException when fetching a package from Guvnor | ||||||
---|---|---|---|---|---|---|---|
Product: | [JBoss] JBoss Enterprise BRMS Platform 5 | Reporter: | Hao Wu <hwu> | ||||
Component: | BRM (Guvnor) | Assignee: | manstis | ||||
Status: | VERIFIED --- | QA Contact: | |||||
Severity: | urgent | Docs Contact: | |||||
Priority: | unspecified | ||||||
Version: | BRMS 5.3.0.GA | CC: | manstis, mproctor | ||||
Target Milestone: | ER9 | ||||||
Target Release: | BRMS 5.3.0.GA | ||||||
Hardware: | x86_64 | ||||||
OS: | Linux | ||||||
Whiteboard: | |||||||
Fixed In Version: | Doc Type: | Bug Fix | |||||
Doc Text: | Story Points: | --- | |||||
Clone Of: | Environment: | ||||||
Last Closed: | Type: | Bug | |||||
Regression: | --- | Mount Type: | --- | ||||
Documentation: | --- | CRM: | |||||
Verified Versions: | Category: | --- | |||||
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||
Cloudforms Team: | --- | Target Upstream Version: | |||||
Embargoed: | |||||||
Attachments: |
|
Description
Hao Wu
2012-06-01 21:32:41 UTC
Created attachment 588769 [details]
The pkg file of the package snapshot
This is a customer bug and needs to be a blocker... Michael, I 've reproduced the issue in a unit test on master: https://github.com/droolsjbpm/guvnor/commit/e5a710e75fd37c5fea617d140487a023b6318699 Hao, Normally, users/customers shouldn't use internal classes like HttpClientImpl and KnowledgePackageImp. They have no backwards compatibility guarantees. Have you tried using the normal api in the knowledge-api module to fetch that KnowledgePackage? I am not sure which classes to use exactly, but Mark or Edson should know. The bug is that the o on this line is an array of Package, instead of a Package: return (Package) o; The L on this line signifies that actually: [Lorg.drools.rule.Package; cannot be cast to org.drools.rule.Package HttpClassImpl is very old and only meant for the old RuleAgent class, which was deprecated some time ago. As a result it seems fixes made to KnowledgeAgentImpl to handle alternative serialised formats where not apply to HttpClassImpl. We will be removing legacy classes very soon, so I don't think we should fix this. My first question though is why not use the KnowlegeAgent directly, rather than doing this sort of thing manually. Anyway if you wish to continue doing manual serialisation, I would recommend using the ResourceFactory and then rip the relevant helper method from KnowledgeAgentImpl. I haven't checked that this compiles, but it shows you the idea: private Collection<KnowledgePackage> createPackageFromResource(Resource resource) InputStream is = null; Collection<KnowledgePackage> kpkgs = null; try { is = resource.getInputStream(); Object object = DroolsStreamUtils.streamIn( is ); if ( object instanceof Collection ) { kpkgs = (Collection<KnowledgePackage>) object; } else if ( object instanceof KnowledgePackageImp ) { kpkgs = Collections.singletonList( (KnowledgePackage) object ); } else if( object instanceof Package ) { kpkgs = Collections.singletonList( (KnowledgePackage) new KnowledgePackageImp( (Package) object ) ); } else if( object instanceof Package[] ) { kpkgs = new ArrayList<KnowledgePackage>(); for( Package pkg : (Package[]) object ) { kpkgs.add( new KnowledgePackageImp( pkg ) ); } } else { throw new RuntimeException("Unknown binary format trying to load resource "+resource.toString()); } } catch ( Exception ex ) { this.listener.exception( new RuntimeException( "KnowledgeAgent exception while trying to deserialize KnowledgeDefinitionsPackage ", ex ) ); } finally { try { if ( is != null ) { is.close(); } } catch ( IOException e ) { this.listener.exception( new RuntimeException( "KnowledgeAgent exception while trying to close KnowledgeDefinitionsPackage ", e ) ); } } } I would add that RuleAgent at the moment is completely brocken. That this is the first time a problem has occured, is a good thing, it means no one has used it until now. And it is considered deprecated. We can fix RuleAgent and related classes. But it involves changing method signatures and lots of instanceofs. Should we do this for a deprecated class, if this is the first customer who has a problem, and they now have a work around anyway? Here's the code to build the Resource parameter in Mark's post from an URL: Resource res = ResourceFactory.newUrlResource(url); KnowledgeAgentConfiguration conf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration(); Authenticator.setDefault(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("admin", "admin".toCharArray()); } }); Recommendation is to move to use of KnowledgeAgent or use code based on KnowledgeAgentImpl (comment #5). No further action required by engineering. This issue's fixes have been picked by ER9. Please verify them on ER9. Workaround is verified for ER9. The code of workaround: - the body of testDownloadPkg is comment #7 - testDownloadPkg calls createPackageFromResource (comment #5) |