5 Replies Latest reply on Oct 28, 2005 12:50 PM by stevehnsn

    Data returned from WS is incorrect type and empty.

    stevehnsn

      I'm attempting to send a tiff file from servlet to client by wrapping it in a datahandler and returning the datahandler via RPC. I'm developing in Eclipse with JBoss 4.0.2. At the server, the datahandler is created correctly, but on the client side, the object that is returned is apparently an AttachmentPart rather than a datahandler, and it's also very much null. In fact the datahandler contained within it is useless. After multiple tries with multiple sources, I followed JBossWSAttachStepByStep to a T.

      Here's the server code which works fine:

      try{
       File theFile = new File(testTiff);
       DataSource ds = new ByteArrayDataSource(theFile, "image/tiff");
       DataHandler dh = new DataHandler(ds);
       return dh;
      }
      catch(Exception ex) { ... }
      


      Here's the client code:

      (To avoid confusion, if I just say
      DataHandler ret = call.invoke(...);
      or
      DataHandler ret = (DataHandler) call.invoke(...);
      which is what I was doing originally, it still doesn't work.
      I've only just pasted my most recent code.)

      try {
       DataHandler dh = null;
       String endpoint = "http://dd-hanson:8080/serviceName/Controller?wsdl";
       URL myURL = new URL(endpoint);
       QName myQ = new QName(NAMESPACE_URI, "ControllerService");
       ServiceFactory factory = (ServiceFactory)ServiceFactory.newInstance();
       Service service = (Service)factory.createService(myURL, myQ);
       Call call = (Call)service.createCall(new QName(NAMESPACE_URI, SERVICE_PORT) );
       call.setTargetEndpointAddress(endpoint);
       call.setOperationName(new QName("http://web.imaging/wsdl", "getImage"));
      
       Object ret = call.invoke(new Object[]{imageID});
      
       System.out.println("ret is type: " + ret.getClass()); // This is how I know 'ret' is an AttachmentPart
       dh = (DataHandler)((org.apache.axis.attachments.AttachmentPart)ret).getDataHandler();
       return dh; // By this point dh is just about as useless as null.
      }
       catch (Exception ex) { ... }
      


      Here's my WSDL:
      <?xml version="1.0" encoding="UTF-8"?>
      
      <definitions name="ControllerService"
       targetNamespace="http://web.imaging/wsdl"
       xmlns:tns="http://web.imaging/wsdl"
       xmlns="http://schemas.xmlsoap.org/wsdl/"
       xmlns:ns2="http://java.sun.com/jax-rpc-ri/internal"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
       xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">
      
       <types />
      
       <message name="FrontControllerInterface_getImage">
       <part name="String_1" type="xsd:string"/></message>
       <message name="FrontControllerInterface_getImageResponse">
       <part name="result" type="xsd:hexBinary"/></message>
       <!-- GetImageResponse used to be type="ns2:datahandler" -->
      
       <portType name="FrontControllerInterface">
      
       <operation name="getImage" parameterOrder="String_1">
       <input message="tns:FrontControllerInterface_getImage"/>
       <output message="tns:FrontControllerInterface_getImageResponse"></output>
       </operation>
       </portType>
      
       <binding name="FrontControllerInterfaceBinding" type="tns:FrontControllerInterface">
       <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
      
       <operation name="getImage">
       <soap:operation soapAction=""/>
       <input>
       <soap:body use="literal" namespace="http://web.imaging/wsdl"/></input>
       <output>
       <soap:body use="literal" namespace="http://web.imaging/wsdl"/>
       <mime:multipartRelated>
       <mime:part>
       <soap:body use="literal" namespace="http://web.imaging/wsdl"/>
       </mime:part>
       <mime:part>
       <mime:content part="result" type="image/tiff" />
       </mime:part>
       </mime:multipartRelated>
       </output>
       </operation>
       </binding>
       <service name="ControllerService">
       <port name="FrontControllerInterfacePort" binding="tns:FrontControllerInterfaceBinding">
       <soap:address location="REPLACE_WITH_ACTUAL_URL"/></port></service>
      </definitions>
      


      Here's my webservices.xml:
      <webservices xmlns="http://java.sun.com/xml/ns/j2ee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
       http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd"
       version="1.1">
       <webservice-description>
       <webservice-description-name>ControllerService</webservice-description-name>
       <wsdl-file>WEB-INF/wsdl/ControllerService.wsdl</wsdl-file>
       <jaxrpc-mapping-file>WEB-INF/mapping.xml</jaxrpc-mapping-file>
       <port-component>
       <port-component-name>PortComponent</port-component-name>
       <wsdl-port>FrontControllerInterfacePort</wsdl-port>
       <service-endpoint-interface>
       imaging.web.FrontControllerInterface
       </service-endpoint-interface>
       <service-impl-bean>
       <servlet-link>Controller</servlet-link>
       </service-impl-bean>
       </port-component>
       </webservice-description>
      </webservices>
      


      Here's my mapping file:
      <?xml version="1.0" encoding="UTF-8"?>
      <java-wsdl-mapping xmlns="http://java.sun.com/xml/ns/j2ee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       version="1.1" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
       http://www.ibm.com/webservices/xsd/j2ee_jaxrpc_mapping_1_1.xsd">
      <package-mapping>
       <package-type>imaging.web</package-type>
       <namespaceURI>http://web.imaging/wsdl</namespaceURI>
      </package-mapping>
      <service-interface-mapping>
       <service-interface>imaging.web.ControllerService</service-interface>
       <wsdl-service-name xmlns:serviceNS="http://web.imaging/wsdl">serviceNS:ControllerService</wsdl-service-name>
       <port-mapping>
       <port-name>FrontControllerInterfacePort</port-name>
       <java-port-name>FrontControllerInterfacePort</java-port-name>
       </port-mapping>
      </service-interface-mapping>
      <service-endpoint-interface-mapping>
       <service-endpoint-interface>imaging.web.FrontControllerInterface</service-endpoint-interface>
       <wsdl-port-type xmlns:portTypeNS="http://web.imaging/wsdl">portTypeNS:FrontControllerInterface</wsdl-port-type>
       <wsdl-binding xmlns:bindingNS="http://web.imaging/wsdl">bindingNS:FrontControllerInterfaceBinding</wsdl-binding>
       <service-endpoint-method-mapping>
       <java-method-name>getImage</java-method-name>
       <wsdl-operation>getImage</wsdl-operation>
       <method-param-parts-mapping>
       <param-position>0</param-position>
       <param-type>java.lang.String</param-type>
       <wsdl-message-mapping>
       <wsdl-message xmlns:wsdlMsgNS="http://web.imaging/wsdl">wsdlMsgNS:FrontControllerInterface_getImage</wsdl-message>
       <wsdl-message-part-name>String_1</wsdl-message-part-name>
       <parameter-mode>IN</parameter-mode>
       </wsdl-message-mapping>
       </method-param-parts-mapping>
       <wsdl-return-value-mapping>
       <method-return-value>javax.activation.DataHandler</method-return-value>
       <wsdl-message xmlns:wsdlMsgNS="http://web.imaging/wsdl">wsdlMsgNS:FrontControllerInterface_getImageResponse</wsdl-message>
       <wsdl-message-part-name>result</wsdl-message-part-name>
       </wsdl-return-value-mapping>
       </service-endpoint-method-mapping>
      </service-endpoint-interface-mapping>
      </java-wsdl-mapping>
      


      Someone please help, I've wasted a week of company time trying to make this work! Thanks so much.

      Steve

        • 1. Re: Data returned from WS is incorrect type and empty.
          stevehnsn

          I'm desperate here guys. I can't solve this and no one that I know can help me. Doesn't anyone have an opinion? Are there any other good forums that I can post this question to? Thanks.

          • 2. Re: Data returned from WS is incorrect type and empty.

            Hi!

            I've tried to compare your wsdl to one of ours which works fine under jboss 4.0.2.. have you tried to remove the

            <soap:body use="literal" namespace="http://web.imaging/wsdl"/>

            line from your output in the binding.. i.e. change it to

             <output>
             <mime:multipartRelated>
             <mime:part>
             <soap:body use="literal" namespace="http://web.imaging/wsdl"/>
             </mime:part>
             <mime:part>
             <mime:content part="result" type="image/tiff" />
             </mime:part>
             </mime:multipartRelated>
             </output>


            let me know if this helps!

            /Ole

            • 3. Re: Data returned from WS is incorrect type and empty.
              stevehnsn

              omatzura: Thank you for the response, but no, that doesn't solve anything.

              • 4. Re: Data returned from WS is incorrect type and empty.
                thomas.diesler

                Have looked at the attachement tests in the testsuite?

                If you are convinced that you found a bug please create a JIRA issue and attach a sample deployment that allows us to reproduce what you are seeing. Idealy, the sample deployment is a webapp packaged as a war that will show the issue when we click on a link. The war should also contain the sources.

                • 5. Re: Data returned from WS is incorrect type and empty.
                  stevehnsn

                  The solution was to define the type for the DataHandler to be "application/octet-stream". The solution looks like this:

                  <?xml version="1.0" encoding="UTF-8"?>
                  
                  <definitions name="ImagingService"
                   targetNamespace="http://web.imaging/ImagingService"
                   xmlns:tns="http://web.imaging/ImagingService"
                   xmlns="http://schemas.xmlsoap.org/wsdl/"
                   xmlns:ns2="http://java.sun.com/jax-rpc-ri/internal"
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                   xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">
                  
                   <types/>
                  
                   <message name="FrontControllerInterface_getImage">
                   <part name="String_1" type="xsd:string"/></message>
                   <message name="FrontControllerInterface_getImageResponse">
                   <part name="result" type="xsd:hexBinary"/></message>
                  
                   <portType name="FrontControllerInterface">
                   <operation name="getImage" parameterOrder="String_1">
                   <input message="tns:FrontControllerInterface_getImage"/>
                   <output message="tns:FrontControllerInterface_getImageResponse"/>
                   </operation>
                   </portType>
                  
                   <binding name="FrontControllerInterfaceBinding" type="tns:FrontControllerInterface">
                   <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
                   <operation name="getImage">
                   <soap:operation soapAction=""/>
                   <input>
                   <soap:body use="literal" namespace="http://web.imaging/ImagingService"/>
                   </input>
                   <output>
                   <mime:multipartRelated>
                   <mime:part>
                   <soap:body use="literal" namespace="http://web.imaging/ImagingService"/>
                   </mime:part>
                   <mime:part>
                   <mime:content part="result" type="application/octet-stream"/>
                   </mime:part>
                   </mime:multipartRelated>
                   </output>
                   </operation>
                   </binding>
                  
                   <service name="ImagingService">
                   <port name="FrontControllerInterfacePort" binding="tns:FrontControllerInterfaceBinding">
                   <soap:address location="REPLACE_WITH_ACTUAL_URL"/>
                   </port>
                   </service>
                  </definitions>
                  


                  This project is going to be rather large before I'm done, so I'm pretty unhappy about having to generate all of the WSDL file by hand from here on out, but as far as I can tell the only solution requires many changes to the WSDL file generated by wscompile from JWSDP. I don't think I found any bugs.