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

  • SEARCH
  • Home
  • 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 8954189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:15:53+00:00 2026-06-15T14:15:53+00:00

I am writing a basic android app for sending and receiving messages. I am

  • 0

I am writing a basic android app for sending and receiving messages. I am also writing the server side code using Tomcat 7.0.21. I am currently trying to implement “programmatic web application security” (http://courses.coreservlets.com/Course-Materials/msajsp.html), where client authentication is performed explicitly.

I have now finished this implementation, and it works fine when I send a request using a REST client. However, when I send the request from an Android device/simulator, I get a java.io.FileNotFoundException. When I check the tomcat access logs, it seems tomcat is sending a 400 Bad Request before my Servlet code is even executed, thus producing the exception.

I don’t know whether this problem is client side or server side. Any insight or suggestions on how else to implement this would be greatly appeciated. Thank you.

Tomcat localhost_access_log:

192.168.1.2 - - [05/Dec/2012:12:20:39 +0100] "GET /CA/users/get_contacts?user_id=freespirit HTTP/1.1" 400 -

Servlet classes I extend, which I believe are never executed:

package carter.server.conversations;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sun.misc.BASE64Decoder;
import carter.sqlite.SQLiteUtilities;
import carter.sqlite.conversations.DatabaseHelper;

public class AuthorizationServlet extends HttpsServlet {

    protected static final int SERVLET_EXCEPTION_UNAUTHORIZED = 1;

    @Override
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

        super.doGet(request, response);

        String authorization = request.getHeader("Authorization");
        if(authorization == null){
            System.out.println("CAAuthorizationServlet: Authorization is null. Sending 401.");
            response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        }
        else{
            String base64encodedDetails = authorization.substring(6).trim(); //remove "BASIC " prefix
            BASE64Decoder decoder = new BASE64Decoder();
            String unencodedDetails = new String(decoder.decodeBuffer(base64encodedDetails));
            String[] userDetails = unencodedDetails.split(":");
            //check database for given details
            Connection databaseConnection = SQLiteUtilities.getConnection(Constants.databasePath);
            try{
                String password = DatabaseHelper.getPassword(userDetails[0], databaseConnection);
                if(password.equals(userDetails[1]) == false){
                    //password does not match this user
                    System.out.println("CAAuthorizationServlet: password does not match this user. Sending 401.");
                    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                }
            }
            catch(SQLException e){
                // no such user found in database.
                System.out.println("CAAuthorizationServlet: no such user exists in database. Sending 401.");
                response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
            }
            finally{
                SQLiteUtilities.closeConnection(databaseConnection);
            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

        super.doPost(request, response);
        doGet(request, response);
    }

}


package carter.server.conversations;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HttpsServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        System.out.println("CAHttpsServlet: checking request is secure");
        if(request.isSecure() == false){
            System.out.println("CAHttpsServlet: Request is NOT secure. Sending 400");
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        doGet(request, response);
    }

}
  • 1 1 Answer
  • 0 Views
  • 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-06-15T14:15:54+00:00Added an answer on June 15, 2026 at 2:15 pm

    Um, you are rejecting the request in your own code:

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    
        System.out.println("CAHttpsServlet: checking request is secure");
        if(request.isSecure() == false){
            System.out.println("CAHttpsServlet: Request is NOT secure. Sending 400");
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey--I'm writing a basic Rails app that uses the digg API. I'm trying to
I am writing a basic app that interacts with a webservice I'm writing using
I'm writing an android app that requires that I retrieve the html code of
I am writing a basic http server in C. Handling a simple static .html
I'm writing a basic Django application. For testing / development purposes I'm trying to
I have got Eclipse to generate a Basic android Hello World app, But it
I'm writing an Android App and I'm looking for the fastest (In terms of
I am writing a basic toon shader in OpenGL. I am using MSVC 2008.
To begin with, this is the first Android app I'm writing, and I have
I'm writing a basic writing app in C# and I wanted to have the

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.