-1

Java 6
jboss-as-7.1.1.Final

I need to copy and paste a file. Using org.apache.commons.io.FileUtils and I tried with the following code,

If I invoke sync() from a jsp, getting

... java.lang.StackOverflowError at org.apache.catalina.core.ApplicationHttpRequest.removeAttribute(ApplicationHttpRequest.java:280) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.ApplicationHttpRequest.removeAttribute(ApplicationHttpRequest.java:280) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.ApplicationHttpRequest.removeAttribute(ApplicationHttpRequest.java:280) [jbossweb-7.0.13.Final.jar:]

private void sync() {
    try {
        FileUtils.copyFile(new File("C:/jboss-as-7.1.1.Final/standalone/deployments/admin.war/xml/news_src/compose.xml"), 
        new File("C:/jboss-as-7.1.1.Final/standalone/deployments/admin.war/xml/news_dest/compose.xml"));            
    } 
    catch (IOException e) {
        e.printStackTrace();
    }
}

If I run the same code as a standalone java application, the file gets copied and pasted to destination

public static void main(String s[]) {
    try {
        FileUtils.copyFile(new File("C:/jboss-as-7.1.1.Final/standalone/deployments/admin.war/xml/news_src/compose.xml"), 
        new File("C:/jboss-as-7.1.1.Final/standalone/deployments/admin.war/xml/news_dest/compose.xml"));        
    } 
    catch (IOException e) {
        e.printStackTrace();
    }
}

Why am I getting the StackOverflowError when the code invoked in a JBoss environment whereas executing the same code as java application runs successfully? Thanks.

Pseudo Sudo
  • 1,402
  • 3
  • 16
  • 34
SyAu
  • 1,651
  • 7
  • 25
  • 47
  • 2
    Can you clarify why you think the StackOverflowError has to do with the file-copying logic in your `sync()` method? (I ask because, judging from the bit of stacktrace you've posted, it looks like it *doesn't*.) – ruakh Sep 12 '16 at 04:55
  • 2
    The stacktrace shows that the error is in a totally different place. It has nothing to do with the file copy. – Andreas Sep 12 '16 at 04:55
  • @ruakh and Andreas Thanks for your comments, please see my answer post. – SyAu Sep 12 '16 at 11:54

2 Answers2

3

I'm guessing that since you're copying your file into the WAR that has the program that is copying it, it then syncs. Which then copies the file into the WAR which is copying it, and then syncs. Which then copies the file into the WAR which is copying it, and then syncs....

JBoss is smart enough to try to reload code that's changed in the WAR file by redeploying automatically. When you're running as a standalone Java application, there isn't a container, so it doesn't redeploy.

Brad
  • 2,261
  • 3
  • 22
  • 32
  • I have my web app in an exploded format (folder - admin.war), I don't have any war file under deployments folder. – SyAu Sep 12 '16 at 06:33
0

I found a fix for this problem. The action class configuration in my framework, which is an in house built framework, was not correct, thus resulting in action class being called in a loop. I updated that setting, thus preventing action class execution in a loop.

This SO post also guided me.

Community
  • 1
  • 1
SyAu
  • 1,651
  • 7
  • 25
  • 47