You know, it's not entirely unreasonable that someone could package a bomb to look like a gift-wrapped paperback. So if their technology can't distinguish your book from a potential explosive via X-rays alone, it may have to get opened. Explosives detection results in false alarms, unfortunately, but as far as I know most countries do it and it rarely results in such inconvenience to passengers.
The rifle cartridge is obviously on their contraband list, so it should have been caught. Someone probably brought it through accidentally. .22 LR?