struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Markus Fischer (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-4813) NP with TextProvider and wildcardmapping
Date Thu, 13 Jul 2017 08:27:00 GMT

    [ https://issues.apache.org/jira/browse/WW-4813?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16085356#comment-16085356
] 

Markus Fischer commented on WW-4813:
------------------------------------

Yes, I did create the utility classes by hand and put them inside the Lists.

My helper class to get around and resolve the issues around TextProvider looks like this.
Would be nice to see an (improved) official method from Struts ;-)

{code}
package util;

import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.LocaleProviderFactory;
import com.opensymphony.xwork2.LocalizedTextProvider;

public class Texti18n {

    private final Logger LOG = LoggerFactory.getLogger(Texti18n.class);

    /**
     * Returns i18n text messages from the default bundles for utility classes which cannot
     * extend ActionSupport to use i18n support, due to a change in behavior with struts >
2.5.2.
     * Returns the value for a key depending on the locale present. For missing i18n keys
in a given
     * language bundle, the default bundle (English) will be used. If a key is not present
at all, the key will
     * be returned instead of a value.
     */
    public String getText(final String key) {

        final LocalizedTextProvider provider = ActionContext.getContext().getInstance(LocalizedTextProvider.class);
        final String value = provider.findDefaultText(key, getLocale());

        if (value != null) {
            return value;
        }

        return key;
    }

    /**
     * Returns the Locale present in the ActionContext. The Locale.US will be returned as
default,
     * if the Locale is invalid.
     */
    public Locale getLocale() {

        Locale locale = null;

        try {

            final LocaleProviderFactory factory = ActionContext.getContext().getInstance(LocaleProviderFactory.class);
            locale = factory.createLocaleProvider().getLocale();
            // validate locale
            locale.getISO3Language(); // may throw an MissingResourceException
            return locale;
        } catch (final Exception ex) {
            LOG.error("Not a valid locale: " + locale);
        }
        // default language
        return Locale.US;
    }
}
{code}



> NP with TextProvider and wildcardmapping
> ----------------------------------------
>
>                 Key: WW-4813
>                 URL: https://issues.apache.org/jira/browse/WW-4813
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.5.12
>         Environment: Linux / FF / Java 8
>            Reporter: Markus Fischer
>             Fix For: 2.5.x
>
>
> Probably another corner case around TextProvider in connection with wildcard mapping:
> Embeded elements (in URLs, image tags...) in jsp like {{<s:text name="edit"/>}}
throw an NP-Exception.
> {{struts.xml}}
> {code}
>         <action name="**" class="org.package.MyClassDoingNothing">
>           <result name="test">/view/test.jsp</result>
>         </action>
> {code}
> {{test.jsp}} contains an element like this:
> {code}
> <img title="<s:text name="edit"/>" alt="<s:text name="edit"/>" src="editImage.jpg"/>
> {code}
> This will give since 2.5.12 null pointer exception:
> {code}
> ERROR DefaultDispatcherErrorHandler - Exception occurred during processing request: java.lang.NullPointerException
> org.apache.jasper.JasperException: java.lang.NullPointerException
> 	at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:591)
> 	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
> 	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
> 	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
> 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
> 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> 	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
> 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
> 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> 	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:719)
> 	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:465)
> 	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:390)
> 	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:317)
> 	at org.apache.struts2.result.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:173)
> 	at org.apache.struts2.result.StrutsResultSupport.execute(StrutsResultSupport.java:208)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
> 	at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:253)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
> 	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:260)
> 	at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:52)
> 	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.doIntercept(ConversionErrorInterceptor.java:139)
> 	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:134)
> 	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:134)
> 	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:199)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:69)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:115)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:88)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:246)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:99)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:139)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:157)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:174)
> 	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at org.apache.struts2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:123)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:171)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:201)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:193)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at util.AuthenticationInterceptor.intercept(AuthenticationInterceptor.java:88)
> 	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
> 	at org.apache.struts2.factory.StrutsActionProxy.execute(StrutsActionProxy.java:53)
> 	at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:577)
> 	at org.apache.struts2.dispatcher.ExecuteOperations.executeAction(ExecuteOperations.java:81)
> 	at org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:143)
> 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
> 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> 	at customization.RequestFilter.doFilter(RequestFilter.java:57)
> 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
> 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
> 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
> 	at org.apache.catalina.authenticator.AuthenticatorBase.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.invoke(StandardEngineValve.java:88)
> 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
> 	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
> 	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
> 	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
> 	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
> 	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:748)
> Caused by: java.lang.NullPointerException
> 	at com.opensymphony.xwork2.ActionSupport.getTextProvider(ActionSupport.java:278)
> 	at com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:111)
> 	at org.apache.struts2.util.TextProviderHelper.getText(TextProviderHelper.java:76)
> 	at org.apache.struts2.components.Text.end(Text.java:162)
> 	at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
> 	at org.apache.jsp.view.admin_jsp._jspx_meth_s_005ftext_005f23(admin_jsp.java:1441)
> 	at org.apache.jsp.view.admin_jsp._jspx_meth_s_005fiterator_005f0(admin_jsp.java:1331)
> 	at org.apache.jsp.view.admin_jsp._jspx_meth_s_005fif_005f0(admin_jsp.java:1242)
> 	at org.apache.jsp.view.admin_jsp._jspService(admin_jsp.java:269)
> 	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
> 	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
> 	... 88 more
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message