简体   繁体   English

Asterisk-Java 无法加载属性文件

[英]Asterisk-Java Unable to load Properties file

I'm developing a very simple Asterisk-Java IVR based program that greets the caller, retrieves some information from a web service, reads up the retrieved data to the caller, and finally hangs up.我正在开发一个非常简单的基于 Asterisk-Java IVR 的程序来迎接调用者,从 web 服务中检索一些信息,将检索到的数据读取给调用者,最后挂断。

What steps I followed:我遵循了哪些步骤:

Added the following line is entered on extensions_custom.conf:在 extensions_custom.conf 中添加了以下行:

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

Created the following file structure inside C:\Project\target\classes\在 C:\Project\target\classes\ 中创建了以下文件结构

Runnable.java
IvrYobi.java
Runnable.class
IvrYobi.class
fastagi-mapping.properties

Inside fastagi-mapping.properties I have:在 fastagi-mapping.properties 里面我有:

ivryobi.agi = main.IvrYobi

The contens of IvrYoby are: IvrYoby的内容是:

public class IvrYobi extends BaseAgiScript {

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

When it works normally当它正常工作时

Running the following command in the console在控制台中运行以下命令

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;. 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 org.asteriskjava.fastagi.DefaultAgiServer

As you can see on the following console output, works perfectly正如您在以下控制台 output 上看到的,完美运行

jun 30, 2020 6:09:04 PM org.asteriskjava.fastagi.DefaultAgiServer startup INFORMACIËN: Listening on *:4573. 2020 年 6 月 30 日下午 6:09:04 org.asteriskjava.fastagi.DefaultAgiServer 启动 INFORMACIËN:监听 *:4573。 jun 30, 2020 6:09:09 PM org.asteriskjava.fastagi.AbstractAgiServer getPool INFORMACIËN: Thread pool started. 2020 年 6 月 30 日下午 6:09:09 org.asteriskjava.fastagi.AbstractAgiServer getPool INFORMACIËN:线程池已启动。 jun 30, 2020 6:09:09 PM org.asteriskjava.fastagi.ResourceBundleMappingStrategy loadResourceBundle INFORMACIËN: Added mapping for 'ivryobi.agi' to class IvrYobi... 2020 年 6 月 30 日下午 6:09:09 org.asteriskjava.fastagi.ResourceBundleMappingStrategy loadResourceBundle INFORMACIËN:将“ivryobi.agi”的映射添加到 class IvrYobi...

When the problem appears当问题出现时

When I run the very same code, but insted of the console I use Runnable.java当我运行相同的代码,但在控制台中插入时,我使用 Runnable.java

Here are the contents of 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();
    }

We can observe the following error on Eclipse's console:我们可以在 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. 0 [main] DEBUG org.asteriskjava.fastagi.DefaultAgiServer - 使用 channelFactory org.asteriskjava.fastagi.internal.DefaultAgiChannelFactory 9 [main] INFO org.asteriskjava.fastagi.DefaultAgiServer - 监听 *: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. 4806 [main] DEBUG org.asteriskjava.fastagi.DefaultAgiServer - 收到来自 /192.168.0.254 的连接 4810 [main] INFO org.asteriskjava.fastagi.DefaultAgiServer - 线程池已启动。 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') 4849 [AJ DaemonPool-1.1] 调试 org.asteriskjava.fastagi.ClassNameMappingStrategy - 无法创建 ivryobi.agi 类型的 AgiScript 实例:Class 未找到,请确保 class1 存在且可用于org.asteriskjava.fastagi.internal.FastAgiConnectionHandler - 没有为 URL 'agi://192.168.0.8/ivryobi.agi' 配置脚本(脚本'ivryobi.agi')

Attempted troubleshooting已尝试故障排除

  • I already made sure that fastagi-mapping.properties is on the CLASSPATH.我已经确定 fastagi-mapping.properties 在 CLASSPATH 上。
  • Tried different name and case尝试了不同的名称和大小写
  • Copied the.properties file on the java Execution Path复制java执行路径上的.properties文件
  • Compiled the project as an executable jar将项目编译为可执行文件 jar
  • Added / removed packages inside eclipse (ex: com.test.IvrYobi) and also applied the changes on the.properties file.在 eclipse(例如:com.test.IvrYobi)中添加/删除了包,并在 .properties 文件上应用了更改。
  • I checked the code inside asterisk-java-3.5.0.jar, looks like that in case that the configuration file is not found, it just continues without throwing any warning.我检查了asterisk-java-3.5.0.jar中的代码,看起来如果没有找到配置文件,它会继续运行而不发出任何警告。 Since is packed inside the jar I'm unable to modify that code.由于包装在 jar 中,因此我无法修改该代码。

Please, do you have any other ideas I can try?请问,你还有什么我可以尝试的想法吗?

Finally found the solution by myself终于自己找到了解决方案

I had to recompile asterisk-java.jar using the project's source code我不得不使用项目的源代码重新编译 asterisk-java.jar

On DefaultAgiServer.java change the line:在 DefaultAgiServer.java 上更改行:

resourceBundle = ResourceBundle.getBundle(configResourceBundleName);

With:和:

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

On the catch, replace the在捕获物上,更换

return;

with a more decent response, so you will know if the resource could not be loaded响应更体面,因此您将知道资源是否无法加载

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM