1

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

WhoAre
  • 144
  • 2
  • 13
  • Axis 1.4 is extremely old and, in many ways, inflexible compared with Axis 2 or CXF. Any chance you could switch frameworks? – Jonathan W Nov 19 '13 at 13:57
  • Axis 2 running in JDK 1.5 or JDK 1.4? – WhoAre Nov 19 '13 at 15:17
  • I make this MessageContext message = call.getMessageContext(); SOAPMessage soapMessage = message.getMessage(); SOAPPart sp = (SOAPPart) soapMessage.getSOAPPart(); //SOAPPart sp = (SOAPPart) mess.getSOAPPart(); SOAPEnvelope env = (SOAPEnvelope) sp.getEnvelope(); env.addNamespaceDeclaration("http://www.more.com.br/MC/Geral", "ger"); – WhoAre Nov 19 '13 at 15:18
  • If you are using JDK 1.5, you should be able to move to either Axis 2 or CXF. – Jonathan W Nov 19 '13 at 18:03
  • It requires minimum Java Version 1.6 – WhoAre Nov 19 '13 at 18:57
  • CXF 2.6.x runs on 1.5. That's going to be infinitely better than Axis 1.4, IMO. – Jonathan W Nov 19 '13 at 19:03
  • By the way, I'm not suggesting that customizing the namespace in Axis 1.4 is impossible, but a lot of features in 1.4 simply aren't documented well and require you to throw on the debugger to see how the code is executing to really understand what is going on. Plus, if you asking help online such as you are, fewer and fewer people are going to be actively using Axis 1.4. (It's kind of like asking questions about Struts 1.x these days.) At some point, you should considering biting the technical debt bullet. – Jonathan W Nov 19 '13 at 19:06
  • I making with this code down MessageContext message = call.getMessageContext(); SOAPMessage soapMessage = message.getMessage(); SOAPPart sp = (SOAPPart) soapMessage.getSOAPPart(); SOAPEnvelope env = (SOAPEnvelope) sp.getEnvelope(); But occurring NullPointERexception in this line SOAPEnvelope env = (SOAPEnvelope) sp.getEnvelope(); – WhoAre Nov 21 '13 at 13:13

1 Answers1

2

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.

Thrax
  • 1,926
  • 1
  • 17
  • 32