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 7563749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:44:34+00:00 2026-05-30T13:44:34+00:00

I’ve got a JAX-WS WebService that is using Spring 3 IOC. I have coded

  • 0

I’ve got a JAX-WS WebService that is using Spring 3 IOC. I have coded a Spring Aspect to handle any exceptions and ensure that they are properly handled in the WebService class prior to completing a call. Within my Aspect, I would like to get access to the user’s locale (defined in my SOAP Header), however I am not sure how to do this.

I know I can get the Locale in a handler, but that doesn’t help me within my aspect. I tried injecting the WebServiceContext, but that is always null.

A little digging around pointed me to https://issues.apache.org/jira/browse/CXF-2674 which seems to indicate that:

  1. Spring intentionally does not inject a WebServiceContext object
  2. the WebServiceContext is a thin wrapper for the SOAPMessageContext

However, if I try to autowire the SOAPMessageContext instead, that fails as well with the following error message:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.xml.ws.handler.soap.SOAPMessageContext com.cws.cs.lendingsimulationservice.error.ServiceErrorInterceptor.webServiceContext; nested exception is java.lang.IllegalArgumentException: Can not set javax.xml.ws.handler.soap.SOAPMessageContext field com.cws.cs.lendingsimulationservice.error.ServiceErrorInterceptor.webServiceContext to java.util.LinkedHashMap
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502) [spring-beans-3.0.5.RELEASE.jar:]
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84) [spring-beans-3.0.5.RELEASE.jar:]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282) [spring-beans-3.0.5.RELEASE.jar:]
        ... 21 more
Caused by: java.lang.IllegalArgumentException: Can not set javax.xml.ws.handler.soap.SOAPMessageContext field com.cws.cs.lendingsimulationservice.error.ServiceErrorInterceptor.webServiceContext to java.util.LinkedHashMap
        at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146) [:1.6.0_29]
        at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150) [:1.6.0_29]
        at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63) [:1.6.0_29]
        at java.lang.reflect.Field.set(Field.java:657) [:1.6.0_29]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:498) [spring-beans-3.0.5.RELEASE.jar:]
        ... 23 more

I figure that there must be a way I can access this information from within an aspect, but cannot seem to figure out how.

If I try to inject a SOAPMessage object instead, I get a org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.xml.soap.SOAPMessage] found for dependency error message.

Can someone point me in the right direction please?

Thanks,

Eric

  • 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-30T13:44:36+00:00Added an answer on May 30, 2026 at 1:44 pm

    My solution uses a handler and a request-scoped object. Hopefully someone else might find this useful in the future

    Handler:

    public class ServiceContextHandler implements SOAPHandler<SOAPMessageContext>{
    
        /**
         * Logger
         */
        private static final Logger logger = LoggerFactory.getLogger(ServiceContextHandler.class);
    
        /**
         * Request object
         */
        @Autowired
        private SOAPHeaderData soapHeaderData;
    
        /**
         * Ensure that the bean has its parameters injected appropriately
         */
        @PostConstruct
        public void init() {
            SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
        }
    
        /**
         * Nothing to do on end of message
         */
        public void close(MessageContext context) {
        }
    
    
        /**
         * Nothing to do for a fault
         */
        public boolean handleFault(SOAPMessageContext context) {
            return true;
        }
    
        /**
         * Process the message
         */
        public boolean handleMessage(SOAPMessageContext context) {
            // no need to bother with outbound requests
            if( !((Boolean) context.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue() )
                process(context);
            return true;
        }
    
        /**
         * Doesn't handle any specific QNames in the header
         */
        public Set<QName> getHeaders() {
            return null;
        }
    
    
        /**
         * Extract the header parameters
         * @param context
         */
        @SuppressWarnings("unchecked")
        private void process(SOAPMessageContext context) {
            // Creating the XML tree
            try {
                JAXBContext jc = JAXBContext.newInstance( ObjectFactory.class);
                Object[] headers = context.getHeaders(new ObjectFactory().createServiceContext(null).getName(), jc, true);
    
                // find the service context element
                for( Object header : headers ){
                    if( (header instanceof JAXBElement<?>) && ((JAXBElement<?>)header).getValue() instanceof ServiceContextType){
                        // found the service context element
                        soapHeaderData.setServiceContext(((JAXBElement<ServiceContextType>)header).getValue());
                        break;
                    }
                }
    
            } catch (JAXBException e) {
                logger.error(ExceptionUtils.getStackTrace(e));
            } catch (WebServiceException e) {
                logger.error(ExceptionUtils.getStackTrace(e));
            }
        }
    }
    

    Defn of SOAPHeaderData:

    <!-- SOAPHeaderData -->
    <bean id="soapHeaderData" class="com.cws.cs.lendingsimulationservice.header.SOAPHeaderDataImpl" scope="request">
        <aop:scoped-proxy proxy-target-class="false"/>
    </bean>
    

    where SOAPHeaderDataImpl is a basic POJO (with an interface so as to not need CGLIB).

    Hope this helps! If anything is unclear, let me know.

    Thanks,

    Eric

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't

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.