[forge-users] Problem with unmarshalling resource with jaxb unmarshaller

Max Schwaab max.schwaab at akquinet.de
Fri Mar 2 11:22:22 EST 2012


Hey there,

I've got another tricky problem with my hibersap plugin

I'm using the HibersapJaxbXmlParser to parse a hibersap.xml file.
What the parser does is the following:

* creating a JAXB context [ jaxbContext = JAXBContext.newInstance( 
HibersapConfig.class ); ]
* creating a JAXB unmarshaller [ unmarshaller = 
jaxbContext.createUnmarshaller(); ]
* unmarshall the given resource stream [ unmarshalledObject = 
unmarshaller.unmarshal( resourceStream ); ]

The problem is:
It unmarshalles the file to the correct class, but some content gets lost.

The funny thing:
If I try this in a seperate test without forge, it works!
The test is part of the plugin and can be found at the github repo 
(https://github.com/forge/plugin-hibersap)

What I want it to do:
Unmarshall a hibersap.xml file and recognize the hibersap config AND the 
session manager in the config.
Within Forge it seems to recognize only the hibersap config and not the 
session manager.

The hibersap.xml is something like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<hibersap xmlns="http://hibersap.org/xml/ns/hibersap-config">
<session-manager name="SM001">
<context>org.hibersap.execution.jco.JCAContext</context>
         .
         .
         .
</session-manager>
</hibersap>

Here is the code from the HibersapJaxbXmlParser:

public HibersapConfig parseResource( final InputStream resourceStream, 
final String resourceName )
             throws HibersapParseException
     {
         Unmarshaller unmarshaller;
         try
         {
             unmarshaller = jaxbContext.createUnmarshaller();
         }
         catch ( final JAXBException e )
         {
             throw new InternalHiberSapException( "Cannot create an 
unmarshaller. ", e );
         }

         Object unmarshalledObject;
         try
         {
             unmarshalledObject = unmarshaller.unmarshal( resourceStream );
         }
         catch ( final JAXBException e )
         {
             throw new HibersapParseException( "Cannot parse the 
resource " + resourceName, e );
         }
         if ( unmarshalledObject == null )
         {
             throw new HibersapParseException( "Resource " + 
resourceName + " is empty." );
         }
         if ( !( unmarshalledObject instanceof HibersapConfig ) )
         {
             throw new HibersapParseException( "Resource " + resourceName
                     + " does not consist of a hibersap specification. I 
found a "
                     + unmarshalledObject.getClass().getSimpleName() );
         }
         return ( HibersapConfig ) unmarshalledObject;
     }


Thank you for your help and best regards

Max



More information about the forge-users mailing list