package org.fedorahosted.flies.rest;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;
import org.jboss.seam.resteasy.ResteasyBootstrap;

@Name("org.jboss.seam.resteasy.bootstrap")
@Scope(ScopeType.APPLICATION)
@Startup
@AutoCreate
@Install(classDependencies = "org.jboss.resteasy.spi.ResteasyProviderFactory", precedence=Install.DEPLOYMENT)
public class FliesResteasyBootstrap extends ResteasyBootstrap {

	@Override
	protected void initDispatcher() {
		super.initDispatcher();
		getDispatcher().getProviderFactory().getServerPreProcessInterceptorRegistry().register(FliesRestSecurityInterceptor.class);
	}
}

@@ -31,16 +31,321 @@
 .rest;%0A%0A
+import java.io.IOException;%0A%0Aimport javax.ws.rs.core.Response.Status;%0A%0Aimport org.jboss.resteasy.core.Dispatcher;%0Aimport org.jboss.resteasy.core.SynchronousDispatcher;%0Aimport org.jboss.resteasy.spi.HttpRequest;%0Aimport org.jboss.resteasy.spi.HttpResponse;%0Aimport org.jboss.resteasy.spi.UnhandledException;%0A
 import o
@@ -365,24 +365,24 @@
 .ScopeType;%0A
-
 import org.j
@@ -458,16 +458,58 @@
 nstall;%0A
+import org.jboss.seam.annotations.Logger;%0A
 import o
@@ -624,16 +624,47 @@
 tartup;%0A
+import org.jboss.seam.log.Log;%0A
 import o
@@ -704,16 +704,76 @@
 otstrap;
+%0Aimport org.jboss.seam.resteasy.SeamResteasyProviderFactory;
 %0A%0A@Name(
@@ -1035,16 +1035,37 @@
 trap %7B%0A%0A
+%09@Logger%0A%09Log log;%0A%09%0A
 %09@Overri
@@ -1128,16 +1128,16 @@
 cher();%0A
-
 %09%09getDis
@@ -1257,10 +1257,639 @@
 ss);%0A%09%7D%0A
+%09%0A%09@Override%0A%09protected Dispatcher createDispatcher(%0A%09%09%09SeamResteasyProviderFactory providerFactory) %7B%0A%09%09return new SynchronousDispatcher(providerFactory)%7B%0A%09%09%09@Override%0A%09%09%09public void invoke(HttpRequest request, HttpResponse response) %7B%0A%09%09%09%09try%7B%0A%09%09%09%09%09super.invoke(request, response);%0A%09%09%09%09%7D%0A%09%09%09%09catch(UnhandledException e)%7B%0A%09%09%09%09%09log.error(%22Failed to process REST request%22, e.getCause());%0A%09%09%09%09%09try%7B%0A%09%09%09%09%09%09response.sendError(Status.INTERNAL_SERVER_ERROR.getStatusCode(), %22Error processing Request%22);%0A%09%09%09%09%09%7D%0A%09%09%09%09%09catch(IOException ioe)%7B%0A%09%09%09%09%09%09log.error(%22Failed to send error on failed REST request%22, ioe);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D;%09%0A%09%7D%0A
 %7D%0A

handle unhandled exceptions within RestEasy rather than letting Seam mess it up