Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6475873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:45:25+00:00 2026-05-25T06:45:25+00:00

I have a spring-ws (2.0.2) service I have implemented that requires some custom elements

  • 0

I have a spring-ws (2.0.2) service I have implemented that requires some custom elements in the soap header. I am trying to use Spring’s MockWebServiceClient to generate a valid request to test the dispatcher, marshallers, etc.

The problem I am getting is that the MockWebSerivce only seems to support the Soap Body (the payload).

How can I access the soap request being generated to get the right headers into it?

If there is a better library for doing this other than Spring’s MockWebServiceClient, that would be fine too.

Related Links:
http://forum.springsource.org/showthread.php?101708-MockWebServiceClient-amp-WS-Security
Add SoapHeader to org.springframework.ws.WebServiceMessage

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:45:26+00:00Added an answer on May 25, 2026 at 6:45 am

    I had the similar problem when I wanted to test spring web service with Security, I ended up using the Spring Interceptors to modify the header before they reach end point, I enabled the interceptors only for testing.

    Create an interceptor, I implemented the SmartEndpointInterceptor, You can use the other interceptors if you choose

    public class ModifySoapHeaderInterceptor implements
        SmartEndpointInterceptor 
    {
      //WSConstants.WSSE_NS;
       private static final String DEFAULT_SECURITY_URL = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
        private static final String SECURITY_TAG = "Security";
        private static final String SECURITY_PREFIX = "wsse";
        private static final String USER_NAME_TOKEN = "UsernameToken";
    
        @Override
    public boolean handleRequest(MessageContext messageContext, Object endpoint)
            throws Exception 
    {
          SaajSoapMessage saajSoapMessage(SaajSoapMessage)messageContext.getRequest());
          SOAPHeader soapHeader = saajSoapMessage.getSaajMessage().getSOAPPart()
                .getEnvelope().getHeader();
    
           //you can modify header's as you choose
           Name headerElement = saajSoapMessage.getSaajMessage().getSOAPPart()
                .getEnvelope()
                .createName(SECURITY_TAG, SECURITY_PREFIX, DEFAULT_SECURITY_URL);
           SOAPHeaderElement soapHeaderElement = soapHeader
                .addHeaderElement(headerElement);
        SOAPElement usernameToken = soapHeaderElement.addChildElement(
                USER_NAME_TOKEN, SECURITY_PREFIX);
    
        SOAPElement userNameElement = usernameToken.addChildElement("Username",
                SECURITY_PREFIX);
        userNameElement.addTextNode("userid");//you can inject via spring
    
        SOAPElement passwordElement = usernameToken.addChildElement("Password",
                SECURITY_PREFIX);
        passwordElement.addTextNode("password");
           return true;
        }
    }
    

    Configure this interceptor in spring context

      <sws:interceptors>
         <bean class="prasanna.ws.security.wss4j.ModifySoapHeaderInterceptor"/>
      </sws:interceptors>
    

    This will add the necessary security headers to the message before it reaches the end point, You can still use MockWebServiceClient to test your web service.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a service class implemented in Java 6 / Spring 3 that needs
I have a SOAP Service that is implemented using Apache Axis 2. It has
I have a WCF service and use Spring.ServiceModel.Activation.ServiceHostFactory as a factory in my *.svc.
Here's what I'm trying to do. We have a SSO authentication service that other
I have implemented a web service(.asmx) using .NET framework that returns me a hash
I have a spring-based Web Service. I now want to build a sort of
I have a Hessian service on Spring + iBatis working on Tomcat. I'm wondering
I have a web service written in Spring MVC. It can be used by
I have a service that give me a date time string in the following
I have a JSP struts application that uses Spring to integrate with the services/dao/database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.