Search code examples
spring-integrationspring-integration-dsl

Adding custom header to MarshallingWebServiceOutboundGateway in SI


Good evening,

I am trying to add custom header to a request but I am not too successful so far. I found examples which uses Http.outboundGateway(...) but I use MarshallingWebServiceOutboundGateway.

The following doesn't work, I cant see the header attributes in HTTP request.

@Bean
public IntegrationFlow processRequest() {
    return flow -> flow.channel(INPUT_CHANNEL)
            .transform(requestMapper, "mapFrom")
            .enrichHeaders(
                    h -> h.header(X_TRANSACTION_ID, "somevalue")
                          .header(CLIENT_ID, "somevalue")
                          .header(CLIENT_SECRET, "somevalue")
            )
            .handle(webserviceOutboundGateway)
            .channel(OUTPUT_CHANNEL);
}

I don't know what I am missing. I'd appreciate any hint please.

Regards, V.

+++++++++ UPDATE +++++++++

As per Artem's hint I crafted the following:

@Bean
@Autowired
public MarshallingWebServiceOutboundGateway muleMLGatewayWebserviceOutboundGateway(...) {
    MarshallingWebServiceOutboundGateway gateway = ...;
    gateway.setAdviceChain(Collections.singletonList(muleGatewayFailingAdvice()));
    gateway.setHeaderMapper(muleSecurityAttributesHeaderMapper());
    return gateway;
}

@Bean
public SoapHeaderMapper muleSecurityAttributesHeaderMapper() {
    return new MuleSecurityAttributesHeaderMapper();
}

class MuleSecurityAttributesHeaderMapper extends DefaultSoapHeaderMapper {

    @Override
    protected void populateUserDefinedHeader(String headerName, Object headerValue, SoapMessage soapMessage) {
        super.populateUserDefinedHeader(headerName, headerValue, soapMessage);
        MimeHeaders mimeHeaders = ((SaajSoapMessage)soapMessage).getSaajMessage().getMimeHeaders();
        mimeHeaders.setHeader("a", "b");
        setRequestHeaderNames("a");
    }
}

However I am still not finding the custom HTTP request header I am afraid.
Any thought please?


Solution

  • It looks like you can subclass SaajSoapMessageFactory and override postProcess - it looks like that's where the default implementation adds an empty soap action header (if it is missing).

    You should probably also call the super method from the override.