Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Spring Boot中使用解释器运行Jolie程序时出现未知操作错误_Java_Spring Boot_Jolie - Fatal编程技术网

Java 在Spring Boot中使用解释器运行Jolie程序时出现未知操作错误

Java 在Spring Boot中使用解释器运行Jolie程序时出现未知操作错误,java,spring-boot,jolie,Java,Spring Boot,Jolie,不久前,我得到了一个关于如何结合朱莉和弹簧靴功能的问题的答案。我曾尝试在Jolie中使用LocalCommChannel类和LocalInputPort实现建议的解决方案,但不幸的是,我传入请求的操作无法识别。下面是我的Spring Boot应用程序,一个简单的控制器,它试图运行解释器和一个Jolie程序 App.java @springboot应用程序 公共类应用程序{ 公共静态void main(字符串[]args){ SpringApplication.run(App.class,args

不久前,我得到了一个关于如何结合朱莉和弹簧靴功能的问题的答案。我曾尝试在Jolie中使用LocalCommChannel类和LocalInputPort实现建议的解决方案,但不幸的是,我传入请求的操作无法识别。下面是我的Spring Boot应用程序,一个简单的控制器,它试图运行解释器和一个Jolie程序

App.java
@springboot应用程序
公共类应用程序{
公共静态void main(字符串[]args){
SpringApplication.run(App.class,args);
}
}
HelloController.java
@RestController
公共类Hello控制器{
@请求映射(“/”)
字符串hello(){
字符串jh=System.getenv(“朱莉之家”);
字符串arg[]=新字符串[]{
“-l”,
“\\lib\\*;$JOLIE_HOME\\lib;$JOLIE_HOME\\javaServices\\*;$JOLIE_HOME\\extensions\\*”。替换(“$JOLIE_HOME”,jh),
“-我”,
“$JOLIE_HOME\\include.”替换(“$JOLIE_HOME”,jh),
“main.ol”
};
试一试{
最终解释器=新解释器(arg,HelloController.class.getClassLoader(),null);
Value v=Value.create();
v、 setFirstChild(“数字”,5);
CommMessage request=CommMessage.createRequest(“两次”、“/”、v);
LocalCommChannel c=解释器.commCore().getLocalCommChannel();
c、 发送(请求);
CommMessage response=c.recvResponseFor(请求);
if(response.isFault()){
System.out.println(“抛出响应.fault()”;
抛出response.fault();
}
返回response.value().toString();
}捕获(例外e){
e、 printStackTrace();
}
返回“坏结果”;
}
}
main.ol 输出 我试图跟踪我的程序使用了哪些Jolie类和函数,我注意到当调用getLocalCommChannel()时,它会创建新的LocalListener,从而创建全新的空接口InputPort,所以我不知道该操作如何显示两次。我怀疑我可能需要在CommCore中使用AddLocaliInputPort(),或者在LocalListener中使用mergeInterface(),然后自己配置,但我希望Jolie可以在不采取任何行动的情况下处理好这件事

PS:这些Jolie core Java类是否有任何在线文档,或者最好也是唯一的选择是阅读github上的代码?

在Java代码中:

  • 你没有使用replaceAll,也没有像我在原来的帖子中那样逃避美元:
  • 你不能启动翻译。自从我写了我最初的博客文章之后,实际上有了一个新的更为奇特的界面:你可以调用解释器.start(),它返回一个未来,你可以等待,直到解释器准备好接收消息
在《朱莉密码》中:

  • 您不需要调用运行时来使用本地位置
  • 在发送响应后,将请求-响应操作的计算放入
    两次
    (注意方括号的位置)
这里有一个对我有用的例子。请注意,我正在使用:而不是;作为参数中的路径分隔符(我正在Linux上测试),您可能需要更改它

Example.java main.ol
希望有帮助

似乎有两次调用的包冲突,请尝试确保您了解这些包。没有关于内部Java类的在线文档。我们很高兴收到这方面的捐款。:-)PS:但是你可以看看Javadoc并改进它们。例如,我们可以发布这些。谢谢。这很有帮助。问题当然是我在朱莉程序中错误地使用了方括号,并且没有运行解释器。奇怪的是,当我试着按照你博客上描述的方式运行它时——使用线程——它仍然不起作用——输出与以前一样,但使用新奇的新方式成功了。:)此外,我在Path中替换$JOLIE_HOME的方式对我来说也很有效——可能是因为不同的环境(我在Windows 10上使用VS代码)。我实际上成功地运行了解释器,并使用线程使其工作——正如你的博客中所描述的那样——但我不得不在t.start()之后、Value.create()之前进行睡眠。很高兴这有帮助!是的,“手动”线程方法的主要问题是,您不知道解释器何时准备好接收消息(解析朱莉程序并初始化其输入端口需要很短的时间)。唯一的方法是让朱莉程序本身以某种方式(通过消息或java服务)通知您。新的启动方法解决了所有这些问题。
include "console.iol"
include "runtime.iol"

execution { concurrent }

type TwiceRequest: void {
    .number: int
}

type TwiceResponse: void {
    .result: int
}

interface LocalInterface {
    RequestResponse:
        twice(TwiceRequest)(TwiceResponse)
}

inputPort TwiceIP {
    Location: "local"
    Interfaces: LocalInterface
}

init
{
    getLocalLocation@Runtime()( TwiceIP.location )
}

main {
    [twice( request )( response )] {
        println@Console("Hello World")();
        response.result = request.number * 2
    }
}
2019-07-07 18:20:53.315  WARN 19236 --- [       Thread-3] Jolie : [main.ol] Received 
a message for operation twice, not specified in the input port LocalInputPort 
at the receiving service. Sending IOException to the caller.
thrown response.fault()
jolie.runtime.FaultException: IOException: Invalid operation: twice
    at jolie.net.CommCore$CommChannelHandlerRunnable.handleMessage(CommCore.java:594)
    at jolie.net.CommCore$CommChannelHandlerRunnable.run(CommCore.java:620)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
public class Example
{
    public static void main( String[] args )
    {
        String jh = System.getenv( "JOLIE_HOME" );
        String arg[] = {
            "-l",
            "./lib/*:$JOLIE_HOME/lib:$JOLIE_HOME/javaServices/*:$JOLIE_HOME/extensions/*".replaceAll("\\$JOLIE_HOME", jh),
            "-i",
            "$JOLIE_HOME/include".replaceAll("\\$JOLIE_HOME", jh),
            "main.ol"
        };
        try {
            final Interpreter interpreter = new Interpreter(arg, Example.class.getClassLoader(), null);
            Exception e = interpreter.start().get();
            if ( e != null )
                throw e;

            Value v = Value.create();
            v.setFirstChild( "number", 5 );
            CommMessage request = CommMessage.createRequest( "twice", "/", v );
            LocalCommChannel c = interpreter.commCore().getLocalCommChannel();
            c.send( request );
            CommMessage response = c.recvResponseFor( request ).get();
            if ( response.isFault() ) {
                System.out.println("thrown response.fault()");
                throw response.fault();
            }
            System.out.println( response.value().getFirstChild( "result" ).strValue() );
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
include "console.iol"

execution { concurrent }

type TwiceRequest: void {
    .number: int
}

type TwiceResponse: void {
    .result: int
}

interface LocalInterface {
    RequestResponse:
        twice(TwiceRequest)(TwiceResponse)
}

inputPort TwiceIP {
    Location: "local"
    Interfaces: LocalInterface
}

main {
    [twice( request )( response ) {
        println@Console("Hello World")();
        response.result = request.number * 2
    }]
}