<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=aloew" rel="nofollow">Andreas Loew</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-5026?redirect=false" rel="nofollow">SPR-5026</a></strong> and commented</p>
<p dir="auto">Summary:</p>
<p dir="auto">When creating the underlying physical JMS connection, SingleConnectionFactory should call the appropriate createXXXConnection method properly reflecting the type of the target XXXConnectionFactory:</p>
<ul dir="auto">
<li>for a target QueueConnectionFactory, call createQueueConnection()</li>
<li>for a target TopicConnectionFactory, call createTopicConnection()</li>
<li>for a target ConnectionFactory, call createTopicConnection()</li>
</ul>
<p dir="auto">Details:</p>
<p dir="auto">The exception I get looks like the following:</p>
<p dir="auto">22.07.2008 12:14:52 org.springframework.jms.connection.SingleConnectionFactory initConnection<br>
INFO: Established shared JMS Connection: com.spirit.wave.jms.WaveConnection@e79839<br>
Exception in thread "main" javax.jms.IllegalStateException: This SingleConnectionFactory does not hold a QueueConnection but rather: com.spirit.wave.jms.WaveConnection@e79839<br>
at org.springframework.jms.connection.SingleConnectionFactory.createQueueConnection(SingleConnectionFactory.java:229)<br>
at testcase.MessageRequestor.main(MessageRequestor.java:47)</p>
<p dir="auto">But my targetConnectionFactory indeed is a JMS 1.1-compliant com.spirit.wave.jms.WaveQueueConnectionFactory.</p>
<p dir="auto">The real root cause for seeing this issue is that, with "my" JMS provider, calling qcf.createConnection() on a WaveQueueConnectionFactory instance qcf only creates a WaveConnection (which only implements connection, but not QueueConnection), but calling qcf.createQueueConnection() creates a WaveQueueConnection (which implements both).</p>
<p dir="auto">I would propose to fix this with the following if ... then ... else in SingleConnectionFactory#doCreateConnection() that ensures that the appropriate create method is being called:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="protected Connection doCreateConnection() throws JMSException {
            ConnectionFactory connfac = getTargetConnectionFactory();
            Connection conn = null;
            if (connfac instanceof QueueConnectionFactory) {
                conn = ((QueueConnectionFactory) connfac).createQueueConnection();
            } else if (connfac instanceof TopicConnectionFactory) {
                conn = ((TopicConnectionFactory) connfac).createTopicConnection();
            } else {
                conn = connfac.createConnection();
            }
	return conn;
}"><pre class="notranslate"><code class="notranslate">protected Connection doCreateConnection() throws JMSException {
            ConnectionFactory connfac = getTargetConnectionFactory();
            Connection conn = null;
            if (connfac instanceof QueueConnectionFactory) {
                conn = ((QueueConnectionFactory) connfac).createQueueConnection();
            } else if (connfac instanceof TopicConnectionFactory) {
                conn = ((TopicConnectionFactory) connfac).createTopicConnection();
            } else {
                conn = connfac.createConnection();
            }
	return conn;
}
</code></pre></div>
<p dir="auto">I do perfectly know that a SingleConnectionFactory102 exists which properly handles this, but (a) my provider is JMS 1.1 compliant and (b) I would rather like to use CachedConnectionFactory (not directly SingleConnectionFactory).</p>
<p dir="auto">I admit that, if you prefer, this issue could also be resolved by adding a CachedConnectionFactory102 that extends SingleConnectionFactory102.</p>
<p dir="auto">Many thanks for considering this fix for the Spring 2.5.x series! :-)</p>
<p dir="auto">Best regards,</p>
<p dir="auto">Andreas</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.5.3, 2.5.4, 2.5.5</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=lisak" rel="nofollow">Josef Vychtrle</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8600?redirect=false" rel="nofollow">SPR-8600</a></strong> and commented</p>
<p dir="auto">There are two major means of data binding initialization, but there is a drawback in the oldschool xml one.</p>
<p dir="auto">In short, you can do this :</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@InitBinder(&quot;order&quot;)public void initBinder(WebDataBinder binder) {
    binder.setAllowedFields(allowedFields.split(&quot;,&quot;));
}"><pre class="notranslate"><span class="pl-c1">@</span><span class="pl-c1">InitBinder</span>(<span class="pl-s">"order"</span>)<span class="pl-k">public</span> <span class="pl-smi">void</span> <span class="pl-s1">initBinder</span>(<span class="pl-smi">WebDataBinder</span> <span class="pl-s1">binder</span>) {
    <span class="pl-s1">binder</span>.<span class="pl-en">setAllowedFields</span>(<span class="pl-s1">allowedFields</span>.<span class="pl-en">split</span>(<span class="pl-s">","</span>));
}</pre></div>
<p dir="auto">but it can't be done with ConfigurableWebBindingInitializer. First off, the binder instance is created in AnnotationMethodHandlerAdapter and initializer is passed the binder instance somewhere in HandlerMethodInvoker so it can't be set up... :</p>
<div class="highlight highlight-text-xml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;bean id=&quot;webBindingInitializer&quot; class=&quot;org.springframework.web.bind.support.ConfigurableWebBindingInitializer&quot;&gt;
    &lt;property name=&quot;messageCodesResolver&quot; ref=&quot;codesResolver&quot; /&gt;
    &lt;!-- missing allowed / disallowed / required  properties --&gt;
