我尝试使用owls-api-3.1基于owls
描述文件执行网络服务。
Web服务是使用jax-ws部署的简单grizzly服务,使用代码示例中的WSDL2OWLS
类生成owls文件(从{{1下载并提取)代码托管在github repository。
(使用src
)
soapUI
@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;
}
}
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
Hello null
答案 0 :(得分:0)
似乎axis 1.4
使用rpc soap绑定来调用网络服务,在网络中设置SOAPBinding
到Style.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;
}
}