Hi

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?

Regards

asked 25.03 at 15:50

Reto%20Weiss's gravatar image

Reto Weiss ♦♦
4.9k172655
accept rate: 74%


Hi

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 
{
    @Override
    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'

Regards

Reto Weiss, Axon.ivy Support

link

answered 25.03 at 15:58

Reto%20Weiss's gravatar image

Reto Weiss ♦♦
4.9k172655
accept rate: 74%

edited 25.03 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

By RSS:

Answers

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

Tags:

×42

Asked: 25.03 at 15:50

Seen: 101 times

Last updated: 25.03 at 15:59