0

I have a client_servlet through which i have to make a a connection to server_servlet .This code is working fine when used by a single user, but it is giving an HTTP status 500 error when tried to use by 2 users .

The following code is in the client_servlet the url of the server_servlet is given in the servletURL . Please help to make this work for more than one user

if (!( request.getParameter("RFQ") == null )) {
    String result = "";
    try {
        String servletURL = http://localhost:8080/Trapii/retservlet_server" ;   
        String query =   "firstCurr=" + ls_firstCurr
            + "&secondCurr=" + ls_secondCurr
            + "&tenor=" + ls_tenor
            + "&direction="+ ls_direction
            + "&firstCurrAmt=" + ls_firstCurrAmt
            + "&rate=" + ls_price
            + "&trapi=" + ls_msg
            + "&userid=" + ls_userid
            + "&sessionid=" + ls_sessionid
            + "&RFQ=RFQ";
        System.out.println("query string is : " + query);
        String charEncoding = "iso-8859-1";
        URL sendUrl = new URL(servletURL);
        System.out.println("This is RFQ");
        //HttpURLConnection conn = (HttpURLConnection) sendUrl.openConnection();
        HttpURLConnection conn = (HttpURLConnection)sendUrl.openConnection();
        conn.setDoOutput(true);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Length", Integer.toString(query.length()));
        conn.getOutputStream().write(query.getBytes(charEncoding));
        System.out.println("Going to get the InputStream Object");
        InputStream inputStream = conn.getInputStream();
        BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
        System.out.println("Reading the ouput received from servlet");
        result = in.readLine();
    } 
    catch (Exception e1) {
        System.out.println("RFQ Error");
        e1.printStackTrace();
    }
    ls_msg = result;
    ls_sessionid = session.getId();
}
DanielBarbarian
  • 4,255
  • 12
  • 30
  • 38
LeDerp
  • 453
  • 1
  • 9
  • 23
  • Where are you getting the 500 status? In the client servlet or the server servlet. Also The 500 status is often the result of an exception. Check your logs for exceptions. – DanielBarbarian Jun 19 '14 at 09:21
  • Does your servlet supports POST method? – Ankit Jun 19 '14 at 09:27
  • @DanielBarbarian yes there is a null pointer exception in the servlet_server. What can i do now? – LeDerp Jun 19 '14 at 10:05
  • @user3752436: I think you should really solve that NPE :). Debug your code and fix the issue. Simple it is :). – Ankit Jun 19 '14 at 10:29
  • @user3752436: Look at your stack trace for the NPE and see where it occurs. If you still can't figure out why, you can edit the question to include the stacktrace as well and also the code where it occurs (if that is not already there). – DanielBarbarian Jun 19 '14 at 11:22
  • @Ankit it's working fine for single user, it's not working for more than one user. for 2 users it's giving npe exception . – LeDerp Jun 19 '14 at 11:24
  • See [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Jesper Jun 19 '14 at 11:32

0 Answers0