title: RestTemplate.exchange() - Illegal character(s) in message header value
body: <p>I'm getting an <code>java.lang.IllegalArgumentException: Illegal character(s) in message header value</code> error when executing the <code>restTemplate.exchange()</code> method.</p>
  <p>I guess the problem is a huge HTTP header, which internally will be base64 encoded:</p>
  <blockquote>
  <p>It seems the SDK is using the old &quot;sun.misc.BASE64Encoder&quot; which will breaking a new line &quot;\n&quot; if the encoded string is too long (&gt;76 characters).</p>
  </blockquote>
  <p><a href="https://github.com/kintone/java-sdk/issues/10#issuecomment-321488606" rel="nofollow noreferrer">Source</a></p>
  <p>My code snippet which produces the error:</p>
  <pre><code>HttpHeaders headers = new HttpHeaders();
  headers.set(&quot;jwt&quot;, jwt); // JSON Web Token with length of over 900 characters
  HttpEntity&lt;String&gt; entity = new HttpEntity&lt;&gt;(&quot;parameters&quot;, headers);
  ResponseEntity&lt;String&gt; response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
  </code></pre>
  <p>But how can I change the used base64-encoder which is used by the <code>RestTemplate</code>?</p>
  <p>The stack trace:</p>
  <pre><code>java.lang.IllegalArgumentException: Illegal character(s) in message header value: eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJJc3N1ZXIiLCJhdWQiOi...
  
  at sun.net.www.protocol.http.HttpURLConnection.checkMessageHeader(Unknown Source) ~[na:1.8.0_91]
  at sun.net.www.protocol.http.HttpURLConnection.isExternalMessageHeaderAllowed(Unknown Source) ~[na:1.8.0_91]
  at sun.net.www.protocol.http.HttpURLConnection.addRequestProperty(Unknown Source) ~[na:1.8.0_91]
  at sun.net.www.protocol.https.HttpsURLConnectionImpl.addRequestProperty(Unknown Source) ~[na:1.8.0_91]
  at org.springframework.http.client.SimpleBufferingClientHttpRequest.addHeaders(SimpleBufferingClientHttpRequest.java:104) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:70) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:596) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:475) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  </code></pre>
  <p>EDIT:<br />
  And while adding the stack trace to my question I found the error: The newline wasn't added by the base64 encoding but by the service that gave me the jwt String...</p>
  <p>I guess I could delete my question but maybe somewhen someone will stumble upon the same mistake, so: <strong>Check your header values!</strong></p>