SOAP Fault response has wrong Content-length on http header when using...
Development toolkit for Web Services and XML data bindings for C & C++
Brought to you by:
engelen
Testing with soapUI I was unable to check soap fault messages. SoapUI was throwing an exception complaining about Content-Length (in http header) being greater than current response size.
I found out the problem only occurs when using SOAP_XML_INDENT flag.
After some research I found the problem was related with soap->level variable.
When using SOAP_XML_STRICT flag for length validation you can get to soap_send_fault method without reseting soap->level variable.
I solved the issue reseting soap->level=0 in soap_send_fault:
soap_send_fault(struct soap *soap)
{ register int status = soap->error;
if (status == SOAP_OK || status == SOAP_STOP)
return soap_closesock(soap);
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Sending back fault struct for error code %d\n", soap->error));
soap->keep_alive = 0; /* to terminate connection */
soap_set_fault(soap);
if (soap->error < 200 && soap->error != SOAP_FAULT)
soap->header = NULL;
if (status != SOAP_EOF || (!soap->recv_timeout && !soap->send_timeout))
{ register int r = 1;
#ifndef WITH_NOIO
if (soap->fpoll && soap->fpoll(soap))
r = 0;
#ifndef WITH_LEAN
else if (soap_valid_socket(soap->socket))
{ r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_SND, 0);
if (r > 0)
{ int t;
if (!(r & SOAP_TCP_SELECT_SND)
|| ((r & SOAP_TCP_SELECT_RCV)
&& recv(soap->socket, (char*)&t, 1, MSG_PEEK) < 0))
r = 0;
}
}
#endif
#endif
if (r > 0)
{ soap->error = SOAP_OK;
soap->level = 0; // <<<<<<<<---------------------------------- HERE
soap->encodingStyle = NULL; /* no encodingStyle in Faults */
soap_serializeheader(soap);
soap_serializefault(soap);
soap_begin_count(soap);
if (soap->mode & SOAP_IO_LENGTH)
{ soap_envelope_begin_out(soap);
soap_putheader(soap);
soap_body_begin_out(soap);
soap_putfault(soap);
soap_body_end_out(soap);
soap_envelope_end_out(soap);
}
soap_end_count(soap);
if (soap_response(soap, status)
|| soap_envelope_begin_out(soap)
|| soap_putheader(soap)
|| soap_body_begin_out(soap)
|| soap_putfault(soap)
|| soap_body_end_out(soap)
|| soap_envelope_end_out(soap))
return soap_closesock(soap);
soap_end_send(soap);
}
}
soap->error = status;
return soap_closesock(soap);
}
Mi problem arises with version 2.7.16 on redhat 6, but I think it is still an issue on latest version.
Thanks for the feedback. The problem will be fixed in 2.8.18.