gpt4 book ai didi

java - Apache cxf java-first 和 SOAP 模块 npm

转载 作者:行者123 更新时间:2023-11-29 03:11:54 25 4
gpt4 key购买 nike

我已经使用默认方法部署了一个 cxf-jaxws-javafirst maven 项目:HelloWorld.sayHi(String text)。

http://localhost:8080/prueba/HelloWorld?wsdl enter image description here

另一方面,我有一个在 Nodejs 上使用 soap 模块实现的 soap 客户端。

var express = require('express')
var app = express()
//soap module
var soap = require('soap');
//url of the wsdl
var url = 'http://localhost:8080/prueba/HelloWorld?wsdl';
//variable
var args = {arg0: 'friend'};

app.get('/', function (req, res) {

soap.createClient(url, function(err, client) {
client.sayHi(args, function(err, result) {
res.send(result);
});
});
})

var server = app.listen(3000, function () {

var host = server.address().address
var port = server.address().port

console.log('Example app listening at http://%s:%s', host, port)

})

我已经尝试将 soap 消息发送到其他 WebService,例如http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl并且我的客户端代码可以正常工作,所以我认为我的 Web 服务中有一些错误。

在我的 maven 项目中,我刚刚在接口(interface)声明上方添加了这行代码,用于调试进出我的 Web 服务的消息:

@org.apache.cxf.feature.Features(features = "org.apache.cxf.feature.LoggingFeature")

通过这种方式我得到了输入消息(soap 客户端)和输出消息(WebService 响应):

输入信息:

mar 05, 2015 1:33:08 PM org.apache.cxf.services.HelloWorldImplService.HelloWorldImplPort.HelloWorld
INFORMACIÓN: Inbound Message
----------------------------
ID: 17
Address: http://localhost:8080/prueba/HelloWorld
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml; charset=utf-8
Headers: {Accept=[text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8], accept-charset=[utf-8], accept-encoding=[none], connection=[close], Content-Length=[230], content-type=[text/xml; charset=utf-8], host=[localhost:8080], SOAPAction=[""], user-agent=[node-soap/0.8.0]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://prueba.prueba/"><soap:Body><sayHi><arg0>Hola</arg0></sayHi></soap:Body></soap:Envelope>

输出信息:

mar 05, 2015 1:33:08 PM org.apache.cxf.services.HelloWorldImplService.HelloWorldImplPort.HelloWorld
INFORMACIÓN: Outbound Message
---------------------------
ID: 17
Response-Code: 500
Encoding: UTF-8
Content-Type: text/xml
Headers: {}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Unexpected wrapper element sayHi found. Expected {http://prueba.prueba/}sayHi.</faultstring></soap:Fault></soap:Body></soap:Envelope>

Java 错误:

mar 05, 2015 1:33:08 PM org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
ADVERTENCIA: Interceptor for {http://prueba.prueba/}HelloWorldImplService#{http://prueba.prueba/}sayHi has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Unexpected wrapper element sayHi found. Expected {http://prueba.prueba/}sayHi.
at org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:106)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:212)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:268)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

使用 SoapUI,我实现了发送字符串:这是 InputMessage(客户端:SoapUI)。

ID: 18
Address: http://localhost:8080/prueba/HelloWorld
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml;charset=UTF-8
Headers: {accept-encoding=[gzip,deflate], connection=[Keep-Alive],
Content-Length=[285], content-type=[text/xml;charset=UTF-8], host=[localhost:8080],
SOAPAction=[""], user-agent=[Apache-HttpClient/4.1.1 (java 1.5)]}
Payload: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pru="http://prueba.prueba/">
<soapenv:Header/>
<soapenv:Body>
<pru:sayHi>
<!--Optional:-->
<arg0>"?"</arg0>
</pru:sayHi>
</soapenv:Body>
</soapenv:Envelope>

我不知道我做错了,我希望有人能帮助我。

提前致谢。

最佳答案

我试图从 SoapUI 中删除命名空间 pru,但我遇到了同样的错误,所以这是我的错误,我必须添加命名空间。 Pru 指的是我的 wsdl 的命名空间 tns

我看了node-soap的github的issues,有一篇提到了命名空间tnshttps://github.com/vpulim/node-soap/issues/537

我已经更改了 wsdl.js 文件的这些行:

this.ignoredNamespaces= [ 'tns', 'targetNamespace', 'typedNamespace']
WSDL.prototype._ignoredSchemaNamespaces = ['tns', 'xs', 'xsd'];

this.ignoredNamespaces= [  'targetNamespace', 'typedNamespace']
WSDL.prototype._ignoredSchemaNamespaces = ['xs', 'xsd'];

我的代码有效。

谢谢你

关于java - Apache cxf java-first 和 SOAP 模块 npm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28878070/

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