You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ricko xavier <or...@gmail.com> on 2008/02/04 16:48:50 UTC

Re: SOAP with attachment - Need to call operation passing a POJO along with multiple attachments

 Hello,
>
> i Need to call a service operation with a POJO and during the same service
> call send multiple file attachments. Would someone know how to do this. An
> example would be great. The current examples of SOAP with attachments only
> send files to the server.
>
> Any help in this regard is appreciated
>
> Rick
>

RE: SOAP with attachment - Need to call operation passing a POJO along with multiple attachments

Posted by "reddy, ramachandra" <ra...@anacomp.com>.
Hi Rick,
I had similar problem where I wanted to send a pojo that had two
attributes one was xml string and the next attribute was a inputstream.
 

//MyDTO
class  SAILTransferObject
{
 String xml;
 InpuStream ios;
 
 SAILTransferObject(){}
 SAILTransferObject(String ipStr,InpuStream ipStream ){
  xml=ipStr;
  ipStream=ios;
 }
 //getters and setters
} 
 
 
 
//My client 
Class MyWebserviceClient{
 
public static void main(String[] args)throws Exception {
  callPojoBasedSAILService();
  
 }
 

private static EndpointReference targetEPR = new EndpointReference(
 "http://localhost:8080/axis2/services/SAILWebService
<http://localhost:8080/axis2/services/SAILWebService> ");
 

private static  void  callPojoBasedSAILService() throws Exception{
  System.out.println(":: callPojoBasedSAILService");
  
  
  RPCServiceClient serviceClient = new RPCServiceClient();
  Options options = serviceClient.getOptions();
  options.setTo(targetEPR);
  options.setProperty(Constants.Configuration.ENABLE_MTOM,
Constants.VALUE_TRUE);
  QName method = new QName("http://webservices.sail.com
<http://webservices.sail.com> ", "pojoService");
  DataHandler dataHandler = new DataHandler(new
FileDataSource("C:\\Resume.doc"));
  ISAILObject sailTransferDto = new
SAILTransferObject(getInboundXml(),dataHandler.getInputStream());
  Object[] inputArgs = new Object[] { sailTransferDto }; 
        Class<?>[] returnTypes = new Class[] { SAILTransferObject.class
};
        try{
         Object[] response = serviceClient.invokeBlocking(method,
inputArgs, returnTypes);
         ISAILObject result = (ISAILObject) response[0];
         
   if(result== null){
    System.out.println("Result was nulll");
   }
   else{
    System.out.println("result :" + result.getXMLMessage());
    System.out.println("result :" + result.getDocStream());
   } 
        }
        catch(AxisFault e){
         System.out.println(""+e.toString());
         System.out.println("\n FaultAction:"+e.getFaultAction());
         System.out.println("\n Node:"+e.getFaultNode());
         System.out.println("\n Reason:"+e.getReason());
        }
 }
 
}
 

// my service
package com.mycomp.webservices;
public class SAILWebService
{
 public ISAILObject pojoService(SAILTransferObject request ) throws
AxisFault
  {
   System.out.println(" Entered :: pojoService");
   try{
    return sailService(request); 
   }
   catch (Exception e) {
    System.out.println("Exception " + e.getStackTrace());
    e.printStackTrace();
    throw new AxisFault(e.getMessage());
   }
  }
 
 private  sailService( SAILTransferObject request){
 
  //Read stuff from DTO.
 
  // Do processing
  
  return SAILTransferObject(" Response xml",Inpustream obj /* The
response file*/ );
 }
}
 
//Service.xml
 
<service name="SAILWebService" scope="application">
    <description>
        SAIL WEB SERVICE
    </description>
 
 <operation name="pojoService">
    <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out
<http://www.w3.org/2004/08/wsdl/in-out> "
        class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
    <parameter name="enableMTOM" locked="false">true</parameter>
    </operation>
    <parameter
name="ServiceClass">com.mycomp.webservices.SAILWebService</parameter>
</service>

 
But for some reason it was complaining "cannot instantiate InpuStream
()" ... it was looking for default constructor for InpuStream  as well.
So right now  I am just using OMELements and it worked fine.But have to
explore the POJO stuff further.
 
 
 
 
 
 
 
 

________________________________

From: ricko xavier [mailto:orangetreats20171@gmail.com] 
Sent: Monday, February 04, 2008 10:49 AM
To: axis-user@ws.apache.org
Subject: Re: SOAP with attachment - Need to call operation passing a
POJO along with multiple attachments





	Hello,
	 
	i Need to call a service operation with a POJO and during the
same service call send multiple file attachments. Would someone know how
to do this. An example would be great. The current examples of SOAP with
attachments only send files to the server.
	 
	Any help in this regard is appreciated
	 
	Rick