public String postMessage ( String ccid , byte [ ] serializedMessage ) { ImmutableMessage message ; try { message = new ImmutableMessage ( serializedMessage ) ; } catch ( EncodingException | UnsuppportedVersionException e ) { throw new JoynrHttpException ( Status . BAD_REQUEST , JOYNRMESSAGINGERROR_DESERIALIZATIONFAILED ) ; } if ( ccid == null ) { log . error ( "POST message {} to cluster controller: NULL. Dropped because: channel Id was not set." , message . getId ( ) ) ; throw new JoynrHttpException ( Status . BAD_REQUEST , JOYNRMESSAGINGERROR_CHANNELNOTSET ) ; } // send the message to the receiver. if ( message . getTtlMs ( ) == 0 ) { log . error ( "POST message {} to cluster controller: {} dropped because: expiry date not set" , ccid , message . getId ( ) ) ; throw new JoynrHttpException ( Status . BAD_REQUEST , JOYNRMESSAGINGERROR_EXPIRYDATENOTSET ) ; } // Relative TTLs are not supported yet. if ( ! message . isTtlAbsolute ( ) ) { throw new JoynrHttpException ( Status . BAD_REQUEST , JOYNRMESSAGINGERROR_RELATIVE_TTL_UNSPORTED ) ; } if ( message . getTtlMs ( ) < System . currentTimeMillis ( ) ) { log . warn ( "POST message {} to cluster controller: {} dropped because: TTL expired" , ccid , message . getId ( ) ) ; throw new JoynrHttpException ( Status . BAD_REQUEST , JOYNRMESSAGINGERROR_EXPIRYDATEEXPIRED ) ; } // look for an existing broadcaster Broadcaster ccBroadcaster = BroadcasterFactory . getDefault ( ) . lookup ( Broadcaster . class , ccid , false ) ; if ( ccBroadcaster == null ) { // if the receiver has never registered with the bounceproxy // (or his registration has expired) then return 204 no // content. log . error ( "POST message {} to cluster controller: {} dropped because: no channel found" , ccid , message . getId ( ) ) ; throw new JoynrHttpException ( Status . BAD_REQUEST , JOYNRMESSAGINGERROR_CHANNELNOTFOUND ) ; } if ( ccBroadcaster . getAtmosphereResources ( ) . size ( ) == 0 ) { log . debug ( "no poll currently waiting for channelId: {}" , ccid ) ; } ccBroadcaster . broadcast ( message ) ; return "messages/" + message . getId ( ) ; }
Posts a message to a long polling channel .