Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of SoapHeader #1005

Open
snajberk opened this issue Jul 10, 2019 · 8 comments
Open

Support of SoapHeader #1005

snajberk opened this issue Jul 10, 2019 · 8 comments
Labels
proposal Proposed Specification or API change waiting for votes Enhancements or changes proposed that need more support before consideration

Comments

@snajberk
Copy link

snajberk commented Jul 10, 2019

Hi,

It would be great, if there could be some support of SoapHeaders when you are using Feign for legacy Soap calls. I just recently came to legacy API, where it was mandatory.

And having something like this would be absolutely amazing as headers might be marshalled objects.

@RequestLine("POST /getObject")
@Headers({
  "SOAPAction: getObject",
  "Content-Type: text/xml"
})
MyJaxbObjectResponse getObject(@SoapHeader MyJaxbHeader header, MyJaxbObjectRequest request);

Second best thing would be method annotation where you could define per method interceptor @SoapHeader(MyJaxbHeaderInterceptor.class)

The simplest solution (which I chose as it is the simplest one and it fit my need) would be to add interceptor in builder (to encoder).

I created copy of SoapEncoder SoapEncoderWithHeader(JAXBContextFactory jaxbContextFactory, MyJaxbHeaderInterceptor headerInterceptor) and I only had to add following two lines in encode method:

Marshaller headerMarshaller = jaxbContextFactory.createMarshaller(interceptor.getHeaderClass());
headerMarshaller.marshal(interceptor.createHeader(), soapMessage.getSOAPHeader());
@kdavisk6 kdavisk6 added the proposal Proposed Specification or API change label Jul 12, 2019
@kdavisk6 kdavisk6 added the waiting for votes Enhancements or changes proposed that need more support before consideration label Dec 30, 2019
@ygorovitch
Copy link

Hi, I have the same need.

@taboubim
Copy link

Hi, We have the same need here too !!! we need to pass security params in the header!!
thanks

@kdavisk6
Copy link
Member

I suspect in the short term, you could extend the SOAPEncoder to append any custom values to the Envelope mimicking the desired behavior. I am leary however, of overloading @Headers to be context sensitive this way. That annotation is for Request headers and I think it should stay that way.

If we want to go the annotation route, we may custom Contract that can support those values. We are open to any potential suggestions and/or solutions.

@osslite
Copy link

osslite commented Jan 23, 2020

Hi, we have the same needs. Using old systems connecting by soap and feign is great for this job

@elesdoar
Copy link

elesdoar commented May 26, 2020

Try extending a SOAPEncoder class:

import feign.Headers;
import feign.RequestTemplate;
import feign.jaxb.JAXBContextFactory;
import feign.soap.SOAPEncoder;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.stream.Stream;

public class CustomSOAPEncoder extends SOAPEncoder {
    public CustomSOAPEncoder(JAXBContextFactory jaxbContextFactory) {
        super(jaxbContextFactory);
    }

    @Override
    public void encode(Object object, Type bodyType, RequestTemplate template) {
        super.encode(object, bodyType, template);
        Method method = template.methodMetadata().method();
        try {
            Headers headers = method.getDeclaredAnnotation(Headers.class);
            Stream.of(headers.value())
                .forEach(h -> {
                    String[] header = h.split(":");
                    if(header.length == 2) {
                        template.header(header[0], header[1].trim());
                    }
                });
        } catch (Exception ignored) {}
    }
}

@CakeSpork
Copy link

@elesdoar that would add HTTP headers, but not a SOAP-ENV:Header in the Soap Envelope

@Laess3r
Copy link
Contributor

Laess3r commented Sep 15, 2021

I just created a PR for an easy solution. This enables any kind of modification to the SOAPMessage before it's finally encoded.
An example is found in the javadoc.

#1503

@odiego
Copy link

odiego commented Jan 17, 2022

Nice! Thanks for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Proposed Specification or API change waiting for votes Enhancements or changes proposed that need more support before consideration
Projects
None yet
Development

No branches or pull requests

9 participants