Bosnia Herzegovina wasn't "occupied" in any way and it belonging to Austria-Hungary was recognized by all European powers, including Serbia, and thus legal under then international law. A limited war against Serbia following the assassination was thus justified, but Austria hadn't considered the "chain" of allied countries assisting each other extending the conflict to basically all of Europe, plus the Germans used it as justification to finally implement 30, 40 year old plans to wage war on basically everyone else around them.
tl;dr it's complicated.