Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-4787

404 page not found error even a build is triggered successfully

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • core
    • None
    • Platform: PC, OS: All

      When a build is triggered using the following code, an 404 error returns even
      the build it triggered successfully.

      String uri = "Hudson build page/build?token=build_me";
      DocumentBuilder parser =
      DocumentBuilderFactory.newInstance().newDocumentBuilder();
      URLConnection connection = new URL(uri).openConnection();
      connection.connect();
      InputStream is = connection.getInputStream();
      Document document = parser.parse(is);

          [JENKINS-4787] 404 page not found error even a build is triggered successfully

          Alan Harder added a comment -

          can you include more of the network capture? What was the HTTP response code
          and Location header from the original request? ie, what URL is giving the 404
          response and FileNotFoundException?

          I wasn't able to reproduce this problem using wget or a java program.. both
          redirected and read the project page OK. I also tried with a space in the
          project name (using %20 in the URL) and that worked fine.. any other special
          characters in your URL that may trigger this?

          Alan Harder added a comment - can you include more of the network capture? What was the HTTP response code and Location header from the original request? ie, what URL is giving the 404 response and FileNotFoundException? I wasn't able to reproduce this problem using wget or a java program.. both redirected and read the project page OK. I also tried with a space in the project name (using %20 in the URL) and that worked fine.. any other special characters in your URL that may trigger this?

          davehun added a comment -

          I am also interested in this issue

          davehun added a comment - I am also interested in this issue

          zhipeng added a comment -

          Hi mindless,

          If I use this code:

          public static void main(String[] args) throws ParserConfigurationException,
          SAXException, IOException

          { String uri = "http://crafnanta:8081/hudson/view/Buttermere-Dev/job/MSXI%20Dev%20-%20Webstart%20Upload%20Scanner/build?token=build_me"; URLConnection connection = new URL(uri).openConnection(); connection.connect(); InputStream is = connection.getInputStream(); }

          to trigger the page.

          I will get this exception:

          Exception in thread "main" java.io.FileNotFoundException:
          http://crafnanta:8081/hudson/view/Buttermere-Dev/job/MSXI%20Dev%20-%20Webstart%20Upload%20Scanner/.
          at
          sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1288)
          at HttpTrigger.main(HttpTrigger.java:20)

          And in Wireshark I can capture this:

          GET
          /hudson/view/Buttermere-Dev/job/MSXI%20Dev%20-%20Webstart%20Upload%20Scanner/.
          HTTP/1.1

          User-Agent: Java/1.6.0_10

          Host: crafnanta:8081

          Accept: text/html, image/gif, image/jpeg, ; q=.2, */; q=.2

          Connection: keep-alive

          HTTP/1.1 404 Not Found

          X-Powered-By: Servlet/2.5

          Server: Sun Java System Application Server 9.1_02

          Set-Cookie: JSESSIONID=3d5060d18300086ba5f8a9a71fe6; Path=/hudson

          Content-Type: text/html

          Content-Language:

          Content-Length: 1028

          Date: Wed, 11 Nov 2009 15:20:38 GMT

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><title>Sun Java
          System Application Server 9.1_02 - Error report</title><style
          type="text/css"><!--H1

          {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}

          H2

          {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;}

          H3

          {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;}

          BODY

          {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;}

          B

          {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;}

          P

          {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}

          A

          {color : black;}

          HR

          {color : #525D76;}

          --></style> </head><body><h1>HTTP Status
          404 - </h1><hr/><p><b>type</b> Status
          report</p><p><b>message</b></p><p><b>description</b>The requested resource () is
          not available.</p><hr/><h3>Sun Java System Application Server
          9.1_02</h3></body></html>

          Hope this helps.

          Thanks

          zhipeng added a comment - Hi mindless, If I use this code: public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException { String uri = "http://crafnanta:8081/hudson/view/Buttermere-Dev/job/MSXI%20Dev%20-%20Webstart%20Upload%20Scanner/build?token=build_me"; URLConnection connection = new URL(uri).openConnection(); connection.connect(); InputStream is = connection.getInputStream(); } to trigger the page. I will get this exception: Exception in thread "main" java.io.FileNotFoundException: http://crafnanta:8081/hudson/view/Buttermere-Dev/job/MSXI%20Dev%20-%20Webstart%20Upload%20Scanner/ . at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1288) at HttpTrigger.main(HttpTrigger.java:20) And in Wireshark I can capture this: GET /hudson/view/Buttermere-Dev/job/MSXI%20Dev%20-%20Webstart%20Upload%20Scanner/. HTTP/1.1 User-Agent: Java/1.6.0_10 Host: crafnanta:8081 Accept: text/html, image/gif, image/jpeg, ; q=.2, */ ; q=.2 Connection: keep-alive HTTP/1.1 404 Not Found X-Powered-By: Servlet/2.5 Server: Sun Java System Application Server 9.1_02 Set-Cookie: JSESSIONID=3d5060d18300086ba5f8a9a71fe6; Path=/hudson Content-Type: text/html Content-Language: Content-Length: 1028 Date: Wed, 11 Nov 2009 15:20:38 GMT <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><title>Sun Java System Application Server 9.1_02 - Error report</title><style type="text/css"><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} A {color : black;} HR {color : #525D76;} --></style> </head><body><h1>HTTP Status 404 - </h1><hr/><p><b>type</b> Status report</p><p><b>message</b></p><p><b>description</b>The requested resource () is not available.</p><hr/><h3>Sun Java System Application Server 9.1_02</h3></body></html> Hope this helps. Thanks

          Alan Harder added a comment -

          Can you post the whole set of requests instead of just the last one? Is that
          "." really on the end of the redirect URL?
          Also, you mentioned 1.308 worked ok, what Hudson version are you using now?

          Alan Harder added a comment - Can you post the whole set of requests instead of just the last one? Is that "." really on the end of the redirect URL? Also, you mentioned 1.308 worked ok, what Hudson version are you using now?

          davehun added a comment -

          the bug is defiantly present in 1.331
          not tried version 1.333 yet

          davehun added a comment - the bug is defiantly present in 1.331 not tried version 1.333 yet

          Alan Harder added a comment -

          davehun, what web container do you use?
          I just tried SJSAS 9_1_02 and I was able to see the problem.. looking into why
          the "." gets appended on the redirect URL when running in SJSAS9. It does work
          with wget, as wget appears to trim the trailing "." before following the
          redirect.. but java takes the redirect as given and gets the 404.

          Alan Harder added a comment - davehun, what web container do you use? I just tried SJSAS 9_1_02 and I was able to see the problem.. looking into why the "." gets appended on the redirect URL when running in SJSAS9. It does work with wget, as wget appears to trim the trailing "." before following the redirect.. but java takes the redirect as given and gets the 404.

          Alan Harder added a comment -

          https://stapler.dev.java.net/source/browse/stapler/trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java?annotate=998

          Looks like the problem is line 96 here.. the lines above it calculate "base" but
          in the end it just passes "url" to super.sendRedirect(), and in this case url is
          "." (from forwardToPreviousPage above, at line 76).

          Alan Harder added a comment - https://stapler.dev.java.net/source/browse/stapler/trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java?annotate=998 Looks like the problem is line 96 here.. the lines above it calculate "base" but in the end it just passes "url" to super.sendRedirect(), and in this case url is "." (from forwardToPreviousPage above, at line 76).

          Code changed in stapler
          User: : mindless
          Path:
          trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java
          https://stapler.dev.java.net/source/browse/stapler/trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java?view=diff&rev=1241&p1=trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java&p2=trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java&r1=1240&r2=1241

          Log:
          JENKINS-4787 r754 added some code to generate an absolute path for a redirect,
          but in the end it does super.sendRedirect(url) with the original given relative path
          instead of the absolute path it built.. in particular, if the relative path was "."
          this actually gets sent to super.sendRedirect(). SJSAS9 container actually includes
          this "." in the redirect URL. Changed to super.sendRedirect(base) so redirect won't
          include trailing "."

          SCM/JIRA link daemon added a comment - Code changed in stapler User: : mindless Path: trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java https://stapler.dev.java.net/source/browse/stapler/trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java?view=diff&rev=1241&p1=trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java&p2=trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java&r1=1240&r2=1241 Log: JENKINS-4787 r754 added some code to generate an absolute path for a redirect, but in the end it does super.sendRedirect(url) with the original given relative path instead of the absolute path it built.. in particular, if the relative path was "." this actually gets sent to super.sendRedirect(). SJSAS9 container actually includes this "." in the redirect URL. Changed to super.sendRedirect(base) so redirect won't include trailing "."

          Code changed in hudson
          User: : mindless
          Path:
          trunk/hudson/main/core/pom.xml
          trunk/www/changelog.html
          http://fisheye4.cenqua.com/changelog/hudson/?cs=23658
          Log:
          [FIXED JENKINS-4787] use latest stapler with fix so we don't redirect to "." (stapler r1241)

          SCM/JIRA link daemon added a comment - Code changed in hudson User: : mindless Path: trunk/hudson/main/core/pom.xml trunk/www/changelog.html http://fisheye4.cenqua.com/changelog/hudson/?cs=23658 Log: [FIXED JENKINS-4787] use latest stapler with fix so we don't redirect to "." (stapler r1241)

          zhipeng added a comment -

          Verified.

          zhipeng added a comment - Verified.

            Unassigned Unassigned
            zhipeng zhipeng
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: