@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2016 the original author or authors .
* Copyright 2002 - 2017 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -37,7 +37,8 @@ public class SockJsFrame {
@@ -37,7 +37,8 @@ public class SockJsFrame {
private static final SockJsFrame CLOSE_GO_AWAY_FRAME = closeFrame ( 3000 , "Go away!" ) ;
private static final SockJsFrame CLOSE_ANOTHER_CONNECTION_OPEN_FRAME = closeFrame ( 2010 , "Another connection still open" ) ;
private static final SockJsFrame CLOSE_ANOTHER_CONNECTION_OPEN_FRAME =
closeFrame ( 2010 , "Another connection still open" ) ;
private final SockJsFrameType type ;
@ -47,10 +48,10 @@ public class SockJsFrame {
@@ -47,10 +48,10 @@ public class SockJsFrame {
/ * *
* Create a new instance frame with the given frame content .
* @param content the content , must be a non - empty and represent a valid SockJS frame
* @param content the content ( must be a non - empty and represent a valid SockJS frame )
* /
public SockJsFrame ( String content ) {
Assert . hasText ( content ) ;
Assert . hasText ( content , "Content must not be empty" ) ;
if ( "o" . equals ( content ) ) {
this . type = SockJsFrameType . OPEN ;
this . content = content ;
@ -72,35 +73,10 @@ public class SockJsFrame {
@@ -72,35 +73,10 @@ public class SockJsFrame {
this . content = ( content . length ( ) > 1 ? content : "c[]" ) ;
}
else {
throw new IllegalArgumentException ( "Unexpected SockJS frame type in content= \"" + content + "\"" ) ;
throw new IllegalArgumentException ( "Unexpected SockJS frame type in content \"" + content + "\"" ) ;
}
}
public static SockJsFrame openFrame ( ) {
return OPEN_FRAME ;
}
public static SockJsFrame heartbeatFrame ( ) {
return HEARTBEAT_FRAME ;
}
public static SockJsFrame messageFrame ( SockJsMessageCodec codec , String . . . messages ) {
String encoded = codec . encode ( messages ) ;
return new SockJsFrame ( encoded ) ;
}
public static SockJsFrame closeFrameGoAway ( ) {
return CLOSE_GO_AWAY_FRAME ;
}
public static SockJsFrame closeFrameAnotherConnectionOpen ( ) {
return CLOSE_ANOTHER_CONNECTION_OPEN_FRAME ;
}
public static SockJsFrame closeFrame ( int code , String reason ) {
return new SockJsFrame ( "c[" + code + ",\"" + reason + "\"]" ) ;
}
/ * *
* Return the SockJS frame type .
@ -110,7 +86,7 @@ public class SockJsFrame {
@@ -110,7 +86,7 @@ public class SockJsFrame {
}
/ * *
* Return the SockJS frame content , never { @code null } .
* Return the SockJS frame content ( never { @code null } ) .
* /
public String getContent ( ) {
return this . content ;
@ -129,7 +105,7 @@ public class SockJsFrame {
@@ -129,7 +105,7 @@ public class SockJsFrame {
* { @code null } .
* /
public String getFrameData ( ) {
if ( SockJsFrameType . OPEN = = getType ( ) | | SockJsFrameType . HEARTBEAT = = getType ( ) ) {
if ( getType ( ) = = SockJsFrameType . OPEN | | getType ( ) = = SockJsFrameType . HEARTBEAT ) {
return null ;
}
else {
@ -146,7 +122,8 @@ public class SockJsFrame {
@@ -146,7 +122,8 @@ public class SockJsFrame {
if ( ! ( other instanceof SockJsFrame ) ) {
return false ;
}
return ( this . type . equals ( ( ( SockJsFrame ) other ) . type ) & & this . content . equals ( ( ( SockJsFrame ) other ) . content ) ) ;
SockJsFrame otherFrame = ( SockJsFrame ) other ;
return ( this . type . equals ( otherFrame . type ) & & this . content . equals ( otherFrame . content ) ) ;
}
@Override
@ -163,4 +140,30 @@ public class SockJsFrame {
@@ -163,4 +140,30 @@ public class SockJsFrame {
return "SockJsFrame content='" + result . replace ( "\n" , "\\n" ) . replace ( "\r" , "\\r" ) + "'" ;
}
public static SockJsFrame openFrame ( ) {
return OPEN_FRAME ;
}
public static SockJsFrame heartbeatFrame ( ) {
return HEARTBEAT_FRAME ;
}
public static SockJsFrame messageFrame ( SockJsMessageCodec codec , String . . . messages ) {
String encoded = codec . encode ( messages ) ;
return new SockJsFrame ( encoded ) ;
}
public static SockJsFrame closeFrameGoAway ( ) {
return CLOSE_GO_AWAY_FRAME ;
}
public static SockJsFrame closeFrameAnotherConnectionOpen ( ) {
return CLOSE_ANOTHER_CONNECTION_OPEN_FRAME ;
}
public static SockJsFrame closeFrame ( int code , String reason ) {
return new SockJsFrame ( "c[" + code + ",\"" + reason + "\"]" ) ;
}
}