Middletown — Raymond Zayas stabbed a guy three years ago in Newburgh.

Middletown — Raymond Zayas stabbed a guy three years ago in Newburgh.

He cut a deal to plead guilty to attempted second-degree assault and got five years' probation.

That conviction meant the 34-year-old Middletown man could not legally have a gun.

But he did — a Czech 9 mm handgun. Cops say he fired the gun Tuesday at Middletown police Officer Christopher Dolan as he responded to a call at Zayas' house about a domestic disturbance. A bullet hit Dolan, 22, in the hip; another bullet hit his arm. Dolan is recovering from his injuries and remains in stable condition at the Horton campus of Orange Regional Medical Center.

Police Chief Matthew Byrne said detectives are working with the federal Bureau of Alcohol, Tobacco, Firearms and Explosives to trace where that gun came from and how Zayas allegedly got his hands on it. Byrne said Zayas didn't have a pistol permit. Sources say the gun was not stolen.

Chances are good that Zayas got the gun illegally, Byrne said.

Dolan responded Tuesday to the Zayas home at 317 Wawayanda Ave. with at least five other Middletown officers for a report of a man with a knife. Dolan had been there July 2 on a custody dispute call, police said. He knocked on the side door to the house and Zayas — who had his 1-year-old son and wife inside with him — fired two shots through the door, hitting the officer.

Middletown police Officer Frank Speranza shot back — at least twice — through the closed door. Byrne would not comment on why Speranza fired through a closed door. He said the department continues to investigate the incident.

Zayas is being held in Orange County Jail with no bail, charged with attempted murder of a police officer.

A grand jury is expected to convene soon to hear evidence in the case against Zayas. Zayas' family could not be reached for comment yesterday.

Yesterday, Byrne attended a news conference in Goshen about the first gun buyback program held in Middletown, Port Jervis and Newburgh.

During that monthlong program, nearly 200 handguns were turned in to those departments in exchange for ShopRite gift cards.

Byrne said of the Czech gun: "If this weapon had been turned in by someone in that house, this never would have happened."