【发布时间】:2019-06-23 14:30:13
【问题描述】:
我正在尝试解析来自我的 Python Web 服务器的其余响应。我成功获取了 JSON 内容的字符串。为了简化问题,我现在只是尝试解析如下所示的测试字符串。
我的 python 测试用例可以很好地解析字符串,但这是针对 java 插件的,所以我试图将它翻译成 java。
我复制了几份看似相同的例子。
String inputJSONs = "{\"connections\":[{\"num\":\"1\"},{\"num\":\"2\"}]}";
System.out.println("testing");
JSONObject jsono = new JSONObject(inputJSONs);
System.out.println("parsed json");
JSONArray arr = jsono.getJSONArray("connections");
System.out.println("have arr");
System.out.println(arr);
错误 o.a.g.rest.RESTExceptionMapper - 意外的内部错误:org/json/JSONObject
我认为插件框架(apache guacamole)可能隐藏了一些更详细的错误,但我不能确定。
添加完整示例(尽可能多地删除我可以重现的其他内容)
package org.apache.guacamole.auth;
import java.util.HashMap;
import java.util.Map;
import java.lang.StringBuilder;
import org.json.JSONObject;
import org.json.JSONArray;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleServerException;
import org.apache.guacamole.environment.Environment;
import org.apache.guacamole.environment.LocalEnvironment;
import org.apache.guacamole.net.auth.simple.SimpleAuthenticationProvider;
import org.apache.guacamole.net.auth.Credentials;
import org.apache.guacamole.protocol.GuacamoleConfiguration;
public class RestAuthenticationProvider extends SimpleAuthenticationProvider {
private final Environment environment;
private Logger logger = LoggerFactory.getLogger(RestAuthenticationProvider.class.getClass());
public RestAuthenticationProvider() throws GuacamoleException{
environment = new LocalEnvironment();
}
@Override
public String getIdentifier() {
logger.info("====Get Identifier====");
return "Rest API";
}
@Override
public Map<String, GuacamoleConfiguration>
getAuthorizedConfigurations(Credentials credentials)
throws GuacamoleException {
if (credentials.getUsername() == null ){
return null;
}
String inputJSONs = "{\"connections\":[{\"num\":\"1\"},{\"num\":\"2\"}]}";
System.out.println("testing 2");
System.out.println(inputJSONs);
JSONObject jsono = new JSONObject(inputJSONs);
System.out.println("parsed json");
JSONArray arr = jsono.getJSONArray("connections");
System.out.println("have arr");
System.out.println(arr);
return null;
}
}
登录服务器后立即输出以下内容
testing 2
{"connections":[{"num":"1"},{"num":"2"}]}
12:00:00.129 [http-nio-8080-exec-8] ERROR o.a.g.rest.RESTExceptionMapper - Unexpected internal error: org/json/JSONObject
【问题讨论】:
-
我无法重现您的问题,您共享的代码可以正常工作。您能否分享Minimal, Complete, and Verifiable example,以便我们重现您的问题?
-
嗯,我把我的代码分解成它自己的测试类,你是对的,它确实工作得很好。所以这意味着它必须是 1) 与插件系统有关,2) 与我的较大代码有关。我将简化我的插件类并发布一个更完整的示例。
-
在 Guacamole 特定论坛的帮助下,我能够缩小范围。最后的解决方法是让 maven 构建一个内置依赖项的 fat jar。