You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by albert kao <al...@gmail.com> on 2021/06/17 11:23:50 UTC

How to set up the conditions to test web pages for HTTP status codes 403, 404, 500, 503

I developed a web application with Java (Struts 2) and Web Experience
Toolkit (WET - https://github.com/wet-boew/wet-boew), which is running on
the WebLogic 12c server.
When any one of the HTTP status codes 403, 404, 500, 503 occurs, my web
application will display a corresponding web page.
e.g. When the HTTP status code 503 occurs, my web application will display
the web page 503.html.
How to set up or simulate the conditions to test my web application web
pages for HTTP status codes 403, 404, 500, 503?
i.e. simulate the HTTP status codes 503, etc so as to test my web
application UI to ensure that 503 is handled properly, assuming that the
webserver works properly.

Re: How to set up the conditions to test web pages for HTTP status codes 403, 404, 500, 503

Posted by Lukasz Lenart <lu...@apache.org>.
pt., 18 cze 2021 o 14:11 albert kao <al...@gmail.com> napisał(a):
>
> Following "Exception mapping" at:
> https://struts.apache.org/getting-started/exception-handling.html
>
> Something like:
> public class HttpIOException extends Exception {
> private static final long serialVersionUID = -4261703341L;
>
> public HttpIOException() {
> super("Http IO Exception");
> }
>
> public HttpIOException(String message) {
> super(message);
> }
> }
>
>
>
> public class Register extends ActionSupport {
>     //...
> public void throwHttpIOException(String message) throws HttpIOException {
> throw new HttpIOException(message);
> }
>
> public void throwHttpIO500Exception() throws HttpIOException {
> throw new HttpIOException("HTTP response code: 500");
> }
>
> public void throwHttpIO503Exception() throws HttpIOException {
> throw new HttpIOException("HTTP response code: 503");
> }
> //...
> }
>
>
>
> struts.xml
>         <action name="cause500exception"
> class="org.apache.struts.register.action.Register"
> method="throwHttpIO500Exception">
>         <result>/500.jsp</result>
>         </action>
>         <action name="cause503exception"
> class="org.apache.struts.register.action.Register"
> method="throwHttpIO503Exception">
>         <result>/503.jsp</result>
>         </action>

You must use different exceptions to handle different Response Codes:

<global-results>
    <result name="error503" type="header">
        <param name="status">503</param>
    </result>
    <result name="error500" type="header">
        <param name="status">500</param>
    </result>
</global-results>

<global-exception-mappings>
    <exception-mapping exception="com.demo.503Exception" result="error503"/>
    <exception-mapping exception="com.demo.500Exception" result="error500"/>
</global-exception-mappings>


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to set up the conditions to test web pages for HTTP status codes 403, 404, 500, 503

Posted by albert kao <al...@gmail.com>.
Following "Exception mapping" at:
https://struts.apache.org/getting-started/exception-handling.html

Something like:
public class HttpIOException extends Exception {
private static final long serialVersionUID = -4261703341L;

public HttpIOException() {
super("Http IO Exception");
}

public HttpIOException(String message) {
super(message);
}
}



public class Register extends ActionSupport {
    //...
public void throwHttpIOException(String message) throws HttpIOException {
throw new HttpIOException(message);
}

public void throwHttpIO500Exception() throws HttpIOException {
throw new HttpIOException("HTTP response code: 500");
}

public void throwHttpIO503Exception() throws HttpIOException {
throw new HttpIOException("HTTP response code: 503");
}
//...
}



struts.xml
        <action name="cause500exception"
class="org.apache.struts.register.action.Register"
method="throwHttpIO500Exception">
        <result>/500.jsp</result>
        </action>
        <action name="cause503exception"
class="org.apache.struts.register.action.Register"
method="throwHttpIO503Exception">
        <result>/503.jsp</result>
        </action>

On Thu, Jun 17, 2021 at 9:08 AM Lukasz Lenart <lu...@apache.org>
wrote:

> czw., 17 cze 2021 o 13:24 albert kao <al...@gmail.com> napisał(a):
> >
> > I developed a web application with Java (Struts 2) and Web Experience
> > Toolkit (WET - https://github.com/wet-boew/wet-boew), which is running
> on
> > the WebLogic 12c server.
> > When any one of the HTTP status codes 403, 404, 500, 503 occurs, my web
> > application will display a corresponding web page.
> > e.g. When the HTTP status code 503 occurs, my web application will
> display
> > the web page 503.html.
> > How to set up or simulate the conditions to test my web application web
> > pages for HTTP status codes 403, 404, 500, 503?
> > i.e. simulate the HTTP status codes 503, etc so as to test my web
> > application UI to ensure that 503 is handled properly, assuming that the
> > webserver works properly.
>
> Exception mapping isn't enough?
> https://struts.apache.org/getting-started/exception-handling.html
>
> Or you can always re-implement ExceptionMappingInterceptor and used in
> your custom stack
>
> https://struts.apache.org/maven/struts2-core/apidocs/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.html
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: How to set up the conditions to test web pages for HTTP status codes 403, 404, 500, 503

Posted by Lukasz Lenart <lu...@apache.org>.
czw., 17 cze 2021 o 13:24 albert kao <al...@gmail.com> napisał(a):
>
> I developed a web application with Java (Struts 2) and Web Experience
> Toolkit (WET - https://github.com/wet-boew/wet-boew), which is running on
> the WebLogic 12c server.
> When any one of the HTTP status codes 403, 404, 500, 503 occurs, my web
> application will display a corresponding web page.
> e.g. When the HTTP status code 503 occurs, my web application will display
> the web page 503.html.
> How to set up or simulate the conditions to test my web application web
> pages for HTTP status codes 403, 404, 500, 503?
> i.e. simulate the HTTP status codes 503, etc so as to test my web
> application UI to ensure that 503 is handled properly, assuming that the
> webserver works properly.

Exception mapping isn't enough?
https://struts.apache.org/getting-started/exception-handling.html

Or you can always re-implement ExceptionMappingInterceptor and used in
your custom stack
https://struts.apache.org/maven/struts2-core/apidocs/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.html


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org