2014-01-20 39 views
0

我正在使用cxf 2.7.7並使用HTOM與https ...並且它與cxf java客戶端正常工作。 但是,當我通過SOAP UI客戶端發送消息,並在服務器端(在我的端點實現類中)嘗試訪問Datahandler對象的任何方法時(請參閱下面的縮略代碼),然後獲得java.lang。 org.apache.cxf.attachment.LazyDataSource中的NullPointerException。請注意,對任何.getXXX方法的調用都會產生異常(這些調用將轉換爲相應的LazyDataSource.getXXX方法的調用,並且看起來像LazyDataSource爲空) 當我通過java客戶端發送請求時,不會發生這種情況。當我使用SOAPUI用於請求 @WebService只發生(的targetNamespace = 「http://webservice.dcca.dell.com」, PORTNAME = 「ObjectMTOMService」,服務名= 「ObjectMTOMServiceService」) 公共類ObjectMTOMServiceImpl實現ObjectMTOMService {org.apache.cxf.attachment.LazyDataSource.getInputStream中的java.lang.NullPointerException

@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發如下:< <我已經接近這一消息 - 複製和SOAPUI日誌粘貼>>

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="<[email protected]>";  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 ... >> 

歡迎任何輸入。 如果有人試圖用MTOM客戶SOAPUI和Axis 2.7.X起組合,讓我知道

由於一噸的幫助

約傑什

回答

0

此問題,因爲我是用在SOAPUI不正確的設置那是發送數據爲空。我認爲這是一個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編碼我們必須指定XOP包含元素參考使用href轉到第二個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的消息表現得非常可口我的服務:-)

相關問題