[beanutils] Issue with ContextClassLoaderLocal class.
Hi, We are working on migrating a J2EE application from WAS6.1 to JBoss EAP 5.0. For unmarshalling of some custom XML we make use of commons-beanutils-1.8.3 within this application; and in the process, we have defined a custom type converter for one of the XML tags. The registration of this converter happens in one EJB module within our EAR, whereas theactual XML parsing occurs in another EJB module within the same EAR. The org.apache.commons.beanutils.ContextClassLoaderLocal class ties 'global' variables to a classloader instance in a map to ensure data isolation even if the variable is referenced by multiple components running within a container. Here is the relevant code snippet from its get() method: ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); if (contextClassLoader != null) { Object value = valueByClassLoader.get(contextClassLoader); if ((value == null) !valueByClassLoader.containsKey(contextClassLoader)) { value = initialValue(); valueByClassLoader.put(contextClassLoader, value); } return value; } After all that background information, here is the problem: During the converter registration process, a BeanUtilsBean instance is maintained in the ContextClassLoaderLocal map against the classloader of the registration EJB module. During the parsing process, this map is queried to retreive the same BeanUtilsBean instance, using the classloader of the parsing EJB module as the key. In Websphere Application server, the classloader instance for the registration module and the parser module are both same; the correct BeanUtilsBean instance is retreived and processing proceeds as expected. However, in JBoss EAP 5.0, the two classloader instances are different so that the parser module fails to retreive the value from the map. Is this a problem with beanutils' design or an issue with JBoss? Please let me know if I am missing something or if additional details are required. Thanks in advance. N.Rammohan. =-=-= Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
[CLI] Command-line arguments and option with mulitple arguments
Hello. [With official release 1.2] I'd like to call a commmand cmd as follows: $ cmd --foo a --foo b --foo c cmdArg1 cmdArg2 There can be any number of arguments to the option --foo. When I try, the parser (GnuParser) considers the cmdArg1 and cmdArg2 arguments as arguments to the --foo option. This is so even with the stopAtNonOption flag set to true. When I try $ cmd --foo 'a b c' cmdArg1 cmdArg2 I don't get 3 separate option arguments a, b, c, but a single string a b c. Best regards, Gilles - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [CLI] Command-line arguments and option with mulitple arguments
Hi Gilles, I had a similar problem, where I wanted a series of command-line arguments to be like -N1=localhost:8000 -N2=localhost:8001 -N3=localhost:8002 etc. The code below allowed me to get all the -N args values as an enumeration, and is based on some code I found in the documentation. Hope it makes sense and is useful. Regards -- Simon Option node = OptionBuilder.withArgName(property=value).hasArgs(2).withValueSeparator() .withDescription(brokerid=address).create(N); options.addOption(node); CommandLineParser parser = new GnuParser(); CommandLine cli = parser.parse(options,args); Properties props = cli.getOptionProperties(N); for (Enumeration keys = props.keys();keys.hasMoreElements();) { String key = (String) keys.nextElement(); String[] address = props.getProperty(key).split(:); NodeInfo n = new NodeInfo(Integer.parseInt(key),address[0],Integer.parseInt(address[1])); cfg.addNode(n); } On Tue, May 24, 2011 at 2:13 PM, Gilles Sadowski gil...@harfang.homelinux.org wrote: Hello. [With official release 1.2] I'd like to call a commmand cmd as follows: $ cmd --foo a --foo b --foo c cmdArg1 cmdArg2 There can be any number of arguments to the option --foo. When I try, the parser (GnuParser) considers the cmdArg1 and cmdArg2 arguments as arguments to the --foo option. This is so even with the stopAtNonOption flag set to true. When I try $ cmd --foo 'a b c' cmdArg1 cmdArg2 I don't get 3 separate option arguments a, b, c, but a single string a b c. Best regards, Gilles - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [CLI] Command-line arguments and option with mulitple arguments
Hi. I had a similar problem, where I wanted a series of command-line arguments to be like -N1=localhost:8000 -N2=localhost:8001 -N3=localhost:8002 etc. The code below allowed me to get all the -N args values as an enumeration, and is based on some code I found in the documentation. Hope it makes sense and is useful. It makes sense, but it's just a workaround that makes you use dummy properties (i.e. you don't need things like 1, 2, 3 in the code). Moreover, it is error-prone because one could easily and mistakenly write -N1=localhost:8000 -N1=localhost:8001 -N3=localhost:8002 which would probably make one of the arguments disappear silently. I think that the simpler syntax -N localhost:8000 -N localhost:8001 -N localhost:8002 should be allowed, and behave as expected, i.e. IMHO one should be able to retrieve the String[] array with String[] nodes = cli.getOptionValues(N); If it is not possible, shouldn't it be considered a bug? Best, Gilles Regards -- Simon Option node = OptionBuilder.withArgName(property=value).hasArgs(2).withValueSeparator() .withDescription(brokerid=address).create(N); options.addOption(node); CommandLineParser parser = new GnuParser(); CommandLine cli = parser.parse(options,args); Properties props = cli.getOptionProperties(N); for (Enumeration keys = props.keys();keys.hasMoreElements();) { String key = (String) keys.nextElement(); String[] address = props.getProperty(key).split(:); NodeInfo n = new NodeInfo(Integer.parseInt(key),address[0],Integer.parseInt(address[1])); cfg.addNode(n); } On Tue, May 24, 2011 at 2:13 PM, Gilles Sadowski gil...@harfang.homelinux.org wrote: Hello. [With official release 1.2] I'd like to call a commmand cmd as follows: $ cmd --foo a --foo b --foo c cmdArg1 cmdArg2 There can be any number of arguments to the option --foo. When I try, the parser (GnuParser) considers the cmdArg1 and cmdArg2 arguments as arguments to the --foo option. This is so even with the stopAtNonOption flag set to true. When I try $ cmd --foo 'a b c' cmdArg1 cmdArg2 I don't get 3 separate option arguments a, b, c, but a single string a b c. Best regards, Gilles - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [beanutils] Issue with ContextClassLoaderLocal class.
On Tue, May 24, 2011 at 1:55 PM, Rammohan Natarajan rammohan.natara...@tcs.com wrote: Hi, We are working on migrating a J2EE application from WAS6.1 to JBoss EAP 5.0. For unmarshalling of some custom XML we make use of commons-beanutils-1.8.3 within this application; and in the process, we have defined a custom type converter for one of the XML tags. The registration of this converter happens in one EJB module within our EAR, whereas theactual XML parsing occurs in another EJB module within the same EAR. The org.apache.commons.beanutils.ContextClassLoaderLocal class ties 'global' variables to a classloader instance in a map to ensure data isolation even if the variable is referenced by multiple components running within a container. Here is the relevant code snippet from its get() method: ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); if (contextClassLoader != null) { Object value = valueByClassLoader.get(contextClassLoader); if ((value == null) !valueByClassLoader.containsKey(contextClassLoader)) { value = initialValue(); valueByClassLoader.put(contextClassLoader, value); } return value; } After all that background information, here is the problem: During the converter registration process, a BeanUtilsBean instance is maintained in the ContextClassLoaderLocal map against the classloader of the registration EJB module. During the parsing process, this map is queried to retreive the same BeanUtilsBean instance, using the classloader of the parsing EJB module as the key. In Websphere Application server, the classloader instance for the registration module and the parser module are both same; the correct BeanUtilsBean instance is retreived and processing proceeds as expected. However, in JBoss EAP 5.0, the two classloader instances are different so that the parser module fails to retreive the value from the map. Is this a problem with beanutils' design or an issue with JBoss? I think you need to register the converter in the module its used in - i.e. your parsing EJB module Niall Please let me know if I am missing something or if additional details are required. Thanks in advance. N.Rammohan. =-=-= Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [codec] Base 64 problem
I fixed this by using readFileToByteArray not readFileToString byte[] zip_content=FileUtils.readFileToByteArray(new File(zip)); On 24.05.2011 19:11, Victor Sterpu wrote: I'm trying to use org.apache.commons.codec.binary.Base64 to code in base64 a zip file but the result is not as expected. The code used to encode is String content = new String(Base64.encodeBase64(FileUtils.readFileToString(new File(FARMD_16611264_20110524_1102.xml.zip)).getBytes())); The result is Base64 content 1. The result that I must obtain is Base64 content 2 and this second string is generated using this online encoder http://www.opinionatedgeek.com/dotnet/tools/base64encode/. I tryed all day to fix this but I can't figure it out. Please give me an ideea about what is going on. I attached the zip file that I try to encode. Thank you. Base64 content 1:
[io] Tailer returning partial lines returned when EOF before newline
Hi All, We are using org.apache.commons.io.input.Tailer to process log files for insertion into a database. What we are seeing is that occasionally a line fails to process because it is incomplete. In reviewing the code, it appears that Tailer.readLines delegates to java.io.RandomAccessFile.readLine which returns a partial line if EOF is reached. Shouldn't Tailer be providing a guarantee of complete lines? Should we create a bug report for this? FYI, we are using 1.6.0_15 on Linux. Thanks, Frank Grimes
Re: [io] Tailer returning partial lines returned when EOF before newline
On Tue, May 24, 2011 at 6:32 PM, frankgrimes97 frankgrime...@gmail.com wrote: Hi All, We are using org.apache.commons.io.input.Tailer to process log files for insertion into a database. What we are seeing is that occasionally a line fails to process because it is incomplete. In reviewing the code, it appears that Tailer.readLines delegates to java.io.RandomAccessFile.readLine which returns a partial line if EOF is reached. Shouldn't Tailer be providing a guarantee of complete lines? Should we create a bug report for this? FYI, we are using 1.6.0_15 on Linux. Sure https://issues.apache.org/jira/browse/IO Niall Thanks, Frank Grimes - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [CLI] Command-line arguments and option with mulitple arguments
Hi, I only offer the code to illustrate how to deal with repeated options. In this particular case, the repeated option is -N with values 1=localhost:8000, 2=localhost:8001 etc (these values relate to the particular application I'm developing). Simon On Tue, May 24, 2011 at 2:57 PM, Gilles Sadowski gil...@harfang.homelinux.org wrote: Hi. I had a similar problem, where I wanted a series of command-line arguments to be like -N1=localhost:8000 -N2=localhost:8001 -N3=localhost:8002 etc. The code below allowed me to get all the -N args values as an enumeration, and is based on some code I found in the documentation. Hope it makes sense and is useful. It makes sense, but it's just a workaround that makes you use dummy properties (i.e. you don't need things like 1, 2, 3 in the code). Moreover, it is error-prone because one could easily and mistakenly write -N1=localhost:8000 -N1=localhost:8001 -N3=localhost:8002 which would probably make one of the arguments disappear silently. I think that the simpler syntax -N localhost:8000 -N localhost:8001 -N localhost:8002 should be allowed, and behave as expected, i.e. IMHO one should be able to retrieve the String[] array with String[] nodes = cli.getOptionValues(N); If it is not possible, shouldn't it be considered a bug? Best, Gilles Regards -- Simon Option node = OptionBuilder.withArgName(property=value).hasArgs(2).withValueSeparator() .withDescription(brokerid=address).create(N); options.addOption(node); CommandLineParser parser = new GnuParser(); CommandLine cli = parser.parse(options,args); Properties props = cli.getOptionProperties(N); for (Enumeration keys = props.keys();keys.hasMoreElements();) { String key = (String) keys.nextElement(); String[] address = props.getProperty(key).split(:); NodeInfo n = new NodeInfo(Integer.parseInt(key),address[0],Integer.parseInt(address[1])); cfg.addNode(n); } On Tue, May 24, 2011 at 2:13 PM, Gilles Sadowski gil...@harfang.homelinux.org wrote: Hello. [With official release 1.2] I'd like to call a commmand cmd as follows: $ cmd --foo a --foo b --foo c cmdArg1 cmdArg2 There can be any number of arguments to the option --foo. When I try, the parser (GnuParser) considers the cmdArg1 and cmdArg2 arguments as arguments to the --foo option. This is so even with the stopAtNonOption flag set to true. When I try $ cmd --foo 'a b c' cmdArg1 cmdArg2 I don't get 3 separate option arguments a, b, c, but a single string a b c. Best regards, Gilles - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [CLI] Command-line arguments and option with mulitple arguments
[With official release 1.2] I'd like to call a commmand cmd as follows: $ cmd --foo a --foo b --foo c cmdArg1 cmdArg2 There can be any number of arguments to the option --foo. When I try, the parser (GnuParser) considers the cmdArg1 and cmdArg2 arguments as arguments to the --foo option. This is so even with the stopAtNonOption flag set to true. When I try $ cmd --foo 'a b c' cmdArg1 cmdArg2 I don't get 3 separate option arguments a, b, c, but a single string a b c. Also, is it standard practice to allow the syntax $ cmd --foo a b c for an option that can take multiple arguments? [IIRC, getopt_long in C only allows *one* argument.] I think that the above syntax makes parsing more difficult and leads to the problem which I stumbled upon. Could it be possible to solve this problem by adding a post-processing of single-arg options that would further split the argument according to a user-defined separator so that $ cmd --foo 'a b c' cmdArg1 cmdArg2 would effectively end up like if it were a multiple-args option? I.e. something that could be used as ---CUT--- final Option fooOpt = OptionBuilder.withArgName(Any of 'a' or 'b' or 'c') .isRequired() .hasArg() .splitWith(\\s+) // --- New feature. .create(foo); ---CUT--- So that when calling: ---CUT--- final String[] foo = line.getOptionValues(foo); ---CUT--- one would indeed get 3 separate arguments even if they were passed as a single string a b c (or 'a b c') on the command-line. What do you think? Gilles - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [CLI] Command-line arguments and option with mulitple arguments
Hello. I only offer the code to illustrate how to deal with repeated options. In this particular case, the repeated option is -N with values 1=localhost:8000, 2=localhost:8001 etc (these values relate to the particular application I'm developing). I understood that. I'm just stressing that it's not your code that is problematic but that IIUC the CLI is forcing me to call my application like $ cmd --foo 1=a --foo 2=b --foo 3=c which, in my case, is totally unnatural because 1, 2 and 3 have no meaning; they are not properties of anything. Regards, Gilles I had a similar problem, where I wanted a series of command-line arguments to be like -N1=localhost:8000 -N2=localhost:8001 -N3=localhost:8002 etc. The code below allowed me to get all the -N args values as an enumeration, and is based on some code I found in the documentation. Hope it makes sense and is useful. It makes sense, but it's just a workaround that makes you use dummy properties (i.e. you don't need things like 1, 2, 3 in the code). Moreover, it is error-prone because one could easily and mistakenly write -N1=localhost:8000 -N1=localhost:8001 -N3=localhost:8002 which would probably make one of the arguments disappear silently. I think that the simpler syntax -N localhost:8000 -N localhost:8001 -N localhost:8002 should be allowed, and behave as expected, i.e. IMHO one should be able to retrieve the String[] array with String[] nodes = cli.getOptionValues(N); If it is not possible, shouldn't it be considered a bug? Best, Gilles Regards -- Simon Option node = OptionBuilder.withArgName(property=value).hasArgs(2).withValueSeparator() .withDescription(brokerid=address).create(N); options.addOption(node); CommandLineParser parser = new GnuParser(); CommandLine cli = parser.parse(options,args); Properties props = cli.getOptionProperties(N); for (Enumeration keys = props.keys();keys.hasMoreElements();) { String key = (String) keys.nextElement(); String[] address = props.getProperty(key).split(:); NodeInfo n = new NodeInfo(Integer.parseInt(key),address[0],Integer.parseInt(address[1])); cfg.addNode(n); } On Tue, May 24, 2011 at 2:13 PM, Gilles Sadowski gil...@harfang.homelinux.org wrote: Hello. [With official release 1.2] I'd like to call a commmand cmd as follows: $ cmd --foo a --foo b --foo c cmdArg1 cmdArg2 There can be any number of arguments to the option --foo. When I try, the parser (GnuParser) considers the cmdArg1 and cmdArg2 arguments as arguments to the --foo option. This is so even with the stopAtNonOption flag set to true. When I try $ cmd --foo 'a b c' cmdArg1 cmdArg2 I don't get 3 separate option arguments a, b, c, but a single string a b c. - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [io] Tailer returning partial lines returned when EOF before newline
The following is a patch against 2.0.1 in SVN which seems to address the limitation: Index: src/main/java/org/apache/commons/io/input/Tailer.java === --- src/main/java/org/apache/commons/io/input/Tailer.java (revision 1127267) +++ src/main/java/org/apache/commons/io/input/Tailer.java (working copy) @@ -335,12 +335,56 @@ * @throws java.io.IOException if an I/O error occurs. */ private long readLines(RandomAccessFile reader) throws IOException { -String line = reader.readLine(); +String line = readLine(reader); while (line != null) { listener.handle(line); -line = reader.readLine(); +line = readLine(reader); } return reader.getFilePointer(); } +/** + * Copied from RandomAccessFile.readLine() but returns null and resets file pointer on EOF. + * @param reader + * @return + * @throws IOException + */ +private final String readLine(RandomAccessFile reader) throws IOException { + long start = reader.getFilePointer(); + StringBuffer input = new StringBuffer(); + int c = -1; + boolean eol = false; + boolean eof = false; + + while (!eol !eof) { +switch (c = reader.read()) { +case -1: +eof = true; +break; +case '\n': + eol = true; + break; +case '\r': + eol = true; + long cur = reader.getFilePointer(); + if ((reader.read()) != '\n') { + reader.seek(cur); + } + break; +default: + input.append((char)c); + break; +} + } + + if ((c == -1) (input.length() == 0)) { +return null; + } + if (eof) { + reader.seek(start); + return null; + } + + return input.toString(); +} } Index: src/test/java/org/apache/commons/io/input/TailerTest.java === --- src/test/java/org/apache/commons/io/input/TailerTest.java (revision 1127267) +++ src/test/java/org/apache/commons/io/input/TailerTest.java (working copy) @@ -45,6 +45,38 @@ protected void tearDown() throws Exception { FileUtils.deleteDirectory(getTestDirectory()); } + +public void testTailerEof() throws Exception { +// Create start the Tailer +long delay = 50; +final File file = new File(getTestDirectory(), tailer2-test.txt); +createFile(file, 0); +final TestTailerListener listener = new TestTailerListener(); +final Tailer tailer = new Tailer(file, listener, delay, false); +final Thread thread = new Thread(tailer); +thread.start(); + +// Write some lines to the file +FileWriter writer = null; +try { + writeString(file, Line); + +Thread.sleep(delay * 2); +ListString lines = listener.getLines(); +assertEquals(1 line count, 0, lines.size()); + +writeString(file, one\n); +Thread.sleep(delay * 2); +lines = listener.getLines(); + +assertEquals(1 line count, 1, lines.size()); +assertEquals(1 line 1, Line one, lines.get(0)); + +listener.clear(); +} finally { +IOUtils.closeQuietly(writer); +} +} public void testTailer() throws Exception { @@ -142,6 +174,17 @@ IOUtils.closeQuietly(writer); } } + +/** Append a string to a file */ +private void writeString(File file, String string) throws Exception { +FileWriter writer = null; +try { +writer = new FileWriter(file, true); +writer.write(string); +} finally { +IOUtils.closeQuietly(writer); +} +} public void testStopWithNoFile() throws Exception { final File file = new File(getTestDirectory(),nosuchfile); On Tue, May 24, 2011 at 1:32 PM, frankgrimes97 frankgrime...@gmail.comwrote: Hi All, We are using org.apache.commons.io.input.Tailer to process log files for insertion into a database. What we are seeing is that occasionally a line fails to process because it is incomplete. In reviewing the code, it appears that Tailer.readLines delegates to java.io.RandomAccessFile.readLine which returns a partial line if EOF is reached. Shouldn't Tailer be providing a guarantee of complete lines? Should we create a bug report for this? FYI, we are using 1.6.0_15 on Linux. Thanks, Frank Grimes
Re: [lang]: Release date for Common Lang 3.0 (Final Release)
Undefined I'm afraid. There were a few issues on the last RC and, for my part, I'm currently in baby-rearing mode with about 10 minutes of personal time each day. Hen On Mon, May 23, 2011 at 4:19 AM, Rohan Kadam roha...@cybage.com wrote: Hi, Please let me know, when common lang 3.0 will be moved from Beta to Final Release? Thanks, Rohan Kadam. Legal Disclaimer: This electronic message and all contents contain information from Cybage Software Private Limited which may be privileged, confidential, or otherwise protected from disclosure. The information is intended to be for the addressee(s) only. If you are not an addressee, any disclosure, copy, distribution, or use of the contents of this message is strictly prohibited. If you have received this electronic message in error please notify the sender by reply e-mail to and destroy the original message and all copies. Cybage has taken every reasonable precaution to minimize the risk of malicious content in the mail, but is not liable for any damage you may sustain as a result of any malicious content in this e-mail. You should carry out your own malicious content checks before opening the e-mail or attachment. www.cybage.com - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org