Results 1 to 6 of 6
  1. #1
    Maks88 is offline Member
    Join Date
    Jul 2016
    Posts
    4
    Rep Power
    0

    Default Internal server 500 error , while sending post request

    Hello! I am trying to send post request to web servlet, and convert to java object with such algorithm.
    But i got such error, what can be the problem ? Any answer can be help full!

    XML Code:
    <form>
    
                          <label for="first-name">First Name:</label>
                          <input id = "first-name"  type="text"><br>
                          <label for = "last-name">Last Name:</label>
                          <input id = "last-name"  type="text"><br>
                          <label for = "nick_name">Nick Name:</label>
                          <input id = "nick_name"  type="text"><br>
                          <label for="email_">Email:</label>
                          <input id = "email_"  type="email"><br>
                          <label for="password_">Password:</label>
                          <input id="password_"  type="password"><br>
                          <label for = "cust-type">Customer Type:</label>
                          <input id = "cust-type" type="text"><br>
                          <input value="Register" type="button" id = "register-button">
    
                      </form>
    Java Code:
    $("#register-button").click(function () {
    
        var user = {
    
            firstName:$("#first-name").val(),
            lastName:$("#last-name").val(),
            nickName:$("#nick_name").val(),
            email:$("#email_").val(),
            password:$("#password_").val(),
            customerType:$("#cust-type").val()
        }
    
        console.log(user);
    
        var JSONString = JSON.stringify(user);
    
        var JSONObject = JSON.parse(JSONString);
    
        console.log(JSONObject);
    
        var url = "http://localhost:8080/CouponProject/register";
    
        $.ajax({
    
            url:url,
            method:"post",
            data:JSONObject,
            contentType:"application/json",
            error:function (message) {
                console.log(message+" In the error function!")
            },
            success:function (data) {
    
                console.log(data);
    
            },
            headers:
            {
                "Accept":"application/json",
                "Accept-Language":"en",
                "Cache-Control":"max-age=3600"
            }
        });
    
    });
    Java Code:
    @WebServlet(name = "registration servlet", urlPatterns = "/register")
    public class Register extends HttpServlet{
    
        PrintWriter output;
        private final static int EMPTY = 0;
        private static int byteContainer = 0;
        private static int lines = 0;
        private static String charContainer = "";
    
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    
            output = resp.getWriter();
            output.print("The Do Get METHOD");
    
        }
    
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    
            output = resp.getWriter();
    
            ServletInputStream servletInputStream = req.getInputStream();
    
    
            if(servletInputStream.isReady()){
    
                byte [] bytes = new byte[4096];
    
                while((byteContainer = servletInputStream.read()) != -1){
    
                    bytes [lines] = (byte)byteContainer;
                    lines++;
    
                    if((servletInputStream.read()) == -1){
    
                        char [] chars = new char[4096];
    
                        for(int  i = 0, k = 0 ; i < lines; i++, k++){
    
                            chars[i] = (char) bytes [k];
                            charContainer += chars[i];
                        }
                    }
                }
            }
    
            lines = EMPTY;
            output.print(charContainer);

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Internal server 500 error , while sending post request

    My experience with servlets is limited but if you want someone on this forum to help you should include the entire
    error message from the server's perspective. This would probably be in the server logs. If you don't have access
    to the logs you should probably do this with your own, controllable instance of a server.

    I could image all sorts of reasons for an internal server error. One might even be something as mundane as
    a null pointer exception.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Maks88 is offline Member
    Join Date
    Jul 2016
    Posts
    4
    Rep Power
    0

    Default Re: Internal server 500 error , while sending post request

    Quote Originally Posted by Maks88 View Post
    Hello! I am trying to send post request to web servlet, and convert to java object with such algorithm.
    But i got such error, what can be the problem ? Any answer can be help full!

    XML Code:
    <form>
    
                          <label for="first-name">First Name:</label>
                          <input id = "first-name"  type="text"><br>
                          <label for = "last-name">Last Name:</label>
                          <input id = "last-name"  type="text"><br>
                          <label for = "nick_name">Nick Name:</label>
                          <input id = "nick_name"  type="text"><br>
                          <label for="email_">Email:</label>
                          <input id = "email_"  type="email"><br>
                          <label for="password_">Password:</label>
                          <input id="password_"  type="password"><br>
                          <label for = "cust-type">Customer Type:</label>
                          <input id = "cust-type" type="text"><br>
                          <input value="Register" type="button" id = "register-button">
    
                      </form>
    Java Code:
    $("#register-button").click(function () {
    
        var user = {
    
            firstName:$("#first-name").val(),
            lastName:$("#last-name").val(),
            nickName:$("#nick_name").val(),
            email:$("#email_").val(),
            password:$("#password_").val(),
            customerType:$("#cust-type").val()
        }
    
        console.log(user);
    
        var JSONString = JSON.stringify(user);
    
        var JSONObject = JSON.parse(JSONString);
    
        console.log(JSONObject);
    
        var url = "http://localhost:8080/CouponProject/register";
    
        $.ajax({
    
            url:url,
            method:"post",
            data:JSONObject,
            contentType:"application/json",
            error:function (message) {
                console.log(message+" In the error function!")
            },
            success:function (data) {
    
                console.log(data);
    
            },
            headers:
            {
                "Accept":"application/json",
                "Accept-Language":"en",
                "Cache-Control":"max-age=3600"
            }
        });
    
    });
    Java Code:
    @WebServlet(name = "registration servlet", urlPatterns = "/register")
    public class Register extends HttpServlet{
    
        PrintWriter output;
        private final static int EMPTY = 0;
        private static int byteContainer = 0;
        private static int lines = 0;
        private static String charContainer = "";
    
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    
            output = resp.getWriter();
            output.print("The Do Get METHOD");
    
        }
    
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    
            output = resp.getWriter();
    
            ServletInputStream servletInputStream = req.getInputStream();
    
    
            if(servletInputStream.isReady()){
    
                byte [] bytes = new byte[4096];
    
                while((byteContainer = servletInputStream.read()) != -1){
    
                    bytes [lines] = (byte)byteContainer;
                    lines++;
    
                    if((servletInputStream.read()) == -1){
    
                        char [] chars = new char[4096];
    
                        for(int  i = 0, k = 0 ; i < lines; i++, k++){
    
                            chars[i] = (char) bytes [k];
                            charContainer += chars[i];
                        }
                    }
                }
            }
    
            lines = EMPTY;
            output.print(charContainer);
    Adding the Error Message! Sorry!
    Java Code:
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1100)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:687)
    	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    	at java.lang.Thread.run(Thread.java:745)

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Internal server 500 error , while sending post request

    That's missing the exception name, and possibly more of the stack trace.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Maks88 is offline Member
    Join Date
    Jul 2016
    Posts
    4
    Rep Power
    0

    Default Re: Internal server 500 error , while sending post request

    Quote Originally Posted by Tolls View Post
    That's missing the exception name, and possibly more of the stack trace.
    Found more in the logs sorry again!

    24-Sep-2016 11:45:27.632 SEVERE [http-nio-8080-exec-6] org.apache.catalina.core.StandardWrapperValve.invo ke Servlet.service() for servlet [registration servlet] in context with path [/CouponProject] threw exception java.lang.IllegalStateException: Not available in non blocking mode at org.apache.catalina.connector.InputBuffer.isReady( InputBuffer.java:297) at org.apache.catalina.connector.CoyoteInputStream.is Ready(CoyoteInputStream.java:242) at coupon.registration.Register.doPost(Register.java: 37) at javax.servlet.http.HttpServlet.service(HttpServlet .java:648) at javax.servlet.http.HttpServlet.service(HttpServlet .java:729) at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:292) at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:207) at org.apache.tomcat.websocket.server.WsFilter.doFilt er(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:207) at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:212) at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve. invoke(AbstractAccessLogValve.java:616) at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:528) at org.apache.coyote.http11.AbstractHttp11Processor.p rocess(AbstractHttp11Processor.java:1100) at org.apache.coyote.AbstractProtocol$AbstractConnect ionHandler.process(AbstractProtocol.java:687) at org.apache.tomcat.util.net.NioEndpoint$SocketProce ssor.doRun(NioEndpoint.java:1520) at org.apache.tomcat.util.net.NioEndpoint$SocketProce ssor.run(NioEndpoint.java:1476) at java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$Wrapping Runnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Internal server 500 error , while sending post request

    You could have tidied it up a bit.
    Anyway, this is the relevant portion:

    java.lang.IllegalStateException: Not available in non blocking mode
    at org.apache.catalina.connector.InputBuffer.isReady( InputBuffer.java:297)
    at org.apache.catalina.connector.CoyoteInputStream.is Ready(CoyoteInputStream.java:242)
    at coupon.registration.Register.doPost(Register.java: 37)

    So, why are you checking isReady?
    That seems to be the immediate cause.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 02-16-2015, 07:29 AM
  2. Replies: 1
    Last Post: 12-15-2014, 11:12 PM
  3. Sending SOAP request server
    By lemdan in forum Java Servlet
    Replies: 0
    Last Post: 10-10-2012, 02:46 PM
  4. AJAX - Sending a request to a server
    By gilbertsavier in forum XML
    Replies: 0
    Last Post: 07-17-2009, 07:35 AM
  5. Replies: 1
    Last Post: 07-14-2007, 05:15 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •