Thanks Dan for this reminder.
Revised it accordingly.

Freeman
On 2012-6-21, at 上午7:42, Daniel Kulp wrote:


Freeman,

I think the Compiler object will need to hold the temp file in and instance variable and delete it in a finally after the javac call completes. Right now, it won't delete till the end. Thus, if you end up create thousands of
DynamicClients, you end up with 1000s of these until the vm exits.

Dan



On Wednesday, June 20, 2012 11:34:21 PM [email protected] wrote:
Author: ffang
Date: Wed Jun 20 23:34:21 2012
New Revision: 1352369

URL: http://svn.apache.org/viewvc?rev=1352369&view=rev
Log:
[CXF-4387]put long classpath in @argfiles to avoid javac command too
long(windows has limitation for command length)

Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ Compiler.java

cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ JaxWs
DynamicClientTest.java

Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ Compiler.java URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/c
ommon/util/Compiler.java?rev=1352369&r1=1352368&r2=1352369&view=diff
= = = = =====================================================================
===== ---
cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Compiler.java
(original) +++
cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ Compiler.java Wed
Jun 20 23:34:21 2012 @@ -150,7 +150,6 @@ public class Compiler {
javacstr = SystemPropertyAction.getProperty("java.home") +
fsep + ".." + fsep + "bin" + fsep + platformjavacname;
        }
-
        list.add(javacstr);
        // End of honoring java.home for used javac

@@ -163,7 +162,9 @@ public class Compiler {
        list.add("-J-Xmx" + maxMemory);

        addArgs(list);
-
+        int classpathIdx = list.indexOf("-classpath");
+        String classpath = list.get(classpathIdx + 1);
+        checkLongClasspath(classpath, list, classpathIdx);
        int idx = list.size();
        list.addAll(Arrays.asList(files));

@@ -273,6 +274,27 @@ public class Compiler {
        }
        return strBuffer.toString().length() > 4096 ? true : false;
    }
+
+    private boolean isLongClasspath(String classpath) {
+        return classpath.length() > 2048 ? true : false;
+    }
+
+ private void checkLongClasspath(String classpath, List<String> list,
int classpathIdx) { +        if (isLongClasspath(classpath)) {
+            PrintWriter out = null;
+            File tmpFile;
+            try {
+                tmpFile =
FileUtils.createTempFile("cxf-compiler-classpath", null); +
out = new PrintWriter(new FileWriter(tmpFile)); +
out.println(classpath);
+                out.flush();
+                out.close();
+                list.set(classpathIdx + 1, "@" + tmpFile);
+            } catch (IOException e) {
+ System.err.print("[ERROR] can't write long classpath to
@argfile"); +            }
+        }
+    }

    public void setEncoding(String string) {
        encoding = string;

Modified:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ JaxWs
DynamicClientTest.java URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/a
pache/cxf/systest/jaxws/JaxWsDynamicClientTest.java? rev=1352369&r1=1352368
&r2=1352369&view=diff
= = = = =====================================================================
===== ---
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ JaxWs
DynamicClientTest.java (original) +++
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ JaxWs
DynamicClientTest.java Wed Jun 20 23:34:21 2012 @@ -105,4 +105,19 @@
public class JaxWsDynamicClientTest exte
        client.invoke("init", list);
    }

+    @Test
+    public void testArgfiles() throws Exception {
+ System.setProperty("org.apache.cxf.common.util.Compiler- fork",
"true"); +        JaxWsDynamicClientFactory dcf =
JaxWsDynamicClientFactory.newInstance(); +        Client client =
dcf.createClient(new URL("http://localhost:"; +
                    + PORT1 + "/ArrayService?wsdl")); +
+        String[] values = new String[] {"foobar", "something" };
+        List<String> list = Arrays.asList(values);
+
+ client.getOutInterceptors().add(new LoggingOutInterceptor());
+        client.getInInterceptors().add(new LoggingInInterceptor());
+        client.invoke("init", list);
+    }
+
}
--
Daniel Kulp
[email protected] - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com

---------------------------------------------
Freeman Fang

FuseSource
Email:[email protected]
Web: fusesource.com
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
http://blog.sina.com.cn/u/1473905042
weibo: http://weibo.com/u/1473905042










Reply via email to