How can I set an additional HTTP header in a SOAP web service request. For example to send a OAuth2 token to the web service?


asked 25.03.2019 at 15:50

Reto%20Weiss's gravatar image

Reto Weiss ♦♦
accept rate: 74%


With CXF you can write your own feature class that sets the additional header:

package wsoauth;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.message.Message;
import ch.ivyteam.ivy.webservice.exec.feature.WebServiceClientFeature;
import ch.ivyteam.ivy.webservice.exec.feature.WebServiceClientFeatureContext;
public class SetOAuthHeader implements WebServiceClientFeature 
    public void initialize(WebServiceClientFeatureContext context) {
        String accessToken = "0b79bab50daca910b000d4f1a2b675d604257e42";
        Client proxy = ClientProxy.getClient(context.getBindingProvider());
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        headers.put("Authorization", Arrays.asList("Bearer "+accessToken));
        proxy.getRequestContext().put(Message.PROTOCOL_HEADERS, headers);

On the web service client add your class to the feature list: alt text

If you now call the web service that HTTP header 'Authorization' is set to 'Bearer 0b79bab50daca910b000d4f1a2b675d604257e42'


Reto Weiss, Axon.ivy Support


answered 25.03.2019 at 15:58

Reto%20Weiss's gravatar image

Reto Weiss ♦♦
accept rate: 74%

edited 25.03.2019 at 15:59

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 25.03.2019 at 15:50

Seen: 3,694 times

Last updated: 25.03.2019 at 15:59