11/*
2- * Copyright 2017-2018 the original author or authors.
2+ * Copyright 2017-2019 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -183,11 +183,11 @@ protected Set<String> getToStringClasses() {
183183 * If any of the supplied packages is {@code "*"}, all packages are trusted.
184184 * If a class for a non-trusted package is encountered, the header is returned to the
185185 * application with value of type {@link NonTrustedHeaderType}.
186- * @param trustedPackages the packages to trust.
186+ * @param packagesToTrust the packages to trust.
187187 */
188- public void addTrustedPackages (String ... trustedPackages ) {
189- if (trustedPackages != null ) {
190- for (String whiteList : trustedPackages ) {
188+ public void addTrustedPackages (String ... packagesToTrust ) {
189+ if (packagesToTrust != null ) {
190+ for (String whiteList : packagesToTrust ) {
191191 if ("*" .equals (whiteList )) {
192192 this .trustedPackages .clear ();
193193 break ;
@@ -213,25 +213,26 @@ public void addToStringClasses(String... classNames) {
213213 public void fromHeaders (MessageHeaders headers , Headers target ) {
214214 final Map <String , String > jsonHeaders = new HashMap <>();
215215 final ObjectMapper headerObjectMapper = getObjectMapper ();
216- headers .forEach ((k , v ) -> {
217- if (matches (k , v )) {
218- if (v instanceof byte []) {
219- target .add (new RecordHeader (k , (byte []) v ));
216+ headers .forEach ((key , val ) -> {
217+ if (matches (key , val )) {
218+ Object valueToAdd = headerValueToAddOut (key , val );
219+ if (valueToAdd instanceof byte []) {
220+ target .add (new RecordHeader (key , (byte []) valueToAdd ));
220221 }
221222 else {
222223 try {
223- Object value = v ;
224- String className = v .getClass ().getName ();
224+ Object value = valueToAdd ;
225+ String className = valueToAdd .getClass ().getName ();
225226 if (this .toStringClasses .contains (className )) {
226- value = v .toString ();
227+ value = valueToAdd .toString ();
227228 className = "java.lang.String" ;
228229 }
229- target .add (new RecordHeader (k , headerObjectMapper .writeValueAsBytes (value )));
230- jsonHeaders .put (k , className );
230+ target .add (new RecordHeader (key , headerObjectMapper .writeValueAsBytes (value )));
231+ jsonHeaders .put (key , className );
231232 }
232- catch (Exception e ) {
233+ catch (@ SuppressWarnings ( "unused" ) Exception e ) {
233234 if (logger .isDebugEnabled ()) {
234- logger .debug ("Could not map " + k + " with type " + v .getClass ().getName ());
235+ logger .debug ("Could not map " + key + " with type " + valueToAdd .getClass ().getName ());
235236 }
236237 }
237238 }
@@ -250,11 +251,11 @@ public void fromHeaders(MessageHeaders headers, Headers target) {
250251 @ Override
251252 public void toHeaders (Headers source , final Map <String , Object > headers ) {
252253 final Map <String , String > jsonTypes = decodeJsonTypes (source );
253- source .forEach (h -> {
254- if (!(h .key ().equals (JSON_TYPES ))) {
255- if (jsonTypes != null && jsonTypes .containsKey (h .key ())) {
254+ source .forEach (header -> {
255+ if (!(header .key ().equals (JSON_TYPES ))) {
256+ if (jsonTypes != null && jsonTypes .containsKey (header .key ())) {
256257 Class <?> type = Object .class ;
257- String requestedType = jsonTypes .get (h .key ());
258+ String requestedType = jsonTypes .get (header .key ());
258259 boolean trusted = false ;
259260 try {
260261 trusted = trusted (requestedType );
@@ -263,26 +264,26 @@ public void toHeaders(Headers source, final Map<String, Object> headers) {
263264 }
264265 }
265266 catch (Exception e ) {
266- logger .error ("Could not load class for header: " + h .key (), e );
267+ logger .error ("Could not load class for header: " + header .key (), e );
267268 }
268269 if (trusted ) {
269270 try {
270- Object value = decodeValue (h , type );
271- headers .put (h .key (), value );
271+ Object value = decodeValue (header , type );
272+ headers .put (header .key (), value );
272273 }
273274 catch (IOException e ) {
274- logger .error ("Could not decode json type: " + new String (h .value ()) + " for key: " + h
275+ logger .error ("Could not decode json type: " + new String (header .value ()) + " for key: " + header
275276 .key (),
276277 e );
277- headers .put (h .key (), h .value ());
278+ headers .put (header .key (), header .value ());
278279 }
279280 }
280281 else {
281- headers .put (h .key (), new NonTrustedHeaderType (h .value (), requestedType ));
282+ headers .put (header .key (), new NonTrustedHeaderType (header .value (), requestedType ));
282283 }
283284 }
284285 else {
285- headers .put (h .key (), h . value ( ));
286+ headers .put (header .key (), headertValueToAddIn ( header ));
286287 }
287288 }
288289 });
@@ -419,7 +420,7 @@ public String toString() {
419420 return "NonTrustedHeaderType [headerValue=" + new String (this .headerValue , StandardCharsets .UTF_8 )
420421 + ", untrustedType=" + this .untrustedType + "]" ;
421422 }
422- catch (Exception e ) {
423+ catch (@ SuppressWarnings ( "unused" ) Exception e ) {
423424 return "NonTrustedHeaderType [headerValue=" + Arrays .toString (this .headerValue ) + ", untrustedType="
424425 + this .untrustedType + "]" ;
425426 }
0 commit comments