01: package com.icesoft.faces.webapp.http.core;
02:
03: import com.icesoft.faces.webapp.http.common.Configuration;
04: import com.icesoft.faces.webapp.http.common.Request;
05: import com.icesoft.faces.webapp.http.common.Response;
06: import com.icesoft.faces.webapp.http.common.ResponseHandler;
07: import com.icesoft.faces.webapp.http.common.Server;
08:
09: import java.io.PrintStream;
10:
11: public class RedirectOnJSBlocked implements Server {
12: private ResponseHandler handler;
13:
14: public RedirectOnJSBlocked(Configuration configuration) {
15: try {
16: final String redirectURI = configuration
17: .getAttribute("javascriptBlockedRedirectURI");
18: handler = new ResponseHandler() {
19: public void respond(Response response) {
20: response.setStatus(307);
21: response.setHeader("Location", redirectURI);
22: }
23: };
24: } catch (Exception e) {
25: handler = new ResponseHandler() {
26: public void respond(Response response) throws Exception {
27: response.setStatus(403);
28: PrintStream stream = new PrintStream(response
29: .writeBody());
30: stream
31: .println("Javascript is blocked. ICEfaces cannot run.");
32: }
33: };
34: }
35: }
36:
37: public void service(final Request request) throws Exception {
38: request.respondWith(handler);
39: }
40:
41: public void shutdown() {
42: }
43: }
|