You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "Mark Proctor (JIRA)" <ji...@apache.org> on 2010/07/08 05:20:52 UTC

[jira] Updated: (CAMEL-2921) DataFormat's should allow url query like parameters

     [ https://issues.apache.org/activemq/browse/CAMEL-2921?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mark Proctor updated CAMEL-2921:
--------------------------------

    Description: 
It would be nice if we could customise DataFormatDefinitions inline:
marshal( "jaxb?contextPath=org.domain.package" )

Here is an outline of some code I think that would achieve this, however to be safe (imho) the resolver should only ever returned "cloned" copies of any registered DataFormatDefinition; to save the originally source from being altered.

DataFormatDefinition
{code}
    public static DataFormat getDataFormat(RouteContext routeContext, DataFormatDefinition type, String ref) {
        if (type == null) {
            ObjectHelper.notNull(ref, "ref or type");
            
            // try to let resolver see if it can resolve it, its not always possible
            int pos = ref.indexOf( '?' );
            if ( pos < 0 ) {                                
                type = routeContext.getCamelContext().resolveDataFormatDefinition( ref );
            } else {
                type = routeContext.getCamelContext().resolveDataFormatDefinition( ref.substring(0, pos -1 ) );
            }        

            if (type != null &&  pos >= 0 ) {
                try {
                    Map<String, Object> parameters = URISupport.parseQuery( ref.substring( pos ) ); 
                    try {
                        IntrospectionSupport.setProperties(routeContext.getCamelContext().getTypeConverter(), type, parameters);
                    } catch (Exception e) {
                        throw new RuntimeException( "Unable to set DataFormatDefinition properties '" + ref + "'", e);
                    }
                } catch (URISyntaxException e) {
                    throw new RuntimeException( "Unable to parse parameters " + ref, e);
                }
                
                return type.getDataFormat(routeContext);
            }

            DataFormat dataFormat = routeContext.getCamelContext().resolveDataFormat(ref);
            if (dataFormat == null) {
                throw new IllegalArgumentException("Cannot find data format in registry with ref: " + ref);
            }

            return dataFormat;
        } else {
            return type.getDataFormat(routeContext);
        }
    }
{code}

  was:
It would be nice if we could customise DataFormatDefinitions inline:
marshal( "jaxb?contextPath=org.domain.package" )

Here is an outline of some code I think that would achieve this, however to be safe (imho) the resolver should only ever returned "cloned" copies of any registered DataFormatDefinition; to save the originally source from being altered.

DataFormatDefinition
{code}
    public static DataFormat getDataFormat(RouteContext routeContext, DataFormatDefinition type, String ref) {
        if (type == null) {
            ObjectHelper.notNull(ref, "ref or type");
            
            // try to let resolver see if it can resolve it, its not always possible
            int pos = ref.indexOf( '?' );
            if ( pos < 0 ) {                                
                type = routeContext.getCamelContext().resolveDataFormatDefinition( ref );
            } else {
                type = routeContext.getCamelContext().resolveDataFormatDefinition( ref.substring(0, pos -1 ) );
            }        

            if (type != null &&  pos >= 0 ) {
                try {
                    Map<String, Object> parameters = URISupport.parseQuery( ref.substring( pos ) ); // 1 to skip the leading ?
                    try {
                        IntrospectionSupport.setProperties(routeContext.getCamelContext().getTypeConverter(), type, parameters);
                    } catch (Exception e) {
                        throw new RuntimeException( "Unable to set DataFormatDefinition properties '" + ref + "'", e);
                    }
                } catch (URISyntaxException e) {
                    throw new RuntimeException( "Unable to parse parameters " + ref, e);
                }
                
                return type.getDataFormat(routeContext);
            }

            DataFormat dataFormat = routeContext.getCamelContext().resolveDataFormat(ref);
            if (dataFormat == null) {
                throw new IllegalArgumentException("Cannot find data format in registry with ref: " + ref);
            }

            return dataFormat;
        } else {
            return type.getDataFormat(routeContext);
        }
    }
{code}


> DataFormat's should allow url query like parameters
> ---------------------------------------------------
>
>                 Key: CAMEL-2921
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2921
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>
> It would be nice if we could customise DataFormatDefinitions inline:
> marshal( "jaxb?contextPath=org.domain.package" )
> Here is an outline of some code I think that would achieve this, however to be safe (imho) the resolver should only ever returned "cloned" copies of any registered DataFormatDefinition; to save the originally source from being altered.
> DataFormatDefinition
> {code}
>     public static DataFormat getDataFormat(RouteContext routeContext, DataFormatDefinition type, String ref) {
>         if (type == null) {
>             ObjectHelper.notNull(ref, "ref or type");
>             
>             // try to let resolver see if it can resolve it, its not always possible
>             int pos = ref.indexOf( '?' );
>             if ( pos < 0 ) {                                
>                 type = routeContext.getCamelContext().resolveDataFormatDefinition( ref );
>             } else {
>                 type = routeContext.getCamelContext().resolveDataFormatDefinition( ref.substring(0, pos -1 ) );
>             }        
>             if (type != null &&  pos >= 0 ) {
>                 try {
>                     Map<String, Object> parameters = URISupport.parseQuery( ref.substring( pos ) ); 
>                     try {
>                         IntrospectionSupport.setProperties(routeContext.getCamelContext().getTypeConverter(), type, parameters);
>                     } catch (Exception e) {
>                         throw new RuntimeException( "Unable to set DataFormatDefinition properties '" + ref + "'", e);
>                     }
>                 } catch (URISyntaxException e) {
>                     throw new RuntimeException( "Unable to parse parameters " + ref, e);
>                 }
>                 
>                 return type.getDataFormat(routeContext);
>             }
>             DataFormat dataFormat = routeContext.getCamelContext().resolveDataFormat(ref);
>             if (dataFormat == null) {
>                 throw new IllegalArgumentException("Cannot find data format in registry with ref: " + ref);
>             }
>             return dataFormat;
>         } else {
>             return type.getDataFormat(routeContext);
>         }
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.