<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=davidparks21" rel="nofollow">David Parks</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8367?redirect=false" rel="nofollow">SPR-8367</a></strong> and commented</p>
<p dir="auto">Reference JIRA: <a href="https://jira.springsource.org/browse/SPR-6180?focusedCommentId=66682#comment-66682" rel="nofollow">https://jira.springsource.org/browse/SPR-6180?focusedCommentId=66682#comment-66682</a></p>
<p dir="auto">Any use cases which require an HttpContext attribute to be set aren't covered in this implementation, and the extensions required make the whole thing so messy as to make using the Rest Template more of a burden than a benefit. Here is the particular case that I've been fussing with today to little avail, setting preemptive authentication (i.e. send basic authentication headers by default rather than performing 2 requests to authenticate):</p>
<p dir="auto"><a href="http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html#d4e1023" rel="nofollow">http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html#d4e1023</a></p>
<p dir="auto">The problem being that the RestTemplate implementation as it is has no support for setting HttpContext parameters (the template calls the Http.execute(HttpUriRequest) which uses only the non-accessible default HttpContext), there aren't any good ways to set the default context parameters on the HttpClient in 4.x Apache HTTP Components. You end up needing to extend HttpClient to provide for default HttpContext params on the HttpClient object and the whole thing just becomes a spaghetti mess from there making the template more pain than pleasure.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1 M2</p>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/f9144ea1eae5b09b3f8609dec0e6343f35c887a9/hovercard" href="https://github.com/spring-projects/spring-framework/commit/f9144ea1eae5b09b3f8609dec0e6343f35c887a9"><tt>f9144ea</tt></a></p>
<p dir="auto">3 votes, 7 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=gobreak" rel="nofollow">gobreak</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2091?redirect=false" rel="nofollow">SPR-2091</a></strong> and commented</p>
<p dir="auto">I have tried using JBossMQ and ActiveMQ to receive async message by DefaultMessageListenerContainer.<br>
Transaction Manager from JBoss are used and set properly as a bean property for DefaultMessageListenerContainer.<br>
To trigger the XA rollback, I throw a runtime exception in the onMessage() callback of the MessageListener.<br>
However, the message is still commit.</p>
<p dir="auto">The bean setting:<br>
&lt;bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"&gt;<br>
&lt;property name="userTransaction" ref="userTransaction"/&gt;<br>
&lt;/bean&gt;</p>
<p dir="auto">&lt;bean id="userTransaction"<br>
class="org.springframework.jndi.JndiObjectFactoryBean"&gt;<br>
&lt;property name="jndiName"&gt;<br>
&lt;value&gt;java:comp/UserTransaction&lt;/value&gt;<br>
&lt;/property&gt;<br>
&lt;/bean&gt;</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;bean id=&quot;listenerContainer&quot;
        class=&quot;org.springframework.jms.listener.DefaultMessageListenerContainer&quot;&gt;
        &lt;property name=&quot;connectionFactory&quot; ref=&quot;XAJmsConnectionFactory&quot; /&gt;
        &lt;property name=&quot;destination&quot; ref=&quot;XADestination&quot; /&gt;
        &lt;property name=&quot;messageListener&quot; ref=&quot;coreInboundBeanImpl&quot; /&gt;
        &lt;property name=&quot;transactionManager&quot; ref=&quot;transactionManager&quot;/&gt;
&lt;/bean&gt;"><pre class="notranslate"><code class="notranslate">&lt;bean id="listenerContainer"
        class="org.springframework.jms.listener.DefaultMessageListenerContainer"&gt;
        &lt;property name="connectionFactory" ref="XAJmsConnectionFactory" /&gt;
        &lt;property name="destination" ref="XADestination" /&gt;
        &lt;property name="messageListener" ref="coreInboundBeanImpl" /&gt;
        &lt;property name="transactionManager" ref="transactionManager"/&gt;
&lt;/bean&gt;
</code></pre></div>
<p dir="auto">Finally, I needed to extend DefaultMessageListenerContainer and override the receive() method using JMSTemplate instead of the message consumer as follow:<br>
public Message receive(long timeOut) throws JMSException{<br>
template.setConnectionFactory(getConnectionFactory());<br>
template.setDefaultDestination(getDestination());<br>
template.setReceiveTimeout(timeOut);<br>
if (getMessageSelector() == null || "".equals(getMessageSelector().trim()))<br>
return template.receive(getDestination());<br>
else<br>
return template.receiveSelected(getDestination(), getMessageSelector());<br>
}</p>
<p dir="auto">I use JMSTemplate because I find it performs XA without any noticed problem.<br>
Using the above implementation can successfully rollback as well as commit the message. I am seeking for better solution on this topic.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0 M4</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="398067460" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/6872" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/6872/hovercard" href="https://github.com/spring-projects/spring-framework/issues/6872">#6872</a> Cannot do XA Rollback Using DefaultMessageListenerContainer in Spring 2.0 RC1 (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398067461" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/6873" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/6873/hovercard" href="https://github.com/spring-projects/spring-framework/issues/6873">#6873</a> Cannot do XA Rollback Using DefaultMessageListenerContainer in Spring 2.0 RC1 (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>