WhoAre
WhoAre

Reputation: 154

Axis 1.4 How to modify soap envelope attributes?

This is envelope which i wanna to send to service:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ger="http://www.more.com.br/MC/Geral" xmlns:num="http://www.more.com.br/SN/Numero">

How make this using Axis 1.4

I need modify the namespace!

I'm using JDK 1.5

Upvotes: 1

Views: 3143

Answers (1)

Thrax
Thrax

Reputation: 1964

Since I couldn't find this answer anywhere, here is how I did it using Axis 1.4.

First of all, you need to create a Handler class which will modify the SOAP Envelope. This Handler must extend BasicHandler.

public class AxisClientEnvelopeHandler extends BasicHandler {

    @Override
    public void invoke(MessageContext msgContext) throws AxisFault {

        try {
            // get the soap header
            SOAPMessageContext smc = (SOAPMessageContext) msgContext;
            SOAPMessage message = smc.getMessage();
            SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();

            // fiddle with the namespaces
            envelope.addNamespaceDeclaration("YOUR NAMESPACE");

        } catch (SOAPException e) {
            e.printStackTrace();
        }
    }
}

Then you have to add this Handler to your SOAP calls. This is done by setting some properties on your service locator.

// Add Handler to Axis SOAP calls
SimpleProvider clientConfig = new SimpleProvider();
AxisClientEnvelopeHandler envelopeHandler = new AxisClientEnvelopeHandler();
SimpleChain reqHandler = new SimpleChain();
SimpleChain respHandler = new SimpleChain();
reqHandler.addHandler(envelopeHandler);
Handler pivot = new HTTPSender();
Handler transport = new SimpleTargetedChain(reqHandler, pivot, respHandler);
clientConfig.deployTransport(HTTPTransport.DEFAULT_TRANSPORT_NAME, transport);
locator.setEngineConfiguration(clientConfig);
locator.setEngine(new AxisClient(clientConfig));

After that, you can call make your calls and the SOAP Envelope will be modfied according to your Handler.

Upvotes: 2

Related Questions