1818
1919import java .nio .charset .Charset ;
2020import java .nio .charset .StandardCharsets ;
21+ import java .security .Principal ;
2122import java .util .Arrays ;
2223import java .util .Collections ;
2324import java .util .List ;
@@ -165,11 +166,13 @@ else if (StompCommand.CONNECT.equals(command)) {
165166 }
166167
167168 void updateStompHeadersFromSimpMessageHeaders () {
168- if (getDestination () != null ) {
169- setNativeHeader (STOMP_DESTINATION_HEADER , getDestination ());
169+ String destination = getDestination ();
170+ if (destination != null ) {
171+ setNativeHeader (STOMP_DESTINATION_HEADER , destination );
170172 }
171- if (getContentType () != null ) {
172- setNativeHeader (STOMP_CONTENT_TYPE_HEADER , getContentType ().toString ());
173+ MimeType contentType = getContentType ();
174+ if (contentType != null ) {
175+ setNativeHeader (STOMP_CONTENT_TYPE_HEADER , contentType .toString ());
173176 }
174177 trySetStompHeaderForSubscriptionId ();
175178 }
@@ -188,21 +191,24 @@ protected Map<String, List<String>> getNativeHeaders() {
188191 }
189192
190193 public StompCommand updateStompCommandAsClientMessage () {
191- if (getMessageType () != SimpMessageType .MESSAGE ) {
192- throw new IllegalStateException ("Unexpected message type " + getMessageType ());
194+ SimpMessageType messageType = getMessageType ();
195+ if (messageType != SimpMessageType .MESSAGE ) {
196+ throw new IllegalStateException ("Unexpected message type " + messageType );
193197 }
194- if (getCommand () == null ) {
198+ StompCommand command = getCommand ();
199+ if (command == null ) {
195200 setHeader (COMMAND_HEADER , StompCommand .SEND );
196201 }
197- else if (!getCommand () .equals (StompCommand .SEND )) {
198- throw new IllegalStateException ("Unexpected STOMP command " + getCommand () );
202+ else if (!command .equals (StompCommand .SEND )) {
203+ throw new IllegalStateException ("Unexpected STOMP command " + command );
199204 }
200- return getCommand () ;
205+ return command ;
201206 }
202207
203208 public void updateStompCommandAsServerMessage () {
204- if (getMessageType () != SimpMessageType .MESSAGE ) {
205- throw new IllegalStateException ("Unexpected message type " + getMessageType ());
209+ SimpMessageType messageType = getMessageType ();
210+ if (messageType != SimpMessageType .MESSAGE ) {
211+ throw new IllegalStateException ("Unexpected message type " + messageType );
206212 }
207213 StompCommand command = getCommand ();
208214 if ((command == null ) || StompCommand .SEND .equals (command )) {
@@ -278,7 +284,8 @@ public void setSubscriptionId(@Nullable String subscriptionId) {
278284 private void trySetStompHeaderForSubscriptionId () {
279285 String subscriptionId = getSubscriptionId ();
280286 if (subscriptionId != null ) {
281- if (getCommand () != null && StompCommand .MESSAGE .equals (getCommand ())) {
287+ StompCommand command = getCommand ();
288+ if (command != null && StompCommand .MESSAGE .equals (command )) {
282289 setNativeHeader (STOMP_SUBSCRIPTION_HEADER , subscriptionId );
283290 }
284291 else {
@@ -403,23 +410,26 @@ public void setVersion(@Nullable String version) {
403410
404411 @ Override
405412 public String getShortLogMessage (Object payload ) {
406- if (StompCommand .SUBSCRIBE .equals (getCommand ())) {
413+ StompCommand command = getCommand ();
414+ if (StompCommand .SUBSCRIBE .equals (command )) {
407415 return "SUBSCRIBE " + getDestination () + " id=" + getSubscriptionId () + appendSession ();
408416 }
409- else if (StompCommand .UNSUBSCRIBE .equals (getCommand () )) {
417+ else if (StompCommand .UNSUBSCRIBE .equals (command )) {
410418 return "UNSUBSCRIBE id=" + getSubscriptionId () + appendSession ();
411419 }
412- else if (StompCommand .SEND .equals (getCommand () )) {
420+ else if (StompCommand .SEND .equals (command )) {
413421 return "SEND " + getDestination () + appendSession () + appendPayload (payload );
414422 }
415- else if (StompCommand .CONNECT .equals (getCommand ())) {
416- return "CONNECT" + (getUser () != null ? " user=" + getUser ().getName () : "" ) + appendSession ();
423+ else if (StompCommand .CONNECT .equals (command )) {
424+ Principal user = getUser ();
425+ return "CONNECT" + (user != null ? " user=" + user .getName () : "" ) + appendSession ();
417426 }
418- else if (StompCommand .CONNECTED .equals (getCommand () )) {
427+ else if (StompCommand .CONNECTED .equals (command )) {
419428 return "CONNECTED heart-beat=" + Arrays .toString (getHeartbeat ()) + appendSession ();
420429 }
421- else if (StompCommand .DISCONNECT .equals (getCommand ())) {
422- return "DISCONNECT" + (getReceipt () != null ? " receipt=" + getReceipt () : "" ) + appendSession ();
430+ else if (StompCommand .DISCONNECT .equals (command )) {
431+ String receipt = getReceipt ();
432+ return "DISCONNECT" + (receipt != null ? " receipt=" + receipt : "" ) + appendSession ();
423433 }
424434 else {
425435 return getDetailedLogMessage (payload );
@@ -462,11 +472,12 @@ private String appendPayload(Object payload) {
462472 "Expected byte array payload but got: " + ClassUtils .getQualifiedName (payload .getClass ()));
463473 }
464474 byte [] bytes = (byte []) payload ;
465- String contentType = (getContentType () != null ? " " + getContentType ().toString () : "" );
466- if (bytes .length == 0 || getContentType () == null || !isReadableContentType ()) {
475+ MimeType mimeType = getContentType ();
476+ String contentType = (mimeType != null ? " " + mimeType .toString () : "" );
477+ if (bytes .length == 0 || mimeType == null || !isReadableContentType ()) {
467478 return contentType ;
468479 }
469- Charset charset = getContentType () .getCharset ();
480+ Charset charset = mimeType .getCharset ();
470481 charset = (charset != null ? charset : StandardCharsets .UTF_8 );
471482 return (bytes .length < 80 ) ?
472483 contentType + " payload=" + new String (bytes , charset ) :
0 commit comments