rangika 2005/02/22 00:46:03
Modified: c/src/server/apache2 AttachmentHelper.h AttachmentHelper.cpp
Log:
Modified Attachment Helper to support Binary attachments.
Revision Changes Path
1.4 +1 -1 ws-axis/c/src/server/apache2/AttachmentHelper.h
Index: AttachmentHelper.h
===================================================================
RCS file: /home/cvs/ws-axis/c/src/server/apache2/AttachmentHelper.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AttachmentHelper.h 31 Jan 2005 04:19:00 -0000 1.3
+++ AttachmentHelper.h 22 Feb 2005 08:46:03 -0000 1.4
@@ -44,7 +44,7 @@
public:
char* getIncomingSOAPMimeHeaders();
ISoapAttachment* getAttachment (const char* pcAttchId);
- void extract_info(string header,const char* label,SoapAttachment* pSoapAttachment);
+ void extract_info(string header,const char* label,SoapAttachment* pSoapAttachment, int&
iEncodingType);
void extract_SOAPMimeHeaders(char* pBuffer);
void extract_Soap (char* pBuffer);
void extract_Attachment (char* pBuffer);
1.3 +40 -15 ws-axis/c/src/server/apache2/AttachmentHelper.cpp
Index: AttachmentHelper.cpp
===================================================================
RCS file: /home/cvs/ws-axis/c/src/server/apache2/AttachmentHelper.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AttachmentHelper.cpp 31 Jan 2005 04:19:00 -0000 1.2
+++ AttachmentHelper.cpp 22 Feb 2005 08:46:03 -0000 1.3
@@ -23,8 +23,7 @@
}
void AttachmentHelper::extract_Attachment(char *pBuffer)
-{
- SoapAttachment* pSoapAttachment= new SoapAttachment();
+{
string Soap_Message = pBuffer;
int boundary1 = Soap_Message.find("</soapenv:Envelope>");
int boundary2 = boundary1 + strlen("</soapenv:Envelope>") + 2;
@@ -38,6 +37,7 @@
while (blnContinue)
{
+ SoapAttachment* pSoapAttachment= new SoapAttachment();
int start =0;
if (blnFirstTime) {
@@ -55,17 +55,33 @@
string header = Soap_Message.substr (start, headerLength);
end = Soap_Message.find(boundary, start);
int length2 = (end- 4) - (start2+5) ;
- xsd__base64Binary* base64_attachment = new xsd__base64Binary();
+
string attachment = Soap_Message.substr(start2+5, length2);
- const char* attach = attachment.c_str ();
- base64_attachment = AxisUtils::decodeFromBase64Binary(attach);
- pSoapAttachment->addBody(base64_attachment);
+ const char* attach = attachment.c_str ();
+
+ int iEncodingType= -1;
+
const char * strContentType1 ="Content-Type";
- extract_info(header,strContentType1,pSoapAttachment);
+ extract_info(header,strContentType1,pSoapAttachment, iEncodingType);
const char * strContentType2 ="Content-Transfer-Encoding";
- extract_info(header,strContentType2,pSoapAttachment);
+ extract_info(header,strContentType2,pSoapAttachment, iEncodingType);
const char * strContentType3 ="Content-Id";
- extract_info(header,strContentType3,pSoapAttachment);
+ extract_info(header,strContentType3,pSoapAttachment, iEncodingType);
+
+ /*Extracting and adding the attch body*/
+
+ if (iEncodingType==AXIS_BASE64) {
+ xsd__base64Binary* base64_attachment = new xsd__base64Binary();
+ base64_attachment = AxisUtils::decodeFromBase64Binary(attach);
+ pSoapAttachment->addBody(base64_attachment);
+ } else if (iEncodingType==AXIS_BINARY) {
+ //if it is binary
+ char* binaryBody = new char[attachment.length() + 1];
+ strcpy(binaryBody, attachment.c_str());
+ pSoapAttachment->addBody(binaryBody);
+
+ }
+
x++;
}
}
@@ -92,7 +108,7 @@
strcpy(pMime, mime_Part.c_str ());
}
-void AttachmentHelper::extract_info(string header, const char *label, SoapAttachment *pSoapAttachment)
+void AttachmentHelper::extract_info(string header, const char *label, SoapAttachment *pSoapAttachment,
int& iEncodingType)
{
int ContentTypeLabel = header.find(label);
int startValue = ContentTypeLabel+strlen(label);
@@ -104,12 +120,21 @@
pSoapAttachment->addHeader(label,ContentValue.c_str());
mymap[ContentValue.c_str()] = pSoapAttachment;
}
- else
+ else
{
- int endValue = header.find ("Content-", startValue);
- int length = endValue - (startValue + 2);
- string ContentValue = header.substr (startValue + 2, length-2);
- pSoapAttachment->addHeader(label,ContentValue.c_str());
+ int endValue = header.find ("Content-", startValue);
+ int length = endValue - (startValue + 2);
+ string ContentValue = header.substr (startValue + 2, length-2);
+
+ if (strcmp(label, "Content-Transfer-Encoding") ==0) {
+ if(strcmp (ContentValue.c_str(), "base64")==0) {
+ iEncodingType = AXIS_BASE64;
+ } else if(strcmp (ContentValue.c_str(), "binary")==0) {
+ iEncodingType = AXIS_BINARY;
+ }
+ }
+
+ pSoapAttachment->addHeader(label,ContentValue.c_str());
}
}
|