private synchronized boolean createChannel ( ) { final String url = settings . getBounceProxyUrl ( ) . buildCreateChannelUrl ( channelId ) ; HttpPost postCreateChannel = httpRequestFactory . createHttpPost ( URI . create ( url . trim ( ) ) ) ; postCreateChannel . setConfig ( defaultRequestConfig ) ; postCreateChannel . addHeader ( httpConstants . getHEADER_X_ATMOSPHERE_TRACKING_ID ( ) , receiverId ) ; postCreateChannel . addHeader ( httpConstants . getHEADER_CONTENT_TYPE ( ) , httpConstants . getAPPLICATION_JSON ( ) ) ; channelUrl = null ; CloseableHttpResponse response = null ; boolean created = false ; try { response = httpclient . execute ( postCreateChannel ) ; StatusLine statusLine = response . getStatusLine ( ) ; int statusCode = statusLine . getStatusCode ( ) ; String reasonPhrase = statusLine . getReasonPhrase ( ) ; switch ( statusCode ) { case HttpURLConnection . HTTP_OK : case HttpURLConnection . HTTP_CREATED : try { Header locationHeader = response . getFirstHeader ( httpConstants . getHEADER_LOCATION ( ) ) ; channelUrl = locationHeader != null ? locationHeader . getValue ( ) : null ; } catch ( Exception e ) { throw new JoynrChannelMissingException ( "channel url was null" ) ; } break ; default : logger . error ( "createChannel channelId: {} failed. status: {} reason: {}" , channelId , statusCode , reasonPhrase ) ; throw new JoynrChannelMissingException ( "channel url was null" ) ; } created = true ; logger . info ( "createChannel channelId: {} returned channelUrl {}" , channelId , channelUrl ) ; } catch ( ClientProtocolException e ) { logger . error ( "createChannel ERROR reason: {}" , e . getMessage ( ) ) ; } catch ( IOException e ) { logger . error ( "createChannel ERROR reason: {}" , e . getMessage ( ) ) ; } finally { if ( response != null ) { try { response . close ( ) ; } catch ( IOException e ) { logger . error ( "createChannel ERROR reason: {}" , e . getMessage ( ) ) ; } } } return created ; }
Create a new channel for the given cluster controller id . If a channel already exists it is returned instead .