package mytest.soapenvelope; import org.apache.axis.message.SOAPEnvelope; import org.apache.axis.message.SOAPBody; public class TestSOAPEnvelope { private SOAPEnvelope soapenv = null; public TestSOAPEnvelope() { this.soapenv = new org.apache.axis.message.SOAPEnvelope(); //By default we will have a body with empty content } public void setBody(SOAPBody body) { this.soapenv.setBody(body); } public SOAPBody getBody() throws Exception { return (SOAPBody)this.soapenv.getBody(); } public static void main(String args[]) throws Exception { TestSOAPEnvelope requestEnvelope = new TestSOAPEnvelope(); TestSOAPEnvelope responseEnvelope = new TestSOAPEnvelope(); SOAPBody requestBody = requestEnvelope.getBody(); SOAPBody responseBody = responseEnvelope.getBody(); //lets remove response envelope body responseBody.detachNode(); if(responseEnvelope.getBody()==null) { System.out.println("Removed response envelope's body successfully\n"); } else { System.out.println("Error detaching response envelope's body node. Exiting...\n"); return; } //now lets freshly 'set' the response envelope's body element //as the request envelope's body element. responseEnvelope.setBody(requestEnvelope.getBody()); //lets cross check if the body really got set //this we do by checking if responseEnvelope's body element is not null anymore if(responseEnvelope.getBody()==null) { System.out.println("There is an error with setBody() of SOAPEnvelope\n"); } else { System.out.println("setBody() did its job. There is nothing to debug!!!\n"); return; } } }