DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Consuming SOAP Service With Apache CXF and Spring
  • GraphQL vs REST API: Which Is Better for Your Project in 2025?
  • MuleSoft Integrate With ServiceNow
  • Demystifying APIs for Product Managers

Trending

  • A System Cannot Protect What It Does Not Understand
  • Multi-Scale Feature Learning in CNN and U-Net Architectures
  • The Agentic Agile Office: Streamlining Enterprise Agile With Autonomous AI Agents
  • Offline-First Patch Management for 10,000 Edge Nodes: A Practical Architecture That Scales
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Adding HTTP Headers to a SOAP Request

Adding HTTP Headers to a SOAP Request

We'll use a custom CXF interceptor to add these headers.

By 
Singaram Subramanian user avatar
Singaram Subramanian
·
Nov. 04, 13 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
58.0K Views

Join the DZone community and get the full member experience.

Join For Free

Let’s assume that we want to make a SOAP call to a service at http://localhost:8080/samplewebservices/echoserviceinterface, and it requires that we add an API / Access token as an HTTP header, we can do it this way:

Assumptions

Endpoint: http://localhost:8080/samplewebservices/echoserviceinterface
Service Interface: singz.ws.test.interface.EchoService
ACCESS_TOKEN: 046b6c7f-0b8a-43b9-b35d-6489e6daee91 (HTTP Header)

Spring Application Context Configuration

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:cxf="http://cxf.apache.org/core"
 xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">

<jaxws:client id="echoServiceClient"
 serviceClass="singz.ws.test.interface.EchoService"
 address="http://localhost:8080/samplewebservices/echoserviceinterface" />
 <cxf:bus>
 <cxf:outInterceptors>
 <bean class="singz.ws.test.echoserviceconsumer.outinterceptor.HttpHeaderInterceptor" />
 </cxf:outInterceptors>
 </cxf:bus>
</beans>

Custom Interceptor to add HTTP headers to outbound SOAP call

singz.ws.test.echoserviceconsumer.outinterceptor.HttpHeaderInterceptor.java

package singz.ws.test.echoserviceconsumer.outinterceptor;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;

public class HttpHeaderInterceptor extends AbstractPhaseInterceptor<Message>{

public HttpHeaderInterceptor() {
 super(Phase.POST_LOGICAL);
 }

public void handleMessage(Message message) {
 Map<String, List<String>> headers = new HashMap<String, List<String>>();
 headers.put("ACCESS_TOKEN", Arrays.asList("046b6c7f-0b8a-43b9-b35d-6489e6daee91"));
 message.put(Message.PROTOCOL_HEADERS, headers);
 }

}

Here’s another example without using interceptor: http://singztechmusings.wordpress.com/2011/09/17/apache-cxf-how-to-add-custom-http-headers-to-a-web-service-request/


SOAP Web Protocols

Published at DZone with permission of Singaram Subramanian. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Consuming SOAP Service With Apache CXF and Spring
  • GraphQL vs REST API: Which Is Better for Your Project in 2025?
  • MuleSoft Integrate With ServiceNow
  • Demystifying APIs for Product Managers

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook