I have a web service client, and I'm sending a request to a web service. However, during the request, I must include the Content-Length and Accept headers in the SOAP call.
Could you please guide me on how to include these headers in the request? I'm making the web service call using Axis2, and the client code is written in Java 7.
Please note that I prefer not to set a custom header. Instead, I would like to directly add the headers to the request.
**My code skeleton: **
org.apache.axis2.client.Stub serviceClient=new org.apache.axis2.client.ServiceClient(configurationContext,_service);
org.apache.axis2.client.OperationClient operationClient =serviceClient.createClient(getname());
org.apache.axis2.context.MessageContext messageContext = new org.apache.axis2.context.MessageContext();
org.apache.axiom.soap.SOAPEnvelope envelope = null;
stub.dummy dummyWrappedType = null;
envelope = toEnvelope(getFactory(operationClient.getOptions().getSoapVersionURI()),message5,dummyWrappedType,optimizeContent(new javax.xml.namespace.QName("http://dummy","test")));
serviceClient.addHeadersToEnvelope(envelope);
messageContext.setEnvelope(envelope);
operationClient.addMessageContext(_messageContext);
operationClient.execute(true);
FYI JAVA Version : 7 Axis2 Version : 1.5.6
- I attempted to add the property both in the message context and client.
- I also tried setting the options in both the message context and client.
Options options = new Options();
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.HEADER_CONTENT_LENGTH, "123");
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.HEADER_ACCEPT, "application/xml");
serviceClient.setOptions(options);