0

I am using cxf 2.7.7 and using MTOM with https ... and it is working ok with cxf java client. However when I send a message though SOAP UI client, and at the server side (in my endpoint implementation class) I try to access any of the methods of the Datahandler object (please see abridged code below) then I get java.lang.NullPointerException in org.apache.cxf.attachment.LazyDataSource. Please note that call to any .getXXX method gives exception (these calls translate to corresponding call to LazyDataSource.getXXX methods ... and looks like LazyDataSource is null) This does NOT happen when I send requests through java client. Happens only when I use SOAPUI for request @WebService(targetNamespace = "http://webservice.dcca.dell.com", portName = "ObjectMTOMService", serviceName = "ObjectMTOMServiceService") public class ObjectMTOMServiceImpl implements 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); 
            } 
} 

The exception I see is as follows

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 

The message that SOAPUI sends is as follows << I have approximated this -- copying and pasting from SOAPUI log >>

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 ... >> 

Any inputs welcome. If anyone has tried MTOM with SOAPui client and Axis 2.7.X onwards combination, let me know

Thanks a ton for your help

Yogesh

Yogesh Devi
  • 617
  • 11
  • 30

1 Answers1

0

This problem was because I was using incorrect setting in SOAPUI that was sending the Data as Null. I consider this as a CXF bug that it gives a Null Pointer exception. There should be a safer way of reporting that I have a null attachment. Anyways, the question is how did I fix it.

The below link, does give information but IMHO it is a bit ambiguous ( or may be I did not interpret it right :-( - had to read it many times over

http://www.soapui.org/SOAP-and-WSDL/adding-headers-and-attachments.html

My incorrect way of specifying the request SOAP message in SOAP UI was

<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>

The correct way is ( note that instead of filling a part id in "Objdata" element- using "cid: id" which sends it as base64 encoded we have to specify XOP Include element referring to the second Mime-Part using href.

<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>

With this my SOAP-UI messages were very much palatable to my service :-)

Yogesh Devi
  • 617
  • 11
  • 30