为什么ProcessExecutionEngine始终向Web服务发送空输入参数?

时间:2014-05-24 19:22:01

标签: java web-services jax-ws semantic-web owl

我尝试使用owls-api-3.1基于owls描述文件执行网络服务。

Web服务是使用部署的简单服务,使用代码示例中的WSDL2OWLS类生成owls文件(从{{1下载并提取)代码托管在github repository

(使用src

对Web服务进行了充分测试

Web服务定义

soapUI

Web服务部署

@WebService(serviceName = "Hello", targetNamespace = HelloService.WSDL_FILE)
public class HelloService {

    public static final String ROUTE = "/hello";
    public static final String OWLS_FILE = Bootstrap.OWLS_DIR + "/hello.owl";
    public static final String WSDL_FILE = "HTTP://127.0.0.1/hello?wsdl";

    /**
     * This is a sample web service operation
     *
     * @param name
     * @return
     */
    @WebMethod(operationName = "hello")
    public String hello(@WebParam(name = "name") String name) {
        return "Hello " + name;
    }
}

OWLS客户端

HttpServer httpServer = new HttpServer();
NetworkListener networkListener = new NetworkListener("grizzly", "0.0.0.0", 8080);
httpServer.addListener(networkListener);
httpServer.getServerConfiguration().addHttpHandler(new CLStaticHttpHandler(Bootstrap.class.getClassLoader(), "static/"), "/");
httpServer.getServerConfiguration().addHttpHandler(new JaxwsHandler(new HelloService()), HelloService.ROUTE);

httpServer.start();
Thread.sleep(2 * 1000); // The services are up and running    
System.out.println(" --- OWLS client --- ");
new HelloServiceOWLSClient().start();    
Thread.currentThread().join();

完整的堆栈跟踪

public class HelloServiceOWLSClient {

    private static final Logger LOG = Logger.getLogger(HelloServiceOWLSClient.class.getName());

    public void start() {
        try {

            OWLKnowledgeBase kb = OWLFactory.createKB();
            Service service = kb.readService(URI.create(HelloService.OWLS_FILE));
            Process process = service.getProcess();         
            ProcessExecutionEngine executionEngine = OWLSFactory.createExecutionEngine();

            ValueMap<Input, OWLValue> inputs = new ValueMap<>();
            inputs.setValue(process.getInput("name"), kb.createDataValue("tarrsalah"));
            LOG.log(Level.INFO, inputs.debugString());

            ValueMap<Output, OWLValue> outputs = executionEngine.execute(process, inputs, kb);

            LOG.log(Level.INFO, outputs.debugString());

        } catch (IOException | ExecutionException ex) {
            LOG.log(Level.SEVERE, ex.toString());
        } finally {

        }
    }
}

在最后一行中,我预计会May 25, 2014 1:34:33 AM org.glassfish.grizzly.http.server.NetworkListener start INFO: Started listener bound to [0.0.0.0:8080] May 25, 2014 1:34:34 AM org.glassfish.grizzly.http.server.HttpServer start INFO: [HttpServer] Started. --- OWLS client --- INFO [org.tarrsalah.owls.examples.Bootstrap.main()] (Vocabulary.java:118) - Loading ontology http://www.daml.org/services/owl-s/1.2/Service.owl# ... INFO [org.tarrsalah.owls.examples.Bootstrap.main()] (Vocabulary.java:118) - Loading ontology http://www.daml.org/services/owl-s/1.2/Profile.owl# ... INFO [org.tarrsalah.owls.examples.Bootstrap.main()] (Vocabulary.java:118) - Loading ontology http://www.daml.org/services/owl-s/1.2/ActorDefault.owl# ... INFO [org.tarrsalah.owls.examples.Bootstrap.main()] (Vocabulary.java:118) - Loading ontology http://www.daml.org/services/owl-s/1.2/ServiceParameter.owl# ... INFO [org.tarrsalah.owls.examples.Bootstrap.main()] (Vocabulary.java:118) - Loading ontology http://www.daml.org/services/owl-s/1.2/ServiceCategory.owl# ... INFO [org.tarrsalah.owls.examples.Bootstrap.main()] (Vocabulary.java:118) - Loading ontology http://www.daml.org/services/owl-s/1.2/Process.owl# ... INFO [org.tarrsalah.owls.examples.Bootstrap.main()] (Vocabulary.java:118) - Loading ontology http://www.daml.org/services/owl-s/1.2/generic/ObjectList.owl# ... INFO [org.tarrsalah.owls.examples.Bootstrap.main()] (Vocabulary.java:118) - Loading ontology http://www.daml.org/services/owl-s/1.2/generic/Expression.owl# ... INFO [org.tarrsalah.owls.examples.Bootstrap.main()] (Vocabulary.java:118) - Loading ontology http://www.daml.org/services/owl-s/1.2/Grounding.owl# ... INFO [org.tarrsalah.owls.examples.Bootstrap.main()] (Vocabulary.java:118) - Loading ontology http://on.cs.unibas.ch/owl-s/1.2/MoreGroundings.owl# ... INFO [org.tarrsalah.owls.examples.Bootstrap.main()] (Vocabulary.java:118) - Loading ontology http://on.cs.unibas.ch/owl-s/1.2/FLAService.owl# ... May 25, 2014 1:34:38 AM org.tarrsalah.owls.examples.HelloServiceOWLSClient start INFO: (name = tarrsalah) May 25, 2014 1:34:39 AM org.tarrsalah.owls.examples.HelloServiceOWLSClient start INFO: (return = Hello null) ----- 而不是Hello tarrsalah

生成完整的owls文件

Hello null

1 个答案:

答案 0 :(得分:0)

似乎 1.4使用 绑定来调用网络服务,在网络中设置SOAPBindingStyle.RPC服务声明解决了这个问题。

WebService(serviceName = "Hello", targetNamespace = "http://127.0.0.1/hello")
@SOAPBinding(style = Style.RPC)

public class HelloService {

    public static final String ROUTE = "/hello";
    public static final String OWLS_FILE = Bootstrap.OWLS_DIR + "/hello.owl";
    public static final String WSDL_FILE = "http://127.0.0.1/hello?wsdl";

    /**
     * This is a sample web service operation
     *
     * @param name
     * @return
     */
    @WebMethod(operationName = "hello")
    @WebResult(name="greeting")
    public String hello(@WebParam(name = "name") String name) {
        return "Hello " + name;
    }
}