private void setNegotiatedExtensions ( String extensionsHeader ) { if ( ( extensionsHeader == null ) || ( extensionsHeader . trim ( ) . length ( ) == 0 ) ) { _negotiatedExtensions = null ; return ; } String [ ] extns = extensionsHeader . split ( "," ) ; List < String > extnNames = new ArrayList < String > ( ) ; for ( String extn : extns ) { String [ ] properties = extn . split ( ";" ) ; String extnName = properties [ 0 ] . trim ( ) ; if ( ! getEnabledExtensions ( ) . contains ( extnName ) ) { String s = String . format ( "Extension '%s' is not an enabled " + "extension so it should not have been negotiated" , extnName ) ; setException ( new WebSocketException ( s ) ) ; return ; } WebSocketExtension extension = WebSocketExtension . getWebSocketExtension ( extnName ) ; WsExtensionParameterValuesSpiImpl paramValues = _negotiatedParameters . get ( extnName ) ; Collection < Parameter < ? > > anonymousParams = extension . getParameters ( Metadata . ANONYMOUS ) ; // Start from the second(0-based) property to parse the name-value // pairs as the first(or 0th) is the extension name. for ( int i = 1 ; i < properties . length ; i ++ ) { String property = properties [ i ] . trim ( ) ; String [ ] pair = property . split ( "=" ) ; Parameter < ? > parameter = null ; String paramValue = null ; if ( pair . length == 1 ) { // We are dealing with an anonymous parameter. Since the // Collection is actually an ArrayList, we are guaranteed to // iterate the parameters in the definition/creation order. // As there is no parameter name, we will just get the next // anonymous Parameter instance and use it for setting the // value. The onus is on the extension implementor to either // use only named parameters or ensure that the anonymous // parameters are defined in the order in which the server // will send them back during negotiation. parameter = anonymousParams . iterator ( ) . next ( ) ; paramValue = pair [ 0 ] . trim ( ) ; } else { parameter = extension . getParameter ( pair [ 0 ] . trim ( ) ) ; paramValue = pair [ 1 ] . trim ( ) ; } if ( parameter . type ( ) != String . class ) { String paramName = parameter . name ( ) ; String s = String . format ( "Negotiated Extension '%s': " + "Type of parameter '%s' should be String" , extnName , paramName ) ; setException ( new WebSocketException ( s ) ) ; return ; } if ( paramValues == null ) { paramValues = new WsExtensionParameterValuesSpiImpl ( ) ; _negotiatedParameters . put ( extnName , paramValues ) ; } paramValues . setParameterValue ( parameter , paramValue ) ; } extnNames . add ( extnName ) ; } HashSet < String > extnsSet = new HashSet < String > ( extnNames ) ; _negotiatedExtensions = unmodifiableCollection ( extnsSet ) ; }
RFC 3864 format .