private boolean sendPayload ( URL payloadResourceUrl , RoxPayload payload , boolean optimized ) { HttpURLConnection conn = null ; final String payloadLogString = optimized ? "optimized payload" : "payload" ; try { conn = uploadPayload ( payloadResourceUrl , payload ) ; if ( conn . getResponseCode ( ) == 202 ) { LOGGER . info ( "The {} was successfully sent to ROX Center." , payloadLogString ) ; return true ; } else { LOGGER . error ( "Unable to send the {} to Rox. Return code: {}, content: {}" , payloadLogString , conn . getResponseCode ( ) , readInputStream ( conn . getInputStream ( ) ) ) ; } } catch ( IOException ioe ) { if ( ! configuration . isPayloadPrint ( ) ) { OutputStreamWriter baos = null ; try { baos = new OutputStreamWriter ( new ByteArrayOutputStream ( ) , Charset . forName ( Constants . ENCODING ) . newEncoder ( ) ) ; serializer . serializePayload ( baos , payload , true ) ; LOGGER . error ( "The {} in error: {}" , payloadLogString , baos . toString ( ) ) ; } catch ( IOException baosIoe ) { } finally { try { if ( baos != null ) { baos . close ( ) ; } } catch ( IOException baosIoe ) { } } if ( conn != null ) { try { if ( conn . getErrorStream ( ) != null ) { LOGGER . error ( "Unable to send the {} to ROX. Error: {}" , payloadLogString , readInputStream ( conn . getErrorStream ( ) ) ) ; } else { LOGGER . error ( "Unable to send the " + payloadLogString + " to ROX. This is probably due to an unreachable network issue." , ioe ) ; } } catch ( IOException errorIoe ) { LOGGER . error ( "Unable to send the {} to ROX for unknown reason." , payloadLogString ) ; } } else { LOGGER . error ( "Unable to send the |{} to ROX. Error: {}" , payloadLogString , ioe . getMessage ( ) ) ; } } } return false ; }
Internal method to send the payload to ROX center agnostic to the payload optimization