Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4333240
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:21:57+00:00 2026-05-21T10:21:57+00:00

I want to test a server I have deployed on GAE to see if

  • 0

I want to test a server I have deployed on GAE to see if a connection can be made via a HTTP POST request. The end client will run on Android but for now I would like to run a simple test on my laptop.

I send different “action” params as part of the request to the server and based on the action it will look for and handle other params to complete the request. Below is an example of how a command is handled. One param is the action and the other a username. It will in the end return a JSON object with the groups this user is a member of but for now I want to just get the test string “Just a test” back to see everything is working.

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
.
.
.
.
        /* 
         * GET GROUPS
         * 
         * @param action == getGroups
         * @param user == the username of the user making the request
         */
        else if(request.getParameter("action").equals("getGroups")) {   
            /* Query for the User by username */
            User user = queryUser(request.getParameter("user"), pm);

            /* Generate the list of groups this user belongs to */
            ArrayList<Group> groups = null;
            if(user != null) {
                groups = new ArrayList<Group>(user.groups().size());
                for(Group group : user.groups()) 
                    groups.add(group);              
            }

        /* Send response back to the client */
        response.setContentType("text/plain");
        response.getWriter().write("Just a test");
        }

A side question, do I send HTTP POST requests to http://myapp.appspot.com/myapplink
or just to http://myapp.appspot.com/?

I have low experience writing client-server code so I was looking for help and examples of a simple POST request using supplied params and then reading the response back (with in my example the test string) and display it to the terminal.

Here is a sample of a test I was running:

public static void main(String[] args) throws IOException {
        String urlParameters = "action=getGroups&username=homer.simpson";
        String request = "http://myapp.appspot.com/myapplink";

        URL url = new URL(request); 
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();           
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setInstanceFollowRedirects(false); 
        connection.setRequestMethod("POST"); 
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
        connection.setRequestProperty("charset", "utf-8");
        connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
        connection.setUseCaches (false);

        DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
        wr.writeBytes(urlParameters);
        wr.flush();
        wr.close();

        if ( connection.getResponseCode() == HttpURLConnection.HTTP_OK ){
            System.out.println("Posted ok!");

            System.out.println("Res" + connection.getResponseMessage()); //OK read
            System.out.println("Size: "+connection.getContentLength()); // is 0
                System.out.println("RespCode: "+connection.getResponseCode()); // is 200
                System.out.println("RespMsg: "+connection.getResponseMessage()); // is 'OK'
        }

        else {
            System.out.println("Bad post...");          
        } 
    }

When executing however, I get that it’s a “bad post”

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:21:58+00:00Added an answer on May 21, 2026 at 10:21 am

    Usually you will want to send it to a particular link, so you have a way of separating the different servlet classes. Assuming that the doPost() method is inside MyAppLinkServlet class in the package myapp, you will need a web.xml file like the one below to describe how you will respond to the link. BTW, the code is only slightly modified from the GAE/J example at http://code.google.com/appengine/docs/java/gettingstarted/creating.html

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE web-app PUBLIC
     "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
     "http://java.sun.com/dtd/web-app_2_3.dtd">
    
    <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
        <servlet>
            <servlet-name>myapplink</servlet-name>
            <servlet-class>myapp.MyAppLinkServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>myapplink</servlet-name>
            <url-pattern>/myapplink</url-pattern>
        </servlet-mapping>
        <welcome-file-list>
            <welcome-file>index.html</welcome-file>
        </welcome-file-list>
    </web-app>
    

    On the server, try adding the line

    response.setStatus(200);
    

    (which effectively sets the status as “OK”).

    On the client side, try something simple to start, such as:

    import java.io.ByteArrayOutputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    public class TestRequest {
        public static void main(String[] args) throws IOException {
            String urlParameters = "action=getGroups&username=homer.simpson";
            String request = "http://myapp.appspot.com/myapplink";
    
            URL postUrl = new URL (request+"?"+urlParameters);
            System.out.println(readFromUrl(postUrl));
        }
        private static String readFromUrl (URL url) throws IOException {
            FetchOptions opt = FetchOptions.Builder.doNotValidateCertificate(); //depending on how did you install GAE, you might not need this anymore
            HTTPRequest request = new HTTPRequest (url, HTTPMethod.POST, opt);
            URLFetchService service = URLFetchServiceFactory.getURLFetchService();
            HTTPResponse response = service.fetch(request);
            if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
            byte[] content = response.getContent();
                return new String(content);
            } else {
                return null;
            }
        }
    }
    

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application deployed on the Jboss 4.2.1 server. I can access
I have a server from which I can access a webpage. I want to
EDIT: In case you want to test i have deployed the code to this
I want to use prosody or maybe another xmpp server to test my xmpp
I'm writing small XMPP server using boost::asio and I want to unit-test my code.
same as in title? I have a test server with mentioned OS and my
I have started mysql on my test server as a root. I have added
I have a server component that I'm trying to load-test. All connections to the
We have a test server where every developer has their own sandbox. In fact,
I have created the following test server using java: import java.io.*; import java.net.*; class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.