Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring web service template set MustUnderstand to none or false

How to set MustUnderstand to none or false. I'm using spring boot and web service template to create client.

POM.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-ws</artifactId>
</dependency>

Config

@Configuration
public class BrokerConnectionServiceConfiguration {

    @Autowired
    private LuiUrlBuilder luiUrlBuilder;    

    @Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setPackagesToScan("com.example");
        return marshaller;
    }    

    @Bean
    public BrokerConnectionServiceClient brokerConnectionServiceClient(Jaxb2Marshaller marshaller) {
        BrokerConnectionServiceClient client = new BrokerConnectionServiceClient();
        client.setDefaultUri(luiUrlBuilder.getConnectionServiceUri());
        client.setMarshaller(marshaller);
        client.setUnmarshaller(marshaller);

        return client;
    }

BrokerConnectionServiceClient.java

public class BrokerConnectionServiceClient extends WebServiceGatewaySupport {

    private static final Logger log = LoggerFactory.getLogger(BrokerConnectionServiceClient.class);

    @Autowired
    private LuiUrlBuilder luiUrlBuilder;    

    public void getBrokerConnectionServiceData(ConnectionRequestType connectionRequestType) {

        log.debug("inside getBrokerConnectionServiceData");

        try {
            getWebServiceTemplate()
                    .marshalSendAndReceive(
                            new JAXBElement<>(new QName(Constants.BROKER_CONNECTION_SERVICE_NAMESPACE_URI, Constants.BROKER_CONNECTION_SERVICE_LOCAL_PART), ConnectionRequestType.class, connectionRequestType),
                            new ActionCallback(new URI(luiUrlBuilder.getConnectionServiceCallBackLocation()), new Addressing200408()));
        } catch (URISyntaxException e) {
            log.trace("URISyntaxException occurred", e);
        }
    }
}

enter image description here

Can some body please let me know how to set "Must understand" to none or false and WS-A version to "200508" instead of "200408"?

Thanks in advance

like image 287
Pratap A.K Avatar asked Feb 01 '26 06:02

Pratap A.K


1 Answers

Using WebServiceMessageCallback we can achieve. ActionCallback intern implements WebServiceMessageCallback.

BrokerConnectionServiceClient.java

getWebServiceTemplate()
.marshalSendAndReceive(
      new JAXBElement<>(new QName(Constants.BROKER_CONNECTION_SERVICE_NAMESPACE_URI, Constants.BROKER_CONNECTION_SERVICE_LOCAL_PART), ConnectionRequestType.class, connectionRequestType),
      new WebServiceMessageCallback() {
      @Override
      public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
      SOAPMessage soapMessage = ((SaajSoapMessage) message).getSaajMessage();
      SOAPHeader soapHeader = soapMessage.getSOAPHeader();

      SOAPHeaderElement actionElement = soapHeader.addHeaderElement(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing", "Action", "wsa"));
      actionElement.setMustUnderstand(false);
      actionElement.setTextContent("ConnectionService");
    }
});

OUTPUT

<wsa:Action soapenv:mustUnderstand="0">ConnectionService</wsa:Action>

same for remaining fields too.

like image 181
Pratap A.K Avatar answered Feb 02 '26 22:02

Pratap A.K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!