gpt4 book ai didi

java - 为什么 ProcessExecutionEngine 总是向 Web 服务发送空输入参数?

转载 作者:太空宇宙 更新时间:2023-11-04 14:50:33 25 4
gpt4 key购买 nike

我正在尝试基于其 owls 执行 Web 服务描述文件使用 owls-api-3.1

Web 服务很简单 使用部署的服务, owls 文件是使用 WSDL2OWLS 生成的在代码示例中找到的类(从 src jar 下载并提取),代码托管在这个 github repository 中。 .

(网络服务已使用 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;
}
}

Web 服务部署

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();

OWLS 客户端

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

生成完整的owls文件

<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:grounding="http://www.daml.org/services/owl-s/1.2/Grounding.owl#"
xmlns="http://www.example.org/service.owl"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:list="http://www.daml.org/services/owl-s/1.2/generic/ObjectList.owl#"
xmlns:expr="http://www.daml.org/services/owl-s/1.2/generic/Expression.owl#"
xmlns:swrl="http://www.w3.org/2003/11/swrl#"
xmlns:service="http://www.daml.org/services/owl-s/1.2/Service.owl#"
xmlns:profile="http://www.daml.org/services/owl-s/1.2/Profile.owl#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:process="http://www.daml.org/services/owl-s/1.2/Process.owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xml:base="http://www.example.org/service.owl">
<owl:Ontology rdf:about="">
<owl:imports rdf:resource="http://www.daml.org/services/owl-s/1.2/Grounding.owl"/>
<owl:imports rdf:resource="http://www.daml.org/services/owl-s/1.2/Profile.owl"/>
</owl:Ontology>
<service:Service rdf:ID="helloService">
<service:supports>
<grounding:WsdlGrounding rdf:ID="helloGrounding"/>
</service:supports>
<service:describedBy>
<process:AtomicProcess rdf:ID="helloProcess"/>
</service:describedBy>
<service:presents>
<profile:Profile rdf:ID="helloProfile"/>
</service:presents>
</service:Service>
<profile:Profile rdf:about="#helloProfile">
<profile:hasOutput>
<process:Output rdf:ID="return">
<process:parameterType rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>http://www.w3.org/2001/XMLSchema#string</process:parameterType>
<rdfs:label>return</rdfs:label>
</process:Output>
</profile:hasOutput>
<profile:hasInput>
<process:Input rdf:ID="name">
<process:parameterType rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>http://www.w3.org/2001/XMLSchema#string</process:parameterType>
<rdfs:label>name</rdfs:label>
</process:Input>
</profile:hasInput>
<profile:textDescription>Auto generated from HTTP://127.0.0.1/hello?wsdl</profile:textDescription>
<profile:serviceName>hello</profile:serviceName>
<service:presentedBy rdf:resource="#helloService"/>
</profile:Profile>
<process:AtomicProcess rdf:about="#helloProcess">
<process:hasOutput rdf:resource="#return"/>
<process:hasInput rdf:resource="#name"/>
<service:describes rdf:resource="#helloService"/>
<rdfs:label>helloProcess</rdfs:label>
</process:AtomicProcess>
<grounding:WsdlGrounding rdf:about="#helloGrounding">
<grounding:hasAtomicProcessGrounding>
<grounding:WsdlAtomicProcessGrounding rdf:ID="helloAtomicProcessGrounding"/>
</grounding:hasAtomicProcessGrounding>
<service:supportedBy rdf:resource="#helloService"/>
</grounding:WsdlGrounding>
<grounding:WsdlAtomicProcessGrounding rdf:about="#helloAtomicProcessGrounding">
<grounding:wsdlOutput>
<grounding:WsdlOutputMessageMap>
<grounding:wsdlMessagePart rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>HTTP://127.0.0.1/hello?wsdl#return</grounding:wsdlMessagePart>
<grounding:owlsParameter rdf:resource="#return"/>
</grounding:WsdlOutputMessageMap>
</grounding:wsdlOutput>
<grounding:wsdlInput>
<grounding:WsdlInputMessageMap>
<grounding:wsdlMessagePart rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>HTTP://127.0.0.1/hello?wsdl#name</grounding:wsdlMessagePart>
<grounding:owlsParameter rdf:resource="#name"/>
</grounding:WsdlInputMessageMap>
</grounding:wsdlInput>
<grounding:wsdlOutputMessage rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>http://127.0.0.1/hello?wsdl#helloResponse</grounding:wsdlOutputMessage>
<grounding:wsdlInputMessage rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>http://127.0.0.1/hello?wsdl#hello</grounding:wsdlInputMessage>
<grounding:wsdlDocument rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>HTTP://127.0.0.1/hello?wsdl</grounding:wsdlDocument>
<grounding:wsdlOperation>
<grounding:WsdlOperationRef>
<grounding:operation rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"
>HTTP://127.0.0.1/hello?wsdl#hello</grounding:operation>
</grounding:WsdlOperationRef>
</grounding:wsdlOperation>
<grounding:owlsProcess rdf:resource="#helloProcess"/>
</grounding:WsdlAtomicProcessGrounding>
</rdf:RDF>

最佳答案

看来 1.4 使用 绑定(bind)来调用Web服务,在Web服务声明中将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;
}
}

关于java - 为什么 ProcessExecutionEngine 总是向 Web 服务发送空输入参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23848800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com