我构建了一个Java webstart应用程序,它需要接收Base64参数作为命令行参数。
我正在使用Apache Common-CLI来解析JNLP中的参数。 只有两个参数,其中一个是JSON,而在这个JSON中有一个Base64字符串。
问题是Base64字符串在末尾填充了“=”(等于char /等号),并且解析器无法将字符串识别为参数的一部分,而是尝试将“=”作为键=参数的值分隔符,它抛出以下异常: org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option
有没有办法来逃避这个字符,或者让解析器忽略它?
CLI选项使用以下代码构建:
Option appletBehaviourConfigJSONOption = Option.builder("J") .longOpt("appletBehaviourConfigJSON") .hasArg() .argName("JSON") .desc("JSON config") .build(); clioptions.addOption(appletBehaviourConfigJSONOption); CommandLineParser cliparser = new DefaultParser(); CommandLine cmd = null; try { cmd = cliparser.parse(clioptions, args); } catch (ParseException e) { e.printStackTrace(); }它是从JNLP调用的:
<argument>-appletBehaviourConfigJSON { "appletBehaviourSignatureType": "HASH", "appletBehaviourHashList": [{"id": "1234", "hash": "ZjQzZDM1NTJiYzBhYmZmMDBlNTc0NjIyZDExMDhhM2Y5MmVlOWJjZAo="}, {"id": "5678", "hash": "ZjQzZDM1NTJiYzBhYmZmMDBlNTc0NjIyZDExMDhhM2Y5MmVlOWJjZAo="}], "appletBehaviourCookies": [{"name": "JSESSIONID", "value": "2edee5627c84937f707bdd390b1c"}, {"name": "STICKY", "value": "ASD123213123adsf"}], "appletBehaviourPostURL": "http://example.org", "stampSelection": "WHITE", "setStampAll": true}</argument>当我在两个哈希上将'='更改为'a'时,解析器按预期工作(但该选项现在具有无效的Base64)。
I built a Java webstart application which needs to receive a Base64 parameter as a command line argument.
I'm using Apache Common-CLI to parse the arguments from inside the JNLP. There are just two arguments, one of which is a JSON, and inside this JSON there is a Base64 string.
The problem is that the Base64 string is padded at the end with "=" (equal char/equal sign), and the parser is having trouble recognizing the string as part of the argument, instead trying to evaluate the "=" as a key=value separator for the argument and it's trowing the following exception: org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option
Is there a way to escape this char, or make the parser ignore it?
The CLI option is built using the following code:
Option appletBehaviourConfigJSONOption = Option.builder("J") .longOpt("appletBehaviourConfigJSON") .hasArg() .argName("JSON") .desc("JSON config") .build(); clioptions.addOption(appletBehaviourConfigJSONOption); CommandLineParser cliparser = new DefaultParser(); CommandLine cmd = null; try { cmd = cliparser.parse(clioptions, args); } catch (ParseException e) { e.printStackTrace(); }And it's being called from a JNLP:
<argument>-appletBehaviourConfigJSON { "appletBehaviourSignatureType": "HASH", "appletBehaviourHashList": [{"id": "1234", "hash": "ZjQzZDM1NTJiYzBhYmZmMDBlNTc0NjIyZDExMDhhM2Y5MmVlOWJjZAo="}, {"id": "5678", "hash": "ZjQzZDM1NTJiYzBhYmZmMDBlNTc0NjIyZDExMDhhM2Y5MmVlOWJjZAo="}], "appletBehaviourCookies": [{"name": "JSESSIONID", "value": "2edee5627c84937f707bdd390b1c"}, {"name": "STICKY", "value": "ASD123213123adsf"}], "appletBehaviourPostURL": "http://example.org", "stampSelection": "WHITE", "setStampAll": true}</argument>When I change the '=' to 'a' on both hashes, the parser works as expected (but the option now has an invalid Base64 of course).
最满意答案
看起来commons-cli并不像处理等号那样处理选项名称和值之间的空白。
因此,尝试使用等号而不是空格
-appletBehaviourConfigJSON={...It seems commons-cli does not handle blanks between name and value for options the same way as an equal sign.
Therefore try to use an equal-sign instead of blank as in
-appletBehaviourConfigJSON={...更多推荐
发布评论