throws NetException,
SerializationException,
IOException,
RemoteCallException
{
final Binding binding = Binding.create();
final ProgressEvent pe = new ProgressEvent();
pe.setAnimate( true );
pe.setSource( this );
try
{
pe.setMessage( ResourceManager.getResource( "bm.net.rpc.SendingCall" ) );
pe.dispatch();
binding.open( url );
final DataOutputStream dos = binding.beginPost();
final ChecksumedOutputStream cos = new ChecksumedOutputStream( dos );
final DataOutputStream dos2 = new DataOutputStream( cos );
final SerializerOutputStream out = new SerializerOutputStream( dos2 );
out.writeByte( VERSION );
out.writeByte( (byte) (encrypted ? 1 : 0) );
out.writeString( Net.getDeviceGuid() != null ? Net.getDeviceGuid() : "" );
out.writeLong( Net.getDeviceId() != null ? Net.getDeviceId().longValue() : 0 );
serialize( out );
final long crc = cos.getCRC();
out.writeString( "END_OF_DATA" );
out.writeLong( crc );
pe.setMessage( ResourceManager.getResource( "bm.net.rpc.WaitingResponse" ) );
pe.dispatch();
log.debug( "Call serialized" );
final DataInputStream is = binding.endPost();
final SerializerInputStream in = new SerializerInputStream( is );
pe.setMessage( ResourceManager.getResource( "bm.net.rpc.ReadingResponse" ) );
pe.dispatch();
final int responseCode = in.readInt();
final String responseMessage = in.readString();
if( responseCode == Net.RC_SUCCESS )
{
return in.readNullableObject();
}
else if( responseCode != Net.RC_INVALID_CRC )
{
log.error( "Unrecoverable error: " + responseCode + " " + responseMessage );
throw new RemoteCallException(
Net.ERR_RC_UNRECOVERABLE_ERROR,
responseMessage
);
}
else
{
log.error( "Invalid CRC" );
throw new IOException( "Invalid CRC" ); // Perform retry
}
}
finally
{
binding.close();
}
}