public WampMessage parseMessage ( ChargingStationId chargingStationId , Reader reader ) throws IOException { String rawMessage = this . convertToString ( reader ) ; String trimmedMessage = this . removeBrackets ( rawMessage ) ; //In case a payload is present, it always is the last part of the message int payloadStart = trimmedMessage . indexOf ( "{" ) ; String payload = payloadStart > 0 ? trimmedMessage . substring ( payloadStart ) : null ; String metaData = payloadStart > 0 ? trimmedMessage . substring ( 0 , payloadStart ) : trimmedMessage ; String [ ] metaDataParts = metaData . split ( "," ) ; int messageType = Integer . parseInt ( removeQuotesAndTrim ( metaDataParts [ 0 ] ) ) ; String callId = removeQuotes ( removeQuotesAndTrim ( metaDataParts [ 1 ] ) ) ; WampMessage wampMessage ; switch ( messageType ) { case WampMessage . CALL : MessageProcUri procUri = MessageProcUri . fromValue ( removeQuotesAndTrim ( metaDataParts [ 2 ] ) ) ; wampMessage = new WampMessage ( messageType , callId , procUri , payload ) ; if ( wampMessageHandler != null ) { wampMessageHandler . handleWampCall ( chargingStationId . getId ( ) , rawMessage , callId ) ; } break ; case WampMessage . CALL_RESULT : wampMessage = new WampMessage ( messageType , callId , payload ) ; if ( wampMessageHandler != null ) { wampMessageHandler . handleWampCallResult ( chargingStationId . getId ( ) , rawMessage , callId ) ; } break ; case WampMessage . CALL_ERROR : String errorCode = removeQuotes ( metaDataParts [ 2 ] ) ; String errorDescription = removeQuotes ( metaDataParts [ 3 ] ) ; String errorDetails = removeQuotes ( metaDataParts [ 4 ] ) ; wampMessage = new WampMessage ( messageType , callId , errorCode , errorDescription , errorDetails ) ; if ( wampMessageHandler != null ) { wampMessageHandler . handleWampCallError ( chargingStationId . getId ( ) , rawMessage , callId ) ; } break ; default : if ( wampMessageHandler != null ) { wampMessageHandler . handle ( chargingStationId . getId ( ) , rawMessage ) ; } throw new IllegalArgumentException ( String . format ( "Unknown WAMP messageType: %s" , messageType ) ) ; } return wampMessage ; }
Parses a CALL RESULT or ERROR message and constructs a WampMessage