Announcement Announcement Module
Collapse
No announcement yet.
change prefix in SOAP envelope Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • change prefix in SOAP envelope

    Hi all,
    I'm stuck at trying to change the prefix part of my SOAP envelope from "soapenv" to "soap".
    The other server is not accepting my envelopes because it understands only <soap:Envelope>, <soap:Header> and so on...

    I've switched to using Axiom, I need it to add headers the the envelope.
    Code:
    	<bean id="messageFactory"
    		class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory">
    		<property name="payloadCaching" value="true" />
    	</bean>
    In my custom interceptor I can see (from debugger) that responseEnvelope is indeed a org.springframework.ws.soap.axiom.AxiomSoapEnvelop e.
    I get a generic org.springframework.ws.soap.SoapEnvelope, but I cannot cast to such a class org.springframework.ws.soap.axiom.AxiomSoapEnvelop e.

    Code:
    	public boolean handleResponse(MessageContext messageContext, Object endpoint)
    			throws Exception {
    ...
    		// modifico la response
    		SoapMessage response = (SoapMessage) messageContext.getResponse();
    		SoapHeader responseSoapHeader = response.getSoapHeader();
    		SoapEnvelope responseEnvelope = response.getEnvelope();
    I'm quite confused about it.

    Some posts on the forum suggest using SAAJ, but I've already removed it, so this is not an option.

    Any hint please?
    Cheers,
    Vito Meuli

  • #2
    The other thread on the subject is an old one, but it suggests using SAAJ, whereas I'm using Axiom:
    Soap envelope prefix?

    Cheers,
    Vito Meuli

    Comment


    • #3
      Good news!
      I managed to change the "soapenv" prefix, so now it is "soap" as required from the other server.

      my interceptor looks like this:
      Code:
      	public boolean handleResponse(MessageContext messageContext, Object endpoint)
      			throws Exception {
      		AxiomSoapMessage response = (AxiomSoapMessage) messageContext
      				.getResponse();
      		org.apache.axiom.soap.SOAPMessage responseMessage = response
      				.getAxiomMessage();
      		org.apache.axiom.soap.SOAPEnvelope responseEnvelope = responseMessage
      				.getSOAPEnvelope();
      		org.apache.axiom.soap.SOAPHeader responseHeader = responseEnvelope
      				.getHeader();
      		org.apache.axiom.soap.SOAPBody responseBody = responseEnvelope
      				.getBody();
      
      		OMNamespace soapNamespace = new OMNamespaceImpl(
      				"http://schemas.xmlsoap.org/soap/envelope/",
      				"soap");
      
      		responseEnvelope.declareNamespace(soapNamespace);
      		responseEnvelope.setNamespace(soapNamespace);
      
      		responseHeader.declareNamespace(soapNamespace);
      		responseHeader.setNamespace(soapNamespace);
      
      		responseBody.declareNamespace(soapNamespace);
      		responseBody.setNamespace(soapNamespace);
      
      		return true;
      	}
      Obviously I have the AxiomSoapMessageFactory:
      Code:
      	<bean id="messageFactory"
      		class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory">
      		<property name="payloadCaching" value="true" />
      	</bean>
      Now I happily get the "soap" prefix in the SOAP element tags:
      Code:
      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <soap:Header>
            <myHeader>
            </myHeader>
         </soap:Header>
         <soap:Body>
            <myMessage>
            </myMessage>
         </soap:Body>
      </soap:Envelope>
      There's one little problem yet: I have the soap envelope namespace twice: once for the "soap" prefix, and once for the "soapenv" prefix, but I think it's no matter.

      Hope this helps someone else.
      Cheers,
      Vito Meuli

      Comment


      • #4
        Hi Vito, thanks for your solution. I was wondering, could you post a bit more of the interceptor? I'm trying to redo what you do, but I don't know what interceptor you've extended.

        Cheers

        Nik

        Comment


        • #5
          Hi Nik,
          I forgot to mention it: I'm implementing SoapEndpointInterceptor
          There's no class to extend, you have to implement the four methods yourself.

          Code:
          public class myInterceptor implements SoapEndpointInterceptor {
          The methods I didn't show are quite empty, except that they must return true, so that the chain is not broken.

          Code:
          	@Override
          	public boolean handleFault(MessageContext messageContext, Object endpoint)
          			throws Exception {
          		return true;
          	}
          Code:
          @Override
          	public boolean handleRequest(MessageContext messageContext, Object endpoint)
          			throws Exception {
                          return true;
          	}
          Code:
          	@Override
          	public boolean understands(SoapHeaderElement arg0) {
          		return false;
          	}
          and these are my imports:
          Code:
          import javax.xml.namespace.QName;
          import javax.xml.transform.Transformer;
          import javax.xml.transform.TransformerFactory;
          
          import org.apache.axiom.om.OMElement;
          import org.apache.axiom.om.OMNamespace;
          import org.apache.axiom.om.impl.OMNamespaceImpl;
          import org.apache.axiom.soap.SOAPProcessingException;
          import org.springframework.ws.context.MessageContext;
          import org.springframework.ws.soap.SoapHeader;
          import org.springframework.ws.soap.SoapHeaderElement;
          import org.springframework.ws.soap.SoapMessage;
          import org.springframework.ws.soap.axiom.AxiomSoapMessage;
          import org.springframework.ws.soap.server.SoapEndpointInterceptor;
          import org.springframework.xml.transform.StringSource;
          I hope it helps.
          Cheers,
          Vito

          Comment

          Working...
          X