sri ranjjani
sri ranjjani

Reputation: 11

HTTP method GET is not supported by this URL- Google App Engine

   public class MailHandlerServlet extends HttpServlet { 
    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {

    try {

    Properties props = new Properties();
    Session session1 = Session.getDefaultInstance(props, null);
    MimeMessage message = new MimeMessage(session1, req.getInputStream());

     //Extract out the important fields from the Mime Message
     String subject = message.getSubject();    
    String contentType = message.getContentType();

    printParts(message);
    //Parse out the Multiparts
    //Perform business logic based on the email
    }
    catch (IOException | MessagingException ex) {

     }
    }

    private static void printParts(Part p) throws IOException, MessagingException {
    Object o = p.getContent();

    if (o instanceof String) {
        out.println("This is a String");
    out.println((String)o);
    }
    else if (o instanceof Multipart) {
    out.println("This is a Multipart");
    Multipart mp = (Multipart)o;

    int count = mp.getCount();
    for (int i = 0; i < count; i++) {
    printParts(mp.getBodyPart(i));
    }
    }
    else if (o instanceof InputStream) {
    out.println("This is just an input stream");
    InputStream is = (InputStream)o;
    int c;
    while ((c = is.read()) != -1)
    out.write(c);
    }
    }

    }

The above code gives me an error like this..."HTTP method GET is not supported by this URL" Please help me to fix it. Am deploying it in GAE. I am writing this code to receive mail to my appspot.com. I have updated my appengine-web.xml and web.xml as well. When i try to run the page, it shows me this error.

Upvotes: 1

Views: 275

Answers (2)

Dhanu MS
Dhanu MS

Reputation: 21

recently, I am also working on google app engine sample web application called DrEdit and I too get this error. I wrote the following code to make it work.

@Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException, ServletException {
      System.out.println("start of GoogleDriveAuth:::::::");
      credentialManager = new CredentialManager(
                getClientSecrets(), TRANSPORT, JSON_FACTORY);
      handleCallbackIfRequired(req, resp);

You need to write the similar doGet method for your application. Hope it helps !

Upvotes: 0

Andrei Volgin
Andrei Volgin

Reputation: 41089

There is no doGet method in this servlet, and you are making a GET call to it. You either have to make a POST call or implement the GET method. For example:

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    doPost(request, response);
}

Upvotes: 1

Related Questions