Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Won't Fix
-
2.2.7
-
None
-
None
-
Windows 7
Description
I have a feature where the configuration is embedded in it like follows:
<feature name="custom-mimetype-resolver" version="1.0" description=Custom MimeTypes Resolver."> <bundle start-level='75'>mvn:ddf.mime/custom-mime-type-resolver/1.0</bundle> <config name="DDF_Custom_Mime_Type_Resolver-DDFCustomMimeTypes"> name = NITF Content Resolver priority = 10 customMimeTypes = nitf=image/nitf,ntf=image/nitf </config> </feature>
The bundle in this feature has a metatype XML file describing the Admin Console interface to configure it. This metatype XML includes an attribute with a cardinality="100", hence a text field will be displayed on the console with +/- buttons to add extra text fields for more values up to a max of 100.
<metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.0.0"> <OCD description="DDF Custom Mime Types" name="DDF Custom Mime Types" id="DDF_Custom_Mime_Type_Resolver"> <AD name="Resolver Name" id="name" required="false" type="String" /> <AD name="Priority" id="priority" required="true" type="Integer" /> <AD name="File Extensions to Mime Types" id="customMimeTypes" required="true" type="String" cardinality="100" description="List of key/value pairs where key is the file extension and value is the mime type, e.g., nitf=image/nitf"/> </OCD> <Designate pid="DDF_Custom_Mime_Type_Resolver" factoryPid="DDF_Custom_Mime_Type_Resolver"> <Object ocdref="DDF_Custom_Mime_Type_Resolver" /> </Designate> </metatype:MetaData>
When karaf comes up and instantiates the bundle in this feature and applies the configuration (thus creating an instance of the DDF_Custom_Mime_Type_Resolver managed service factory), the customMimeTypes are displayed in one field as nitf=image/nitf,ntf=image/nitf rather than 2 separate fields with their values delimited by the comma as I had hoped. However, the setCustomMimeTypes(String[] mimeTypes) method in the managed service instance is called with a String[] as expected.
But if I add another mime type mapping via the Admin Console, say xyz=image/xyz, when the setCustomMimeTypes(String[]) method is called it no longer trats the "," as a delimiter for the "nitf=image/nitf,ntf=image/nitf" entry and treats this as a single mime type mapping.
Here is a log trace of what happens:
For:
<config name="DDF_Custom_Mime_Type_Resolver-DDFCustomMimeTypes">
name = NITF Content Resolver
priority = 10
customMimeTypes = nitf=image/nitf,ntf=image/nitf
</config>
Get:
ENTERING: setCustomMimeTypes nitf=image/nitf Creating fileExtensions array for mime type: image/nitf Adding file extension: nitf for mime type: image/nitf ntf=image/nitf Adding file extension: ntf for mime type: image/nitf customFileExtensionsToMimeTypesMap = {nitf=image/nitf, ntf=image/nitf} customMimeTypesToFileExtensionsMap = {image/nitf=[nitf, ntf]} EXITING: setCustomMimeTypes
Add a new mime type xyz=image/xyz via Admin Console:
ENTERING: setCustomMimeTypes nitf=image/nitf,ntf=image/nitf Creating fileExtensions array for mime type: image/nitf,ntf Adding file extension: nitf for mime type: image/nitf,ntf xyz=image/xyz Creating fileExtensions array for mime type: image/xyz Adding file extension: xyz for mime type: image/xyz customFileExtensionsToMimeTypesMap = {nitf=image/nitf,ntf, xyz=image/xyz} customMimeTypesToFileExtensionsMap = {image/xyz=[xyz], image/nitf,ntf=[nitf]} EXITING: setCustomMimeTypes
If I cut/paste the ntf=image/nitf from the entry with "nitf=image/nitf,ntf=image/nitf"
into its own text field (by hitting "+" button) I get (which is correct):
ENTERING: setCustomMimeTypes nitf=image/nitf Creating fileExtensions array for mime type: image/nitf Adding file extension: nitf for mime type: image/nitf xyz=image/xyz Creating fileExtensions array for mime type: image/xyz Adding file extension: xyz for mime type: image/xyz ntf=image/nitf Adding file extension: ntf for mime type: image/nitf customFileExtensionsToMimeTypesMap = {nitf=image/nitf, ntf=image/nitf, xyz=image/xyz} customMimeTypesToFileExtensionsMap = {image/nitf=[nitf, ntf], image/xyz=[xyz]} EXITING: setCustomMimeTypes
Tried this variation on the <config> in the feature but it did not work:
<config name="DDF_Custom_Mime_Type_Resolver-DDFCustomMimeTypes">
name = NITF Content Resolver
priority = 10
customMimeTypes = nitf=image/nitf
customMimeTypes = ntf=image/nitf
</config>
And only the last customMimeTypes was added (ntf=image/nitf).
Here is the setCustomMimeTypes(String[]) method being called:
public void setCustomMimeTypes( String[] customMimeTypes ) { logger.info( "ENTERING: setCustomMimeTypes" ); this.customMimeTypes = customMimeTypes; this.customFileExtensionsToMimeTypesMap = new HashMap<String, String>(); this.customMimeTypesToFileExtensionsMap = new HashMap<String, List<String>>(); for ( String mimeTypeMapping : this.customMimeTypes ) { logger.info( mimeTypeMapping ); // mimeTypeMapping is of the form <file extension>=<mime type> // Example: nitf=image/nitf // where: customParts[0] = file extension // customParts[1] = mime type String[] customParts = mimeTypeMapping.split( "=" ); customFileExtensionsToMimeTypesMap.put( customParts[0], customParts[1] ); List<String> fileExtensions = (List<String>) customMimeTypesToFileExtensionsMap.get( customParts[1] ); if ( fileExtensions == null ) { logger.info( "Creating fileExtensions array for mime type: " + customParts[1] ); fileExtensions = new ArrayList<String>(); } logger.info( "Adding file extension: " + customParts[0] + " for mime type: " + customParts[1] ); fileExtensions.add( customParts[0] ); customMimeTypesToFileExtensionsMap.put( customParts[1], fileExtensions ); } logger.info( "customFileExtensionsToMimeTypesMap = " + customFileExtensionsToMimeTypesMap ); logger.info( "customMimeTypesToFileExtensionsMap = " + customMimeTypesToFileExtensionsMap ); logger.info( "EXITING: setCustomMimeTypes" ); }
So there seems to be a disconnect between the <config> specification and the Admin Console. I also reproduced the problem using a .cfg file dropped in the karaf /etc directory.
Attachments
Issue Links
- is a clone of
-
KARAF-1701 Parsing of config for a field with cardinality > 1 is incorrectlyprocessed and displayed on Admin Console
- Resolved