&lt;/bean&gt;"><pre class="notranslate">&lt;<span class="pl-ent">bean</span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>webBindingInitializer<span class="pl-pds">"</span></span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>org.springframework.web.bind.support.ConfigurableWebBindingInitializer<span class="pl-pds">"</span></span>&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>messageCodesResolver<span class="pl-pds">"</span></span> <span class="pl-e">ref</span>=<span class="pl-s"><span class="pl-pds">"</span>codesResolver<span class="pl-pds">"</span></span> /&gt;
    <span class="pl-c"><span class="pl-c">&lt;!--</span> missing allowed / disallowed / required  properties <span class="pl-c">--&gt;</span></span>
&lt;/<span class="pl-ent">bean</span>&gt;</pre></div>
<p dir="auto">FIX :<strong>ConfigurableWebBindingInitializer.java</strong></p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="public void initBinder(WebDataBinder binder, WebRequest request) {if(this.allowedFields != null) {
                        binder.setAllowedFields(allowedFields);
                }
                if(this.disallowedFields != null) {
                        binder.setDisallowedFields(disallowedFields);
                }
             if(this.allowedFields != null) {
                        binder.setRequiredFields(requiredFields);
                }
                if (this.directFieldAccess) {
			binder.initDirectFieldAccess();
		}if (this.messageCodesResolver != null) {
			binder.setMessageCodesResolver(this.messageCodesResolver);
		}if (this.bindingErrorProcessor != null) {
			binder.setBindingErrorProcessor(this.bindingErrorProcessor);
		}if (this.validator != null &amp;&amp; binder.getTarget() != null &amp;&amp;this.validator.supports(binder.getTarget().getClass())) {
			binder.setValidator(this.validator);
		}if (this.conversionService != null) {
			binder.setConversionService(this.conversionService);
		}if (this.propertyEditorRegistrars != null) {for (PropertyEditorRegistrar propertyEditorRegistrar : this.propertyEditorRegistrars) {
				propertyEditorRegistrar.registerCustomEditors(binder);
			}
		}
	}"><pre class="notranslate"><span class="pl-k">public</span> <span class="pl-smi">void</span> <span class="pl-s1">initBinder</span>(<span class="pl-smi">WebDataBinder</span> <span class="pl-s1">binder</span>, <span class="pl-smi">WebRequest</span> <span class="pl-s1">request</span>) {<span class="pl-k">if</span>(<span class="pl-smi">this</span>.<span class="pl-s1">allowedFields</span> != <span class="pl-c1">null</span>) {
                        <span class="pl-s1">binder</span>.<span class="pl-en">setAllowedFields</span>(<span class="pl-s1">allowedFields</span>);
                }
                <span class="pl-k">if</span>(<span class="pl-smi">this</span>.<span class="pl-s1">disallowedFields</span> != <span class="pl-c1">null</span>) {
                        <span class="pl-s1">binder</span>.<span class="pl-en">setDisallowedFields</span>(<span class="pl-s1">disallowedFields</span>);
                }
             <span class="pl-k">if</span>(<span class="pl-smi">this</span>.<span class="pl-s1">allowedFields</span> != <span class="pl-c1">null</span>) {
                        <span class="pl-s1">binder</span>.<span class="pl-en">setRequiredFields</span>(<span class="pl-s1">requiredFields</span>);
                }
                <span class="pl-k">if</span> (<span class="pl-smi">this</span>.<span class="pl-s1">directFieldAccess</span>) {
			<span class="pl-s1">binder</span>.<span class="pl-en">initDirectFieldAccess</span>();
		}<span class="pl-k">if</span> (<span class="pl-smi">this</span>.<span class="pl-s1">messageCodesResolver</span> != <span class="pl-c1">null</span>) {
			<span class="pl-s1">binder</span>.<span class="pl-en">setMessageCodesResolver</span>(<span class="pl-smi">this</span>.<span class="pl-s1">messageCodesResolver</span>);
		}<span class="pl-k">if</span> (<span class="pl-smi">this</span>.<span class="pl-s1">bindingErrorProcessor</span> != <span class="pl-c1">null</span>) {
			<span class="pl-s1">binder</span>.<span class="pl-en">setBindingErrorProcessor</span>(<span class="pl-smi">this</span>.<span class="pl-s1">bindingErrorProcessor</span>);
		}<span class="pl-k">if</span> (<span class="pl-smi">this</span>.<span class="pl-s1">validator</span> != <span class="pl-c1">null</span> &amp;&amp; <span class="pl-s1">binder</span>.<span class="pl-en">getTarget</span>() != <span class="pl-c1">null</span> &amp;&amp;<span class="pl-smi">this</span>.<span class="pl-s1">validator</span>.<span class="pl-en">supports</span>(<span class="pl-s1">binder</span>.<span class="pl-en">getTarget</span>().<span class="pl-en">getClass</span>())) {
			<span class="pl-s1">binder</span>.<span class="pl-en">setValidator</span>(<span class="pl-smi">this</span>.<span class="pl-s1">validator</span>);
		}<span class="pl-k">if</span> (<span class="pl-smi">this</span>.<span class="pl-s1">conversionService</span> != <span class="pl-c1">null</span>) {
			<span class="pl-s1">binder</span>.<span class="pl-en">setConversionService</span>(<span class="pl-smi">this</span>.<span class="pl-s1">conversionService</span>);
		}<span class="pl-k">if</span> (<span class="pl-smi">this</span>.<span class="pl-s1">propertyEditorRegistrars</span> != <span class="pl-c1">null</span>) {<span class="pl-k">for</span> (<span class="pl-smi">PropertyEditorRegistrar</span> <span class="pl-s1">propertyEditorRegistrar</span> : <span class="pl-smi">this</span>.<span class="pl-s1">propertyEditorRegistrars</span>) {
				<span class="pl-s1">propertyEditorRegistrar</span>.<span class="pl-en">registerCustomEditors</span>(<span class="pl-s1">binder</span>);
			}
		}
	}</pre></div>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1 M2</p>
<p dir="auto"><strong>Reference URL:</strong> <a href="http://stackoverflow.com/q/7014245/306488" rel="nofollow">http://stackoverflow.com/q/7014245/306488</a></p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398113988" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13245" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13245/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13245">#13245</a> ConfigurableWebBindingInitializer should have allowed / disallowed / required fields for DataBinder initialization (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>