aspose file tools*
The moose likes Java in General and the fly likes Server returned HTTP response code: 405 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Server returned HTTP response code: 405" Watch "Server returned HTTP response code: 405" New topic
Author

Server returned HTTP response code: 405

Prashant Sehgal
Ranch Hand

Joined: Jun 20, 2003
Posts: 56
Hi,

I have read two threadS here on this but both seemed inconclusive, hence posting a new one. Here're the deatils:

Objects:
-------
  • I have an Applet that calls a Servlet.
  • The Servlet in turn calls a utility class.
  • The utility class generates random logging messages.


  • Flow:
    -----
  • The Applet passes data to the servlet in onMigrate() method.
  • The Servlet instantiates a new DummyLogger and gets some messages.
  • The Servlet then passes the log messages back to the Applet.
  • The Applet uses a timer to wake up, checks if there's a new log message and then displays them in it's text area.



  • Problem:
    --------
  • When I use the doGet() in the servlet, the code works only if I create a new URLConnection object everytime in the run method.
  • When I use the doPost() method the following exception is thrown:




  • Questions:
    ----------
  • What am I doing wrong?
  • I read all over the web that one need to include the method that's causing an HTTP 405 error, in the response's "Allow" header. Isn't that the ServletContainer's job (setting response headers). I did try the following two ways, but neither worked:


  • and
  • How do I get this to work?



  • I'm now going to attach the code for my app, apologies for the long code/ For the sake of simplicity - I have omitted the complex logging logic (as it used other classes also) but just using System.set/getProperty(new java.util.Date()); to simulate 50 different log messages.

    MigrationApplet.java


    MigrationServlet.java


    DummyLogger.java


    [ September 07, 2007: Message edited by: Prashant Sehgal ]
    [ September 09, 2007: Message edited by: Prashant Sehgal ]
    Ryan DeJana
    Greenhorn

    Joined: Sep 07, 2007
    Posts: 9
    Hello, you need to implement doPost in your servlet. The 405 is saying that the servlet does not support the POST method.
    Prashant Sehgal
    Ranch Hand

    Joined: Jun 20, 2003
    Posts: 56
    Well, I've tried both. doPost() also throws the same error. The whole idea of giving the entire code here was so that someone could try running/deploying this.
    Ryan DeJana
    Greenhorn

    Joined: Sep 07, 2007
    Posts: 9
    Not clear what you mean by tried both, but run this simple sample servlet.
    Run this servlet. In IE you will see a message that says "HTTP 405 - Resource not allowed" and in Firefox, the message is a bit clearer: "Error 405: HTTP method GET is not supported by this URL" Looking back at the code you will see that this servlet does not implement doGet. If you were to add the doGet method, it would work fine. Your code as the same problem; if your applet uses an HTTP POST method, the container will return the 405 error as you haven't implemented doPost.
    Prashant Sehgal
    Ranch Hand

    Joined: Jun 20, 2003
    Posts: 56
    Thanks ryan, I added doGet() and it worked.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Server returned HTTP response code: 405