Asterisk-Java 无法加载属性文件

Asterisk-Java Unable to load Properties file

我正在开发一个非常简单的 Asterisk-Java 基于 IVR 的程序,它会问候呼叫者,从 Web 服务中检索一些信息,将检索到的数据读给呼叫者,最后挂断。

我遵循的步骤:

添加了在 extensions_custom.conf 上输入的以下行:

exten => 1000,n,Agi(agi://192.168.0.8/ivryobi.agi)

在 C:\Project\target\classes\

中创建了以下文件结构
Runnable.java
IvrYobi.java
Runnable.class
IvrYobi.class
fastagi-mapping.properties

在 fastagi-mapping.properties 我有:

ivryobi.agi = main.IvrYobi

IvrYoby 的内容是:

public class IvrYobi extends BaseAgiScript {

    public void service(AgiRequest request, AgiChannel channel) throws AgiException {
    String callerMsisdn = request.getCallerIdNumber();
}

正常工作时

运行在控制台执行以下命令

C:\Project\target\classes>java -cp asterisk-java.jar;commons-lang3-3.10.jar;commons-logging-1.2.jar;httpclient-4.5.12.jar;httpcore-4.4.13.jar;mysql-connector-java-8.0.20.jar;. org.asteriskjava.fastagi.DefaultAgiServer

正如您在以下控制台输出中看到的那样,运行完美

jun 30, 2020 6:09:04 PM org.asteriskjava.fastagi.DefaultAgiServer startup INFORMACIËN: Listening on *:4573. jun 30, 2020 6:09:09 PM org.asteriskjava.fastagi.AbstractAgiServer getPool INFORMACIËN: Thread pool started. jun 30, 2020 6:09:09 PM org.asteriskjava.fastagi.ResourceBundleMappingStrategy loadResourceBundle INFORMACIËN: Added mapping for 'ivryobi.agi' to class IvrYobi ...

出现问题时

当我 运行 完全相同的代码,但我使用 Runnable.java

安装控制台

这里是Runnable.java的内容:

DefaultAgiServer server = new DefaultAgiServer();

    public MyRunnable() {

        ClassNameMappingStrategy strategy = new ClassNameMappingStrategy(false);

        server.setMappingStrategy(strategy);

    }

    public void run() {

        try {

            server.startup();

        } catch (IllegalStateException | IOException e) {

            e.printStackTrace();

            server.shutdown();

        }

    }

    public void stop() {
        server.shutdown();
    }

我们可以在 Eclipse 的控制台上观察到以下错误:

0 [main] DEBUG org.asteriskjava.fastagi.DefaultAgiServer - Using channelFactory org.asteriskjava.fastagi.internal.DefaultAgiChannelFactory 9 [main] INFO org.asteriskjava.fastagi.DefaultAgiServer - Listening on *:4573. 4806 [main] DEBUG org.asteriskjava.fastagi.DefaultAgiServer - Received connection from /192.168.0.254 4810 [main] INFO org.asteriskjava.fastagi.DefaultAgiServer - Thread pool started. 4849 [AJ DaemonPool-1.1] DEBUG org.asteriskjava.fastagi.ClassNameMappingStrategy - Unable to create AgiScript instance of type ivryobi.agi: Class not found, make sure the class exists and is available on the CLASSPATH 4849 [AJ DaemonPool-1.1] ERROR org.asteriskjava.fastagi.internal.FastAgiConnectionHandler - No script configured for URL 'agi://192.168.0.8/ivryobi.agi' (script 'ivryobi.agi')

已尝试故障排除

拜托,你有什么其他想法可以尝试吗?

终于自己找到了解决方法

我不得不使用项目的源代码重新编译 asterisk-java.jar

在 DefaultAgiServer.java 上更改行:

resourceBundle = ResourceBundle.getBundle(configResourceBundleName);

有:

    FileInputStream fis = new FileInputStream("myivr.properties");
    resourceBundle = new PropertyResourceBundle(fis);
     
    logger.info("resourceBundle cargado ok!");

上钩,替换

return;

响应更佳,如果资源无法加载,您将知道

logger.info("resourceBundle cargado ok!");                 
            
        }
        catch (MissingResourceException | IOException e)
        {
            logger.error("No existe el recurso invocado: " + e.getMessage());
            return;
        }