Alexander Garmash
Alexander Garmash

Reputation: 41

Handle HTTP status 500

In my JSP page I use this script:

<script type="text/javascript">
$("#birthDate").datepicker({ dateFormat: 'dd/mm/yy' });
$("#update").click(function (e) {
    var res = true;
    var alertMsg = "";
    $(".required").each(function (index) {
        if (this.value == null || this.value.length == 0) {
            alertMsg += this.name + " can't be empty! \n";
            res = false;
        }
    });

    if (res) {
        var response = $("#updateForm").submit();
        Window.location.reload();
    } else {
        alert(alertMsg);
    }
})


But, requested resource is not available, and I get this exception:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.RuntimeException: org.springframework.remoting.RemoteAccessException: Could not access remote service at [http://some.resource.com]; nested exception is javax.xml.ws.WebServiceException: java.lang.IllegalStateException: Current event not START_ELEMENT or END_ELEMENT
    com.dn.eb.controller.UpdateAccountServlet.throwException(UpdateAccountServlet.java:140)
    com.dn.eb.controller.UpdateAccountServlet.doPost(UpdateAccountServlet.java:122)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

org.springframework.remoting.RemoteAccessException: Could not access remote service at [http://some.resource.com]; nested exception is javax.xml.ws.WebServiceException: java.lang.IllegalStateException: Current event not START_ELEMENT or END_ELEMENT
    org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:510)
    org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.invoke(JaxWsPortClientInterceptor.java:487)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy98.updateAccountRecord(Unknown Source)
    com.dn.eb.controller.UpdateAccountServlet.doPost(UpdateAccountServlet.java:117)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


How can handle this exception, so that on my page displays the error message?

Upvotes: 0

Views: 2005

Answers (2)

AllTooSir
AllTooSir

Reputation: 49382

You need to declare the error page in the web.xml :

<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/error.jsp</location>
</error-page>

Now any Throwable thrown by the app will invoke the error.jsp.Or this way :

<error-page>
    <error-code>500</error-code>
    <location>/error.jsp</location>
</error-page>

All 500 errors will invoke error.jsp.

error.jsp is an error page which can be used to display error messages , declare the page directive in error.jsp:

<%@ page isErrorPage="true"%>

This gives your JSP an handle to the implicit exception object.

Upvotes: 1

Marko Topolnik
Marko Topolnik

Reputation: 200168

You should see the actual response from your remote side. Most probably you'll see some boilerplate HTML saying your resource wasn't found, you are not authorized, or something similar instead of the actual WS response. This can happen when the WS server is hidden behind an Apache front end, which is misconfigured to assume you are a browser.

Upvotes: 0

Related Questions