Q
Problem solve Get help with specific problems with your technologies, process and projects.

How can I get the HTTP/SOAP Requests and Responses for a particular endpoint?

I want to get the HTTP Request with the SOAP Request and HTTP Response with the SOAP Response for a particular endpoint. I am new to Web services. Can you please guide or send me some sample code to achieve this functionality?

A SOAP message that is transported across an HTTP connection might take on any number of personalities before it is actually morphed into a valid SOAP envelope. For example, let's assume that an RPC service is desired and the SOAP service, method and method parameters are to be communicated to the server as parameters of a query string. The code to extract and build the SOAP envelope might look something like this:

String parseSOAPMessage(HttpServletRequest request,
HttpServletResponse response)
throws SOAPFault
{
String serviceName = null;
String operationName = null;
String operationArgs = "";
Enumeration enum = request.getParameterNames();
while (enum.hasMoreElements())
{
String param = (String)enum.nextElement();
if (param.equalsIgnoreCase("service"))
{
serviceName = req.getParameter(param);
}
else if (param.equalsIgnoreCase("operation"))
{
operationName = req.getParameter(param);
}
else
{
operationArgs += "<" + param + ">"
+ req.getParameter(param)
+ "</" + param + ">";
}
}

if (serviceName == null || serviceName.length() == 0)
{
throw new SOAPFault(response, "No service specified.");
}

if (operationName == null || operationName.length() == 0)
{
throw new SOAPFault(response);
}

String soapEnv = "<SOAP-ENV:Envelope"
+
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<SOAP-ENV:Body>"
+ "<" + operationName + ">"
+ operationArgs + " "
+ "</" + operationName + ">"
+ "</SOAP-ENV:Body>"
+ "</SOAP-ENV:Envelope>";

return soapEnv;
}

After setting the content type and content length appropriately for a SOAP response, the response envelope should be constructed as follows:

String createSOAPResponse(String someValue)
{
String soapEnv = "<SOAP-ENV:Envelope"
+
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<SOAP-ENV:Body>"
+ "<r:MyResponse
xmlns:r=\"http://www.mycompany.com/SOAPResponseNS\">"
+ "<ResponseValue>" + someValue + "</ResponseValue>"
+ "</r:MyResponse>"
+ "</SOAP-ENV:Body>"
+ "</SOAP-ENV:Envelope>";

return soapEnv;

This was last published in December 2002

Dig Deeper on Microservices pattern, platforms and frameworks

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchSoftwareQuality

SearchCloudApplications

SearchAWS

TheServerSide.com

SearchWinDevelopment

DevOpsAgenda

Close