NonStop SOAP User's Manual
Customizing the SOAP Server
NonStop SOAP User’s Manual—520501-012
8-32
Examples
Example 8-3. Sample Code Accessing Attachments
long SoapUEHandler_Generic::pre_process (ServiceEnv *env,
       SoapFault *sf)
{
  gSoapTrace.log ("Entered SoapUEHandler_Generic::pre_process\n");
  AttachmentManager * reqMgr = env -> getReqAttMgr( );
  if (reqMgr == NULL ||  
  reqMgr -> getAttachmentCount ( ) <= 1){ //if attachment count == 1 ,
  // then it implies that the attachment present
  // represents the request SOAP message.
   gSoapTrace.log ("No interesting attachments found. Leaving
   pre_process.");
   return 0;
  }
  Attachment * attPtr = reqMgr -> getFirstAttachment ( );
  // The first one if !null represents the request SOAP message
  attPtr = reqMgr -> getNextAttachment ( );
  int count = 1;
  //The following while loop prints the data associated with the
  //claim.doc and crashPic.jpg attachments
  while (attPtr != NULL){
   gSoapTrace.log ("Attachment # %d\n", count);
   gSoapTrace.log (" ****************************\n");
   gSoapTrace.log ( attPtr -> getContent( ).c_str( ) );
   gSoapTrace.log (" ****************************\n");
   attPtr = reqMgr -> getNextAttachment ( );
   count++; 
  }
  // The acknowledgement to the receipt of the claim is now created
  // This is the form of attachments that we can set in the output
  AttachmentManager * respMgr = env -> getRespAttMgr();
  respMgr -> setMimeBoundary("Simple_Mime_Boundary");
  //some image that acknowledges the receipt is to be created
  //as an attachment
  Attachment * ackAttach = respMgr -> createAttachment
        ("acknowledge.jpg", "image/jpeg");
  ackAttach -> setContent("......");
  //now set a date for the 2nd attachment
  Attachment * dateAttach = respMgr -> createAttachment
     ("processingDateXML", "text/xml");
  string dateContent = "<date>\n";
  dateContent += "\t<month>August</month>\n";
  dateContent += "\t<day>10</day>\n";
  dateContent += "\t<year>2004</year>\n";
  dateContent += "</date>";
  dateAttach -> setContent (dateContent);
  //set the attachment manager as the response AttachmentManager
  bool success = env -> setRespAttMgr ( respMgr );
  if(success){
  gSoapTrace.log ("Successfully set 2 attachments for the output");
  }else{
  gSoapTrace.log ("Could not set the 2 attachments for the output");
  }
  return 0;
 }










