question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support of SoapHeader

See original GitHub issue

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());

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:11
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
CakeSporkcommented, Jun 8, 2020

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

2reactions
elesdoarcommented, 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) {}
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

SOAPHeader (Java Platform SE 7 ) - Oracle Help Center
A SOAP header element consists of XML data that affects the way the application-specific content is processed by the message provider. For example,...
Read more >
SoapHeader Class (System.Web.Services.Protocols)
Create a class that derives from SoapHeader representing the data passed into the SOAP header. Add a member to the class implementing an...
Read more >
SOAP headers - IBM
Use a SOAP header to include application-specific context information in the web service SOAP request and response messages.
Read more >
2.2. Adding SOAP Headers to a SOAP 1.1 Binding
As well as the mandatory message and part attributes, soap:header also supports the namespace , the use , and the encodingStyle attributes.
Read more >
SoapHeader - Manual - PHP
The SoapHeader class ¶. (PHP 5, PHP 7, PHP 8). Introduction ¶. Represents a SOAP header. Class synopsis ¶.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found