[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16378410#comment-16378410 ] ASF subversion and git services commented on WW-4921: - Commit 54fa3f7b0474f415575e7416b43f3bf7f241a13a in struts's branch refs/heads/master from Lukasz Lenart [ https://gitbox.apache.org/repos/asf?p=struts.git;h=54fa3f7 ] Merge pull request #214 from yasserzamani/WW-4921 WW-4921 initialize session like WW-3442 > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Assignee: Yasser Zamani >Priority: Major > Labels: test > Fix For: 2.5.16 > > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16378406#comment-16378406 ] ASF subversion and git services commented on WW-4921: - Commit b806c11ea57b66d8751e0a1442c951235afd4929 in struts's branch refs/heads/master from [~yasser.zamani] [ https://gitbox.apache.org/repos/asf?p=struts.git;h=b806c11 ] initialize session See also WW-4921 > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Assignee: Yasser Zamani >Priority: Major > Labels: test > Fix For: 2.5.16 > > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16378405#comment-16378405 ] ASF GitHub Bot commented on WW-4921: lukaszlenart closed pull request #214: WW-4921 initialize session like WW-3442 URL: https://github.com/apache/struts/pull/214 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java b/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java index b39349d60..9a917e3cf 100644 --- a/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java +++ b/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java @@ -37,6 +37,7 @@ import org.springframework.core.io.DefaultResourceLoader; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.mock.web.MockHttpSession; import org.springframework.mock.web.MockPageContext; import org.springframework.mock.web.MockServletContext; @@ -155,10 +156,7 @@ protected ActionProxy getActionProxy(String uri) { ActionProxy proxy = config.getContainer().getInstance(ActionProxyFactory.class).createActionProxy( namespace, name, method, new HashMap(), true, false); -ActionContext invocationContext = proxy.getInvocation().getInvocationContext(); - invocationContext.setParameters(HttpParameters.create(request.getParameterMap()).build()); -// set the action context to the one used by the proxy -ActionContext.setContext(invocationContext); +initActionContext(proxy.getInvocation().getInvocationContext()); // this is normally done in onSetUp(), but we are using Struts internal // objects (proxy and action invocation) @@ -170,6 +168,20 @@ protected ActionProxy getActionProxy(String uri) { return proxy; } +protected void initActionContext(ActionContext actionContext) { + actionContext.setParameters(HttpParameters.create(request.getParameterMap()).build()); +initSession(actionContext); +// set the action context to the one used by the proxy +ActionContext.setContext(actionContext); +} + +protected void initSession(ActionContext actionContext) { +if (actionContext.getSession() == null) { +actionContext.setSession(new HashMap()); +request.setSession(new MockHttpSession(servletContext)); +} +} + /** * Finds an ActionMapping for a given request */ diff --git a/plugins/junit/src/test/java/org/apache/struts2/StrutsJUnit4TestCaseTest.java b/plugins/junit/src/test/java/org/apache/struts2/StrutsJUnit4TestCaseTest.java index d3e0d15d3..8bc691522 100644 --- a/plugins/junit/src/test/java/org/apache/struts2/StrutsJUnit4TestCaseTest.java +++ b/plugins/junit/src/test/java/org/apache/struts2/StrutsJUnit4TestCaseTest.java @@ -18,6 +18,7 @@ */ package org.apache.struts2; +import com.opensymphony.xwork2.ActionProxy; import org.junit.Assert; import org.junit.Test; @@ -33,6 +34,13 @@ public void testExecuteActionAgainstCustomStrutsConfigFile() throws Exception { Assert.assertEquals("Test-2", output); } +@Test +public void testSessionInitialized() throws Exception { +ActionProxy proxy = getActionProxy("/test/testAction-2.action"); +Assert.assertNotNull("invocation session should being initialized", +proxy.getInvocation().getInvocationContext().getSession()); +} + @Override protected String getConfigPath() { return "struts-test.xml"; This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Assignee: Yasser Zamani >Priority: Major > Labels: test > Fix For: 2.5.16 > > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this w
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16378409#comment-16378409 ] ASF subversion and git services commented on WW-4921: - Commit 54fa3f7b0474f415575e7416b43f3bf7f241a13a in struts's branch refs/heads/master from Lukasz Lenart [ https://gitbox.apache.org/repos/asf?p=struts.git;h=54fa3f7 ] Merge pull request #214 from yasserzamani/WW-4921 WW-4921 initialize session like WW-3442 > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Assignee: Yasser Zamani >Priority: Major > Labels: test > Fix For: 2.5.16 > > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16378407#comment-16378407 ] ASF subversion and git services commented on WW-4921: - Commit a448b8a91b68dfcca43c9716eb02714f188995a2 in struts's branch refs/heads/master from [~yasser.zamani] [ https://gitbox.apache.org/repos/asf?p=struts.git;h=a448b8a ] make newly added methods protected to allow users to override them See also WW-4921, WW-3442 > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Assignee: Yasser Zamani >Priority: Major > Labels: test > Fix For: 2.5.16 > > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16378309#comment-16378309 ] ASF GitHub Bot commented on WW-4921: yasserzamani opened a new pull request #214: WW-4921 initialize session like WW-3442 URL: https://github.com/apache/struts/pull/214 This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Assignee: Yasser Zamani >Priority: Major > Labels: test > Fix For: 2.5.16 > > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16374743#comment-16374743 ] ASF GitHub Bot commented on WW-4921: yasserzamani closed pull request #213: WW-4921 revert I18nInterceptor logic from WW-4741 changes… URL: https://github.com/apache/struts/pull/213 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java index 682bbe6d7..8a9e7bafc 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java @@ -282,14 +282,15 @@ public Locale find() { @Override public Locale store(ActionInvocation invocation, Locale locale) { HttpSession session = ServletActionContext.getRequest().getSession(false); +Map invocationSession = invocation.getInvocationContext().getSession(); -if (session != null) { +if (session != null && invocationSession != null) { String sessionId = session.getId(); synchronized (sessionId.intern()) { - invocation.getInvocationContext().getSession().put(attributeName, locale); +invocationSession.put(attributeName, locale); } } else { -LOG.debug("session creation avoided as it doesn't exist already"); +LOG.debug("locale did not stored because either request or invocation does not have session"); } return locale; @@ -301,11 +302,12 @@ public Locale read(ActionInvocation invocation) { LOG.debug("Checks session for saved locale"); HttpSession session = ServletActionContext.getRequest().getSession(false); +Map invocationSession = invocation.getInvocationContext().getSession(); -if (session != null) { +if (session != null && invocationSession != null) { String sessionId = session.getId(); synchronized (sessionId.intern()) { -Object sessionLocale = invocation.getInvocationContext().getSession().get(attributeName); +Object sessionLocale = invocationSession.get(attributeName); if (sessionLocale != null && sessionLocale instanceof Locale) { locale = (Locale) sessionLocale; LOG.debug("Applied session locale: {}", locale); diff --git a/core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java index fcc0dd11b..171008b6b 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java @@ -83,6 +83,37 @@ public void testNoSessionButLocale() throws Exception { assertNull("should not be stored here", session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); } +public void testNoInvocationSessionNoLocale() throws Exception { +mai.getInvocationContext().setSession(null); +try { +interceptor.intercept(mai); +assertTrue(true); +} catch (Exception ignore) { +fail("Shouldn't throw any exception!"); +} + +assertFalse("should have been removed", + mai.getInvocationContext().getParameters().get(I18nInterceptor.DEFAULT_PARAMETER).isDefined()); +assertNull("should not be created", mai.getInvocationContext().getSession()); +assertNull("should not be stored here", session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); +} + +public void testNoInvocationSessionButLocale() throws Exception { +prepare(I18nInterceptor.DEFAULT_PARAMETER, "da_DK"); //prevents shouldStore to being false +mai.getInvocationContext().setSession(null); +try { +interceptor.intercept(mai); +assertTrue(true); +} catch (Exception ignore) { +fail("Shouldn't throw any exception!"); +} + +assertFalse("should have been removed", + mai.getInvocationContext().getParameters().get(I18nInterceptor.DEFAULT_PARAMETER).isDefined()); +assertNull("should not be created", mai.getInvocationContext().getSession()); +assertNull("should not be stored here", session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); +} + public void testDefaultLocale() throws Exception {
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16373258#comment-16373258 ] Yasser Zamani commented on WW-4921: --- I analysed this issue and to sum up, I saw WW-3442 adds session creation to StrutsTestCase but I'm not sure if it's good idea to also follow such policy for StrutsJUnit4TestCase (?) because what should we do then when a user wants to run it's test with no invocation session (on) ... so I decided to revert back it's logic to previous stable logic from WW-4741 while keeping it fixed. > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Priority: Major > Labels: test > Fix For: 2.5.16 > > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16373248#comment-16373248 ] ASF GitHub Bot commented on WW-4921: yasserzamani opened a new pull request #213: WW-4921 revert I18nInterceptor logic from WW-4741 changes… URL: https://github.com/apache/struts/pull/213 … to it's previous stable logic WW-4741 changes logic which breaks WW-4921. This commit if applied, will revert the logic to previous stable state but keeps WW-4741 fixed and also will fix WW-4921. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Priority: Major > Labels: test > Fix For: 2.5.16 > > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16372464#comment-16372464 ] Michael Hintenaus commented on WW-4921: --- No session is no alternative for me. Setting a Map is my workaround (see below). But as mentioned by [~yasser.zamani] : StrutsTestCase has a {{initActionContext}} Method (which set the map automatically), StrutsJUnit4TestCase has not such a method - why? {code:java} @Override protected ActionProxy getActionProxy(final String uri) { final ActionProxy proxy = super.getActionProxy(uri); final ActionContext context = proxy.getInvocation().getInvocationContext(); if (context.getSession() == null) { context.setSession(new SessionMap<>(request)); } return proxy; }{code} > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Priority: Major > Labels: test > Fix For: 2.5.16 > > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16371900#comment-16371900 ] Aleksandr Mashchenko commented on WW-4921: -- With the {{request.getSession(true);}} you're creating mock session which is not set in the invocation context. Remove {{request.getSession(true);}} or set new hashmap into invocation context. > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Priority: Major > Labels: test > Fix For: 2.5.16 > > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16371077#comment-16371077 ] Michael Hintenaus commented on WW-4921: --- with Struts 2.5.14.1 it works fine, with Struts 2.5.15 the test will fail {code:java} @Action(results = @Result(location="http://struts.apache.org";, type="redirect")) public class MyAction extends ActionSupport { } {code} {code:java} public class MyTest extends StrutsJUnit4TestCase { @Test public void test() throws Exception { request.getSession(true); final ActionProxy proxy = getActionProxy("/my-action.action"); final ActionInvocation invocation = proxy.getInvocation(); invocation.invoke(); assertTrue(invocation.isExecuted()); assertEquals(MyAction.SUCCESS, invocation.getResultCode()); } }{code} {code:java} java.lang.NullPointerException at org.apache.struts2.interceptor.I18nInterceptor$SessionLocaleHandler.read(I18nInterceptor.java:308) at org.apache.struts2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:107) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:167) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.silbergrau.cal6.MyTest.test(MyTest.java:20){code} > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Priority: Major > Labels: test > Fix For: 2.5.16 > > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16370386#comment-16370386 ] Aleksandr Mashchenko commented on WW-4921: -- [~Michael Hintenaus] Please add which Struts version you are using along with the whole error stacktrace and your test code. Simple test is working fine for me. > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Priority: Major > Labels: test > Fix For: 2.5.16 > > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16369851#comment-16369851 ] Michael Hintenaus commented on WW-4921: --- calling execute() of ActionProxy, also calls invoke() and I will also get a NPE. Calling executeAction will solve the problem, but I want to assert the return code of the action... > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Priority: Major > Labels: test > Fix For: 2.5.16 > > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16369447#comment-16369447 ] Aleksandr Mashchenko commented on WW-4921: -- [~Michael Hintenaus] Can you show more code of your test. Any reason why do you use {{invoke()}}? There is {{execute()}} in {{ActionProxy}} and {{executeAction}} in test case. > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Priority: Major > Labels: test > Fix For: 2.5.16 > > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16369125#comment-16369125 ] Michael Hintenaus commented on WW-4921: --- No, I didn't consider using the old fashion StrutsTestCase, I wan't to use JUnit4 features... > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Priority: Major > Labels: test > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read
[ https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16369120#comment-16369120 ] Yasser Zamani commented on WW-4921: --- I see {{org.apache.struts2.StrutsTestCase}} inits session. Did you consider using it instead? I see {{org.apache.struts2.StrutsTestCase#getActionProxy}} and {{org.apache.struts2.StrutsJUnit4TestCase #getActionProxy}} are exactly same except {{StrutsTestCase}} has been refactored lines #158-161 into a seperate function name {{initActionContext}} and also has been added creation of session. Currently I don't know if it's a design decision? or {{StrutsJUnit4TestCase}} should be changed same as {{StrutsTestCase}}? > NPE in I18nInterceptor$SessionLocaleHandler.read > > > Key: WW-4921 > URL: https://issues.apache.org/jira/browse/WW-4921 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors >Reporter: Michael Hintenaus >Priority: Major > Labels: test > > Calling > {code:java} > getActionProxy("/index.action").getInvocation().invoke(){code} > in a TestCase which extends from StrutsJUnit4TestCase will lead to a > NullPointerException. > Overriding getActionProxy like this will help: > {code:java} > @Override > protected ActionProxy getActionProxy(final String uri) { > final ActionProxy proxy = super.getActionProxy(uri); > final ActionContext context = > proxy.getInvocation().getInvocationContext(); > if (context.getSession() == null) { > context.setSession(new SessionMap<>(request)); > } > return proxy; > }{code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)