[jira] [Commented] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read

2018-02-20 Thread Aleksandr Mashchenko (JIRA)

[ 
https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=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-4920) Could not create JarEntryRevision for [zip:C:/.... unknown protocol c

2018-02-20 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on WW-4920:


yasserzamani opened a new pull request #211: WW-4920 fix 
java.net.JarURLConnection#parseSpecs
URL: https://github.com/apache/struts/pull/211
 
 
   I inspired such fix from Spring Framework when I found it during my research 
at 
[here](https://github.com/spring-projects/spring-framework/blob/8d3264f680018ccbec6a40253b477283aa3a7e6e/spring-core/src/main/java/org/springframework/util/ResourceUtils.java#L316).
   
   Oracle WebLogic may report jar urls like 
"zip:C:/web-app-lib-path/some-jar.jar" but JDK's JarURLConnection#parseSpecs 
breaks on such urls.
   
   While JDK's JarURLConnection#parseSpecs is private then I had to extend 
URLConnection instead.
   
   Struts keeps a reference of all loaded files regardless of `devMode` or 
`struts.configuration.xml.reload` values (i.e. user may get a warning exception 
if framework was not able to create a revision for loaded file). But Struts 
checks if reload is needed only when `struts.configuration.xml.reload` constant 
is set to
   true (`devMode` still doesn't make sense). So, javadocs of `FileManager` 
interface also fixed to keep it consistent with current implementation.


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


> Could not create JarEntryRevision for [zip:C:/ unknown protocol c
> -
>
> Key: WW-4920
> URL: https://issues.apache.org/jira/browse/WW-4920
> Project: Struts 2
>  Issue Type: Bug
>  Components: Core
>Affects Versions: 2.5.14
> Environment: Weblogic server (Weblogic server version 12.2.1.2.0, JDK 
> v 1.8.0_101)
>Reporter: Yasser Zamani
>Assignee: Yasser Zamani
>Priority: Major
>  Labels: weblogic
> Fix For: 2.5.16
>
>
> This is a follow up for [BUG in 
> struts-2.5.15|http://mail-archives.apache.org/mod_mbox/struts-user/201802.mbox/browser].
> copy of report from user mail list:
> Hi all,
> Testing your upcoming struts-2.5.15, when starting Weblogic server (Weblogic 
> server version
> 12.2.1.2.0, JDK v 1.8.0_101), we see exception below.
> Thanks,
> Liem.
> 
> {code:java}
> 2018-02-14 10:28:37.194 WARN  - Could not create JarEntryRevision for 
> [zip:C:/Oracle/Middleware/Oracle_Home12.2.1.0.0/user_projects/domains/iwa_local_domain/servers/AdminServer/tmp/_WL_user/IWA/zfd81u/war/WEB-INF/lib/struts2-core.jar!/struts-default.xml]!
> java.net.MalformedURLException: unknown protocol: c
> at java.net.URL.(URL.java:600) ~[?:1.8.0_101]
> at java.net.URL.(URL.java:490) ~[?:1.8.0_101]
> at java.net.URL.(URL.java:439) ~[?:1.8.0_101]
> at 
> java.net.JarURLConnection.parseSpecs(JarURLConnection.java:175) ~[?:1.8.0_101]
> at 
> java.net.JarURLConnection.(JarURLConnection.java:158) ~[?:1.8.0_101]
> at 
> com.opensymphony.xwork2.util.fs.StrutsJarURLConnection.(StrutsJarURLConnection.java:44)
> ~[struts2-core.jar:2.5.15]
> at 
> com.opensymphony.xwork2.util.fs.StrutsJarURLConnection.openConnection(StrutsJarURLConnection.java:99)
> ~[struts2-core.jar:2.5.15]
> at 
> com.opensymphony.xwork2.util.fs.JarEntryRevision.build(JarEntryRevision.java:42)
> [struts2-core.jar:2.5.15]
> at 
> com.opensymphony.xwork2.util.fs.DefaultFileManager.monitorFile(DefaultFileManager.java:94)
> [struts2-core.jar:2.5.15]
> at 
> com.opensymphony.xwork2.util.fs.DefaultFileManager.loadFile(DefaultFileManager.java:73)
> [struts2-core.jar:2.5.15]
> at 
> com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles(XmlConfigurationProvider.java:1054)
> [struts2-core.jar:2.5.15]
> at 
> com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadDocuments(XmlConfigurationProvider.java:198)
> [struts2-core.jar:2.5.15]
> at 
> com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.init(XmlConfigurationProvider.java:165)
> [struts2-core.jar:2.5.15]
> at 
> com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:166)
> [struts2-core.jar:2.5.15]
> at 
> com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
> [struts2-core.jar:2.5.15]
> at 
> 

[jira] [Comment Edited] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read

2018-02-20 Thread Michael Hintenaus (JIRA)

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

Michael Hintenaus edited comment on WW-4921 at 2/20/18 9:38 AM:


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...


was (Author: michael hintenaus):
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

2018-02-20 Thread Michael Hintenaus (JIRA)

[ 
https://issues.apache.org/jira/browse/WW-4921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=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-4920) Could not create JarEntryRevision for [zip:C:/.... unknown protocol c

2018-02-20 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on WW-4920:


yasserzamani closed pull request #209: WW-4920 fix 
java.net.JarURLConnection#parseSpecs
URL: https://github.com/apache/struts/pull/209
 
 
   

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/com/opensymphony/xwork2/util/fs/JarEntryRevision.java 
b/core/src/main/java/com/opensymphony/xwork2/util/fs/JarEntryRevision.java
index dc5f0a757..a0fea58c4 100644
--- a/core/src/main/java/com/opensymphony/xwork2/util/fs/JarEntryRevision.java
+++ b/core/src/main/java/com/opensymphony/xwork2/util/fs/JarEntryRevision.java
@@ -37,7 +37,7 @@
 private long lastModified;
 
 public static Revision build(URL fileUrl, FileManager fileManager) {
-JarURLConnection conn = null;
+StrutsJarURLConnection conn = null;
 try {
 conn = StrutsJarURLConnection.openConnection(fileUrl);
 conn.setUseCaches(false);
@@ -70,7 +70,7 @@ private JarEntryRevision(URL jarFileURL, long lastModified) {
 }
 
 public boolean needsReloading() {
-JarURLConnection conn = null;
+StrutsJarURLConnection conn = null;
 long lastLastModified = lastModified;
 try {
 conn = StrutsJarURLConnection.openConnection(jarFileURL);
diff --git 
a/core/src/main/java/com/opensymphony/xwork2/util/fs/StrutsJarURLConnection.java
 
b/core/src/main/java/com/opensymphony/xwork2/util/fs/StrutsJarURLConnection.java
index 8c1b71a79..44a376aaf 100644
--- 
a/core/src/main/java/com/opensymphony/xwork2/util/fs/StrutsJarURLConnection.java
+++ 
b/core/src/main/java/com/opensymphony/xwork2/util/fs/StrutsJarURLConnection.java
@@ -20,34 +20,89 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
 import java.net.JarURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.net.URLDecoder;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.StandardCopyOption;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
+import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 
 /**
- * WW-4901 Decouples from underlying implementation of {@link 
URL#openConnection()}
+ * WW-4901 If was needed, decouples from underlying implementation of {@link 
URL#openConnection()}
  * e.g. from IBM WebSphere 
com.ibm.ws.classloader.Handler$ClassLoaderURLConnection
+ * WW-4920 Also decouples from and fixes {@link 
JarURLConnection#parseSpecs(URL)} if was needed
+ * e.g. from Oracle WebLogic which may report jar urls like 
"zip:C:/web-app-lib-path/some-jar.jar"
+ * but {@link JarURLConnection#parseSpecs(URL)} breaks on such urls
+ * While {@link JarURLConnection#parseSpecs(URL)} is private, then we had to 
extend {@link URLConnection} instead
  * @since 2.5.15
  */
-class StrutsJarURLConnection extends JarURLConnection {
+class StrutsJarURLConnection extends URLConnection {
+private static final String FILE_URL_PREFIX = "file:";
+
+private JarURLConnection jarURLConnection;
+
 private JarFile jarFile;
+private String entryName;
+private URL jarFileURL;
 
-private StrutsJarURLConnection(URL url) throws MalformedURLException {
+private StrutsJarURLConnection(URL url) throws IOException {
 super(url);
+
+URLConnection conn = this.url.openConnection();
+if (conn instanceof JarURLConnection) {//decoupling is not needed?
+jarURLConnection = (JarURLConnection) conn;
+} else {
+try {
+conn.getInputStream().close();
+} catch (IOException ignored) {
+}
+parseSpecs(url);
+}
 }
 
-@Override
-public JarFile getJarFile() throws IOException {
-connect();
-return jarFile;
+/**
+* A fixed copy of {@link JarURLConnection#parseSpecs(URL)}
+*/
+private void parseSpecs(URL url) throws MalformedURLException, 
UnsupportedEncodingException {
+String spec = url.getFile();
+
+int separator = spec.indexOf("!/");
+/*
+ * REMIND: we don't handle nested JAR URLs
+ */
+if (separator == -1) {
+throw new MalformedURLException("no !/ found in url spec:" + spec);
+}
+
+// start of fixing JarURLConnection#parseSpecs(URL) via handling 
MalformedURLException
+String jarFileSpec = spec.substring(0, separator++);
+try {
+jarFileURL = new URL(jarFileSpec);
+