File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\diagnosis\ReverseProxySetupMonitor.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2010, InfraDNA, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.diagnosis;
25
26 import hudson.Extension;
27 import hudson.model.AdministrativeMonitor;
28 import hudson.util.FormValidation;
29 import org.kohsuke.stapler.HttpRedirect;
30 import org.kohsuke.stapler.HttpResponse;
31 import org.kohsuke.stapler.HttpResponses;
32 import org.kohsuke.stapler.QueryParameter;
33 import org.kohsuke.stapler.WebMethod;
34
35 import java.io.IOException;
36
37 /**
38 * Looks out for a broken reverse proxy setup that doesn't rewrite the location header correctly.
39 *
40 * <p>
41 * Have the JavaScript make an AJAX call, to which we respond with 302 redirect. If the reverse proxy
42 * is done correctly, this will be handled by {@link #doFoo()}, but otherwise we'll report that as an error.
43 * Unfortunately, {@code XmlHttpRequest} doesn't expose properties that allow the client-side JavaScript
44 * to learn the details of the failure, so we have to make do with limited information.
45 *
46 * @author Kohsuke Kawaguchi
47 */
48 @Extension
49 public class ReverseProxySetupMonitor extends AdministrativeMonitor {
50 @Override
51 public boolean isActivated() {
52 // return true to always inject an HTML fragment to perform a test
53 return true;
54 }
55
56 public HttpResponse doTest() {
57 return new HttpRedirect("test-for-reverse-proxy-setup");
58 }
59
60 @WebMethod(name="test-for-reverse-proxy-setup")
61 public FormValidation doFoo() {
62 return FormValidation.ok();
63 }
64
65 /**
66 * Depending on whether the user said "yes" or "no", send him to the right place.
67 */
68 public HttpResponse doAct(@QueryParameter String no) throws IOException {
69 if(no!=null) { // dismiss
70 disable(true);
71 // of course the irony is that this redirect won't work
72 return HttpResponses.redirectViaContextPath("/manage");
73 } else {
74 return new HttpRedirect("https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+says+my+reverse+proxy+setup+is+broken");
75 }
76 }
77 }
78
79