<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=david_syer" rel="nofollow">Dave Syer</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9367?redirect=false" rel="nofollow">SPR-9367</a></strong> and commented</p>
<p dir="auto">It is very difficult (impossible) to handle a 401 response in the RestTemplate with default settings (Documentation?).  In fact it is possible, but you have to supply an error handler <strong>and</strong> a request factory.  The error handler was obvious, but the problem is that the default request factory uses java.net which can throw HttpRetryException when you try to look at the status code of the response (despite it being obviously available).  The solution is to use HttpComponentsClientHttpRequestFactory.  E.g.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="template.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
template.setErrorHandler(new DefaultResponseErrorHandler() {
	public boolean hasError(ClientHttpResponse response) throws IOException {
		HttpStatus statusCode = response.getStatusCode();
		return statusCode.series() == HttpStatus.Series.SERVER_ERROR;
	}
});"><pre class="notranslate"><code class="notranslate">template.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
template.setErrorHandler(new DefaultResponseErrorHandler() {
	public boolean hasError(ClientHttpResponse response) throws IOException {
		HttpStatus statusCode = response.getStatusCode();
		return statusCode.series() == HttpStatus.Series.SERVER_ERROR;
	}
});
</code></pre></div>
<p dir="auto">With these settings then a 401 JSON response will be extracted and converted nicely if you just use <code class="notranslate">template.exchange()</code> expecting a JSON response in the 200 case.  This is not exactly clear from the user guide, and HttpComponentsClientHttpRequestFactory isn't even mentioned - the deprecated CommonsClientHttpRequestFactory is (I'm looking at <a href="http://static.springsource.org/spring/docs/current/spring-framework-reference/htmlsingle/spring-framework-reference.html" rel="nofollow">http://static.springsource.org/spring/docs/current/spring-framework-reference/htmlsingle/spring-framework-reference.html</a>).</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1.1</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="398226894" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/21321" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/21321/hovercard" href="https://github.com/spring-projects/spring-framework/issues/21321">#21321</a> RestTemplate - providing custom ResponseErrorHandler does not prevent an error with http 401 responses (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<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/24ffa5a706d1b8538ff1359c635905f0f9af9fb5/hovercard" href="https://github.com/spring-projects/spring-framework/commit/24ffa5a706d1b8538ff1359c635905f0f9af9fb5"><tt>24ffa5a</tt></a></p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=sgarlatm" rel="nofollow">Matthew Sgarlata</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-5931?redirect=false" rel="nofollow">SPR-5931</a></strong> and commented</p>
<p dir="auto">The dojo framework creates form widgets using a syntax like this</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  &lt;select	dojoType=&quot;dijit.form.FilteringSelect&quot;
id=&quot;setvaluetest2&quot;
name=&quot;state1&quot;
autoComplete=&quot;false&quot;
invalidMessage=&quot;Invalid state name&quot;
onChange=&quot;dojo.byId('oc1').value=arguments[0]&quot;"><pre class="notranslate"><code class="notranslate">  &lt;select	dojoType="dijit.form.FilteringSelect"
id="setvaluetest2"
name="state1"
autoComplete="false"
invalidMessage="Invalid state name"
onChange="dojo.byId('oc1').value=arguments[0]"
</code></pre></div>
<p dir="auto">As far as I can tell, it's impossible to do stuff like this with the Spring &lt;form&gt; tags because there is no way to specify non-standard HTML attributes.  An approach I've used for my own custom tags is to add a catch-all attribute called "attributes" so the syntax would look something like</p>
<p dir="auto">&lt;form:select id="setvaluetest2" attributes='dojoType="dijit.form.FilteringSelect" invalidMessage="Invalid state name" ... etc</p>
<hr>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/15637/SPR-5931-patch-draft.txt" rel="nofollow">SPR-5931-patch-draft.txt</a> (<em>4.54 kB</em>)</li>
</ul>
<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="398097500" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/10782" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/10782/hovercard" href="https://github.com/spring-projects/spring-framework/issues/10782">#10782</a> Upgrade the Spring JSP tag libraries to JSP 2.0 (<em><strong>"depends on"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398095919" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/10543" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/10543/hovercard" href="https://github.com/spring-projects/spring-framework/issues/10543">#10543</a> form.tld - Add support for custom attributes (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<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/982ece595c5dc0f9f0c8b6c0c37f2db8539790a8/hovercard" href="https://github.com/spring-projects/spring-framework/commit/982ece595c5dc0f9f0c8b6c0c37f2db8539790a8"><tt>982ece5</tt></a></p>
<p dir="auto">1 votes, 3 watchers</p>