SOAP post() 操作获取 Java nullptr 异常
SOAP post() operation gets Java nullptr exception
我在使用 SavonRuby 代码 posting SOAP 时遇到问题
我有一个参数 XML_BODY,它显然没有被发送,或者,如果是,对于接收它的 Java 代码来说看起来是空的(如果我尝试 return "TEST"+XML_BODY,响应显示"TEST null")
其他数据似乎发送正常 - 真的很困惑
客户端操作是pub_mugs(), post(), subscribe()
这个Python/Zeep代码完全成功
from requests import Session
from zeep import Client
from zeep.transports import Transport
if __name__ == "__main__":
url="http://localhost:8080/Wormhole?wsdl"
with open('../../web/web/xsd/DETEP2012-with-content.xml', 'r') as f:
xml=f.read().replace('\n', '')
session = Session()
session.verify = False
transport = Transport(session=session)
client = Client(url, transport=transport)
print client.service.PubMugs(username='usr',password='pwd') #SUCCESS
print client.service.subscribe(username='usr',password='pwd') #SUCCESS
print client.service.post(username='usr',password='pwd',mug='110',XML_BODY=xml) #SUCCESS
此 Ruby/Savon 代码对 pub_mugs() 和 subscribe() 成功,但 对 post()[=19 失败=]
client = Savon.client(wsdl: ENV["WSDL"],
:ssl_verify_mode => :none,
:raise_errors => false,
pretty_print_xml: true)
doc = File.open("../web/web/xsd/DETEP2012-with-content.xml") { |f| Nokogiri::XML(f) }
xml = doc.to_xml.delete("\n").split(">",2)[1] # Removes initial <?xml ... >
ap xml # The XML here looks correct
response_pub_mugs = client.call(:pub_mugs, message: { username: "usr", password: "pwd" } )
ap response_pub_mugs #SUCCESS
response_subscribe = client.call(:subscribe, message: { username: "usr", password: "pwd" } )
ap response_subscribe #SUCCESS
#THIS CALL FAILS!
response_post = client.call(:post,
message: {
username: "usr",
password: "pwd",
mug: "110",
XML_BODY: xml
}
)
故障响应是这样的
:fault => {
:faultcode => "S:Server",
:faultstring => "java.lang.NullPointerException",
:"@xmlns:ns4" => "http://www.w3.org/2003/05/soap-envelope"
}
堆栈跟踪并没有告诉我太多信息
SEVERE: null
java.lang.NullPointerException
at seti.Wormhole.post(Wormhole.java:103)
at sun.reflect.GeneratedMethodAccessor42.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:75)
at sun.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:279)
WSDL 文件
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://seti/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://seti/" name="Wormhole">
<types>
<xsd:schema>
<xsd:import namespace="http://seti/" schemaLocation="http://localhost:8080/Wormhole?xsd=1"/>
</xsd:schema>
</types>
<message name="PubMugs">
<part name="parameters" element="tns:PubMugs"/>
</message>
<message name="PubMugsResponse">
<part name="parameters" element="tns:PubMugsResponse"/>
</message>
<message name="post">
<part name="parameters" element="tns:post"/>
</message>
<message name="postResponse">
<part name="parameters" element="tns:postResponse"/>
</message>
<message name="subscribe">
<part name="parameters" element="tns:subscribe"/>
</message>
<message name="subscribeResponse">
<part name="parameters" element="tns:subscribeResponse"/>
</message>
<portType name="Wormhole">
<operation name="PubMugs">
<input wsam:Action="http://seti/Wormhole/PubMugsRequest" message="tns:PubMugs"/>
<output wsam:Action="http://seti/Wormhole/PubMugsResponse" message="tns:PubMugsResponse"/>
</operation>
<operation name="post">
<input wsam:Action="http://seti/Wormhole/postRequest" message="tns:post"/>
<output wsam:Action="http://seti/Wormhole/postResponse" message="tns:postResponse"/>
</operation>
<operation name="subscribe">
<input wsam:Action="http://seti/Wormhole/subscribeRequest" message="tns:subscribe"/>
<output wsam:Action="http://seti/Wormhole/subscribeResponse" message="tns:subscribeResponse"/>
</operation>
</portType>
<binding name="WormholePortBinding" type="tns:Wormhole">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="PubMugs">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="post">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="subscribe">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="Wormhole">
<port name="WormholePort" binding="tns:WormholePortBinding">
<soap:address location="http://localhost:8080/Wormhole"/>
</port>
</service>
</definitions>
post() 操作运行一些 Java 访问 MySQL 数据库的代码
也许 Savon 正在生成不同的 header?我真的很茫然 - 非常感谢任何帮助
编辑 - 更多信息
post()
的 Java 原型
@WebMethod(operationName = "post")
public String post(@WebParam(name = "username") String username, @WebParam(name = "password") String password, @WebParam(name = "mug") String mug, @WebParam(name = "XML_BODY") String XML_BODY)
顺便说一句,我还尝试将文件直接读入字符串 xml,跳过 Nokogiri 文档
而且我尝试从字符串 xml 中删除所有空格,并删除 pretty_print
如果我更改用户名或密码,我可以得到由 Java 代码生成的此响应,所以显然 Java 到此为止很开心,并且它正在访问数据库
:post_response => {
:return => "Unknown username or password. Message NOT submitted.",
:"@xmlns:ns2" => "http://seti/"
}
答案是这样的
已添加:none convert_request_keys_to
client = Savon.client(wsdl: ENV["WSDL"],
:ssl_verify_mode => :none,
:raise_errors => false,
pretty_print_xml: false,
convert_request_keys_to: :none)
哈希键使用了文字字符串
response_post = client.call(:post, message: { 'username': 'usr', 'password': 'pwd', 'mug': '110', 'XML_BODY': xml })
我在使用 SavonRuby 代码 posting SOAP 时遇到问题
我有一个参数 XML_BODY,它显然没有被发送,或者,如果是,对于接收它的 Java 代码来说看起来是空的(如果我尝试 return "TEST"+XML_BODY,响应显示"TEST null")
其他数据似乎发送正常 - 真的很困惑
客户端操作是pub_mugs(), post(), subscribe()
这个Python/Zeep代码完全成功
from requests import Session
from zeep import Client
from zeep.transports import Transport
if __name__ == "__main__":
url="http://localhost:8080/Wormhole?wsdl"
with open('../../web/web/xsd/DETEP2012-with-content.xml', 'r') as f:
xml=f.read().replace('\n', '')
session = Session()
session.verify = False
transport = Transport(session=session)
client = Client(url, transport=transport)
print client.service.PubMugs(username='usr',password='pwd') #SUCCESS
print client.service.subscribe(username='usr',password='pwd') #SUCCESS
print client.service.post(username='usr',password='pwd',mug='110',XML_BODY=xml) #SUCCESS
此 Ruby/Savon 代码对 pub_mugs() 和 subscribe() 成功,但 对 post()[=19 失败=]
client = Savon.client(wsdl: ENV["WSDL"],
:ssl_verify_mode => :none,
:raise_errors => false,
pretty_print_xml: true)
doc = File.open("../web/web/xsd/DETEP2012-with-content.xml") { |f| Nokogiri::XML(f) }
xml = doc.to_xml.delete("\n").split(">",2)[1] # Removes initial <?xml ... >
ap xml # The XML here looks correct
response_pub_mugs = client.call(:pub_mugs, message: { username: "usr", password: "pwd" } )
ap response_pub_mugs #SUCCESS
response_subscribe = client.call(:subscribe, message: { username: "usr", password: "pwd" } )
ap response_subscribe #SUCCESS
#THIS CALL FAILS!
response_post = client.call(:post,
message: {
username: "usr",
password: "pwd",
mug: "110",
XML_BODY: xml
}
)
故障响应是这样的
:fault => {
:faultcode => "S:Server",
:faultstring => "java.lang.NullPointerException",
:"@xmlns:ns4" => "http://www.w3.org/2003/05/soap-envelope"
}
堆栈跟踪并没有告诉我太多信息
SEVERE: null
java.lang.NullPointerException
at seti.Wormhole.post(Wormhole.java:103)
at sun.reflect.GeneratedMethodAccessor42.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:75)
at sun.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:279)
WSDL 文件
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://seti/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://seti/" name="Wormhole">
<types>
<xsd:schema>
<xsd:import namespace="http://seti/" schemaLocation="http://localhost:8080/Wormhole?xsd=1"/>
</xsd:schema>
</types>
<message name="PubMugs">
<part name="parameters" element="tns:PubMugs"/>
</message>
<message name="PubMugsResponse">
<part name="parameters" element="tns:PubMugsResponse"/>
</message>
<message name="post">
<part name="parameters" element="tns:post"/>
</message>
<message name="postResponse">
<part name="parameters" element="tns:postResponse"/>
</message>
<message name="subscribe">
<part name="parameters" element="tns:subscribe"/>
</message>
<message name="subscribeResponse">
<part name="parameters" element="tns:subscribeResponse"/>
</message>
<portType name="Wormhole">
<operation name="PubMugs">
<input wsam:Action="http://seti/Wormhole/PubMugsRequest" message="tns:PubMugs"/>
<output wsam:Action="http://seti/Wormhole/PubMugsResponse" message="tns:PubMugsResponse"/>
</operation>
<operation name="post">
<input wsam:Action="http://seti/Wormhole/postRequest" message="tns:post"/>
<output wsam:Action="http://seti/Wormhole/postResponse" message="tns:postResponse"/>
</operation>
<operation name="subscribe">
<input wsam:Action="http://seti/Wormhole/subscribeRequest" message="tns:subscribe"/>
<output wsam:Action="http://seti/Wormhole/subscribeResponse" message="tns:subscribeResponse"/>
</operation>
</portType>
<binding name="WormholePortBinding" type="tns:Wormhole">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="PubMugs">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="post">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="subscribe">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="Wormhole">
<port name="WormholePort" binding="tns:WormholePortBinding">
<soap:address location="http://localhost:8080/Wormhole"/>
</port>
</service>
</definitions>
post() 操作运行一些 Java 访问 MySQL 数据库的代码
也许 Savon 正在生成不同的 header?我真的很茫然 - 非常感谢任何帮助
编辑 - 更多信息
post()
的 Java 原型@WebMethod(operationName = "post")
public String post(@WebParam(name = "username") String username, @WebParam(name = "password") String password, @WebParam(name = "mug") String mug, @WebParam(name = "XML_BODY") String XML_BODY)
顺便说一句,我还尝试将文件直接读入字符串 xml,跳过 Nokogiri 文档
而且我尝试从字符串 xml 中删除所有空格,并删除 pretty_print
如果我更改用户名或密码,我可以得到由 Java 代码生成的此响应,所以显然 Java 到此为止很开心,并且它正在访问数据库
:post_response => {
:return => "Unknown username or password. Message NOT submitted.",
:"@xmlns:ns2" => "http://seti/"
}
答案是这样的
已添加:none convert_request_keys_to
client = Savon.client(wsdl: ENV["WSDL"],
:ssl_verify_mode => :none,
:raise_errors => false,
pretty_print_xml: false,
convert_request_keys_to: :none)
哈希键使用了文字字符串
response_post = client.call(:post, message: { 'username': 'usr', 'password': 'pwd', 'mug': '110', 'XML_BODY': xml })