javaservletsjdbcapache-calcite

Retrieve parameters in a servlet with a JDBC client


I have a JDBC client calling a servlet.

Here's my client :

String query = "select * FROM Table";
int port = 8080;
String user = "user";
String password = "passwd";
String jdbcAvaticaURL = "jdbc:avatica:remote:url=http://localhost:"+port+";authentication=BASIC;serialization=JSON";
Connection connection = DriverManager.getConnection(jdbcAvaticaURL, user, password); // ,info);

executeQuery(connection,query);

connection.close();

And here's my servlet :

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.getParameter("user"); // returns NULL
    Enumeration<String> params = request.getParameterNames(); // Empty Collection
    response.setContentType("application/json;charset=utf-8");
    response.setStatus(HttpServletResponse.SC_OK);
    // DO THINGS
}

is there a way to retrieve the user and password from DriverManager.getConnection(jdbcAvaticaURL, user, password); in the servlet ?

I already tried String auth = request.getHeader("Authorization"); when I put the parameters in the JDBC URL, it's working, I can retrieve the user and the password, but this is not what I want.


Solution

  • It's fine, after trying to get the attributes, parameters, etc... of the request, turns out the credentials were just in the request...

    Doing this in the servlet let me access the user and password used for the connection in the client (after some JSON parsing) :

    String myRequest = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));