protected void setupNotificationArea ( ) throws Throwable { final String sourceMethod = "setupNotificationArea" ; URL notificationsURL = null ; HttpsURLConnection connection = null ; try { // Get URL for creating a notification area notificationsURL = serverConnection . getNotificationsURL ( ) ; if ( logger . isLoggable ( Level . FINEST ) ) { logger . logp ( Level . FINEST , logger . getName ( ) , sourceMethod , "[" + RESTClientMessagesUtil . getObjID ( this ) + "] About to call notificationURL: " + notificationsURL ) ; } // Get connection to server connection = serverConnection . getConnection ( notificationsURL , HttpMethod . POST , true ) ; // Create NotificationSettings object NotificationSettings ns = new NotificationSettings ( ) ; ns . deliveryInterval = serverConnection . getConnector ( ) . getNotificationDeliveryInterval ( ) ; ns . inboxExpiry = serverConnection . getConnector ( ) . getNotificationInboxExpiry ( ) ; // Write CreateMBean JSON to connection output stream OutputStream output = connection . getOutputStream ( ) ; converter . writeNotificationSettings ( output , ns ) ; output . flush ( ) ; } catch ( ConnectException ce ) { // Server is down; not a client bug throw ce ; } catch ( IOException io ) { throw serverConnection . getRequestErrorException ( sourceMethod , io , notificationsURL ) ; } // Check response code from server final int responseCode = connection . getResponseCode ( ) ; if ( logger . isLoggable ( Level . FINEST ) ) { logger . logp ( Level . FINEST , logger . getName ( ) , sourceMethod , "Received responseCode: " + responseCode ) ; } switch ( responseCode ) { case HttpURLConnection . HTTP_OK : JSONConverter converter = JSONConverter . getConverter ( ) ; try { // Process and return server response, which should be a NotificationArea NotificationArea area = converter . readNotificationArea ( connection . getInputStream ( ) ) ; inboxURL = new DynamicURL ( serverConnection . connector , area . inboxURL ) ; registrationsURL = new DynamicURL ( serverConnection . connector , area . registrationsURL ) ; serverRegistrationsURL = new DynamicURL ( serverConnection . connector , area . serverRegistrationsURL ) ; notificationClientURL = new DynamicURL ( serverConnection . connector , area . clientURL ) ; if ( logger . isLoggable ( Level . FINER ) ) { logger . logp ( Level . FINER , logger . getName ( ) , "setupNotificationArea" , "Successfully setup inboxURL: " + inboxURL . getURL ( ) ) ; } break ; } catch ( Exception e ) { throw serverConnection . getResponseErrorException ( sourceMethod , e , notificationsURL ) ; } finally { JSONConverter . returnConverter ( converter ) ; } case HttpURLConnection . HTTP_NOT_FOUND : throw new IOException ( RESTClientMessagesUtil . getMessage ( RESTClientMessagesUtil . URL_NOT_FOUND ) ) ; case HttpURLConnection . HTTP_UNAVAILABLE : case HttpURLConnection . HTTP_BAD_REQUEST : case HttpURLConnection . HTTP_INTERNAL_ERROR : // Server response should be a serialized Throwable throw serverConnection . getServerThrowable ( sourceMethod , connection ) ; case HttpURLConnection . HTTP_UNAUTHORIZED : case HttpURLConnection . HTTP_FORBIDDEN : throw serverConnection . getBadCredentialsException ( responseCode , connection ) ; default : throw serverConnection . getResponseCodeErrorException ( sourceMethod , responseCode , connection ) ; } }
we want to avoid cycles .