我正在使用cxf 2.7.7并使用带有https的MTOM ...它可以正常使用cxf java客户端。 但是,当我通过SOAP UI客户端发送消息时,在服务器端(在我的端点实现类中),我尝试访问Datahandler对象的任何方法(请参阅下面的删节代码)然后我得到java.lang.NullPointerException在org.apache.cxf.attachment.LazyDataSource中。请注意,调用任何.getXXX方法都会产生异常(这些调用转换为对LazyDataSource.getXXX方法的相应调用......看起来像LazyDataSource为null) 当我通过Java客户端发送请求时,这不会发生。仅在我使用SOAPUI请求时才会发生 @WebService(targetNamespace =“http://webservice.dcca.dell.com”, portName =“ObjectMTOMService”,serviceName =“ObjectMTOMServiceService”) public class ObjectMTOMServiceImpl实现ObjectMTOMService {
@Resource
WebServiceContext wsContext;
public ObjectStoreResp uploadObject(ObjectStoreReq objectReqParam) {
DataHandler objHandler = objectReqParam.getObjData();
try {
if (objHandler != null)
{
String objName=objHandler.getName();
String contentType=objHandler.getContentType();
InputStream iStream= objHandler.getDataSource().getInputStream();
}
catch (Exception e) {
e.printStackTrace();
respParam.setRespCode(-1);
return (respParam);
}
}
我看到的例外情况如下
java.lang.NullPointerException
at org.apache.cxf.attachment.LazyDataSource.getName(LazyDataSource.java:73)
at javax.activation.DataHandler.getName(DataHandler.java:191)
at com.dell.dcca.webservice.objectmtomservice.ObjectMTOMServiceImpl.uploadObject(ObjectMTOMServiceImpl.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
........ <<< removed lot of stack trace for brevity >>>
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1555)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
java.lang.NullPointerException
SOAPUI发送的消息如下&lt;&lt;我已接近这一点 - 从SOAPUI日志复制和粘贴&gt;&gt;
POST https://160.110.73.35:8443/ObjectMTOMService/services/ObjectMTOMService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: multipart/related; type="application/xop+xml"; start="<rootpart@soapui.org>"; start-info="text/xml"; boundary="----=_Part_13_756617.1389959552144"
SOAPAction: "http://InteropBaseAddress/interop/header"
MIME-Version: 1.0
Content-Length: 5432
Host: 160.110.73.35:8443
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
------=_Part_13_756617.1389959552144"
"Content-Type: application/octet-stream; name=InfantHealthcare.jpg"
Content-Transfer-Encoding: binary
Content-ID: <images.jpg>
Content-Disposition: attachment; name="images.jpg"; filename="InfantHealthcare.jpg
<< file contents ... >>
欢迎任何投入。 如果有人尝试过使用SOAPui客户端和Axis 2.7.X组合的MTOM,请告诉我
非常感谢你的帮助
约杰什
答案 0 :(得分:0)
这个问题是因为我在SOAPUI中使用了错误的设置,即将数据作为Null发送。我认为这是一个CXF错误,它给出了空指针异常。应该有一种更安全的方式来报告我有一个空附件。无论如何,问题是我是如何解决的。
以下链接,确实提供了信息,但恕我直言,它有点含糊不清(或者可能是我没有解释它:-( - 不得不多次阅读
http://www.soapui.org/SOAP-and-WSDL/adding-headers-and-attachments.html
我在SOAP UI中指定请求SOAP消息的错误方法是
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:typ="http://webservice.dcca.dell.com/types">
<soapenv:Header/>
<soapenv:Body>
<typ:objectStoreReq>
<typ:ObjData>cid:183942097334</typ:ObjData>
<typ:objMetadata>
<typ:objName>img</typ:objName>
<typ:organizationName>Dell</typ:organizationName>
</typ:objMetadata>
</typ:objectStoreReq>
</soapenv:Body>
</soapenv:Envelope>
正确的方法是(注意,不是在“Objdata”元素中填充部分id-使用“cid:id”将其作为base64编码发送,我们必须使用href指定XOP Include元素引用第二个Mime-Part
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:typ="http://webservice.dcca.dell.com/types">
<soapenv:Header/>
<soapenv:Body>
<typ:objectStoreReq>
<typ:ObjData>
<inc:Include
href="cid:myImage.jpg"
xmlns:inc="http://www.w3.org/2004/08/xop/include"
/>
</typ:ObjData>
<typ:objMetadata>
<typ:objName>img</typ:objName>
<typ:organizationName>Dell</typ:organizationName>
</typ:objMetadata>
</typ:objectStoreReq>
</soapenv:Body>
</soapenv:Envelope>
有了这个,我的SOAP-UI消息非常适合我的服务:-)